1 package org.codehaus.xfire.java.type;
2
3 import java.util.Set;
4
5 import org.codehaus.xfire.java.mapping.TypeMapping;
6 import org.codehaus.xfire.java.message.MessageReader;
7 import org.codehaus.xfire.java.message.MessageWriter;
8 import org.codehaus.xfire.wsdl.WSDLType;
9 import org.dom4j.Element;
10 import org.dom4j.QName;
11
12 /***
13 * Type
14 *
15 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
16 */
17 public abstract class Type
18 implements WSDLType
19 {
20 private QName schemaType;
21 private TypeMapping typeMapping;
22 private Class typeClass;
23
24 public Type()
25 {
26 }
27
28 public abstract Object readObject( MessageReader reader );
29
30 public abstract void writeObject( Object object, MessageWriter writer );
31
32 public void writeSchema( Element element )
33 {
34 }
35
36 /***
37 * @return Returns the typeMapping.
38 */
39 public TypeMapping getTypeMapping()
40 {
41 return typeMapping;
42 }
43
44 /***
45 * @param typeMapping The typeMapping to set.
46 */
47 public void setTypeMapping( TypeMapping typeMapping )
48 {
49 this.typeMapping = typeMapping;
50 }
51
52 /***
53 * @return Returns the typeClass.
54 */
55 public Class getTypeClass()
56 {
57 return typeClass;
58 }
59
60 /***
61 * @param typeClass The typeClass to set.
62 */
63 public void setTypeClass( Class typeClass )
64 {
65 this.typeClass = typeClass;
66 }
67
68 /***
69 * @return True if a complex type schema must be written.
70 */
71 public boolean isComplex()
72 {
73 return false;
74 }
75
76 /***
77 * Return a set of Type dependencies. Returns null if this type
78 * has no dependencies.
79 *
80 * @return
81 */
82 public Set getDependencies()
83 {
84
85 return null;
86 }
87
88 /***
89 * @see java.lang.Object#equals(java.lang.Object)
90 */
91 public boolean equals(Object obj)
92 {
93 if ( obj instanceof Type )
94 {
95 Type type = (Type) obj;
96
97 if ( type.getSchemaType().equals( getSchemaType() )
98 &&
99 type.getTypeClass().equals( getTypeClass() ) )
100 {
101 return true;
102 }
103 }
104
105 return false;
106 }
107
108 public int hashCode()
109 {
110 int hashcode = 0;
111
112 if (getTypeClass() != null)
113 {
114 hashcode ^= getTypeClass().hashCode();
115 }
116
117 if (getSchemaType() != null)
118 {
119 hashcode ^= getSchemaType().hashCode();
120 }
121
122 return hashcode;
123 }
124
125 /***
126 * @return Returns the qName.
127 */
128 public QName getSchemaType()
129 {
130 return schemaType;
131 }
132
133 /***
134 * @param name The qName to set.
135 */
136 public void setSchemaType(QName name)
137 {
138 schemaType = name;
139 }
140 }