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