View Javadoc

1   package org.codehaus.xfire.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.fault.XFireFault;
9   import org.codehaus.xfire.message.MessageReader;
10  import org.codehaus.xfire.message.MessageWriter;
11  import org.codehaus.xfire.wsdl.SchemaType;
12  import org.dom4j.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      
26      public Type()
27      {
28      }
29      
30      public abstract Object readObject( MessageReader reader, MessageContext context ) 
31      	throws XFireFault;
32      
33      public abstract void writeObject( Object object, MessageWriter writer, MessageContext context ) 
34      	throws XFireFault;
35      
36      public void writeSchema( Element element )
37      {
38      }
39      
40  	/***
41  	 * @return Returns the typeMapping.
42  	 */
43  	public TypeMapping getTypeMapping()
44  	{
45  		return typeMapping;
46  	}
47      
48  	/***
49  	 * @param typeMapping The typeMapping to set.
50  	 */
51  	public void setTypeMapping( TypeMapping typeMapping )
52  	{
53  		this.typeMapping = typeMapping;
54  	}
55      
56  	/***
57  	 * @return Returns the typeClass.
58  	 */
59  	public Class getTypeClass()
60  	{
61  		return typeClass;
62  	}
63      
64  	/***
65  	 * @param typeClass The typeClass to set.
66  	 */
67  	public void setTypeClass( Class typeClass )
68  	{
69  		this.typeClass = typeClass;
70  	}
71  
72      /***
73       * @return True if a complex type schema must be written.
74       */
75      public boolean isComplex()
76      {
77          return false;
78      }
79  
80      /***
81       * Return a set of Type dependencies.  Returns null if this type
82       * has no dependencies.
83       * 
84       * @return
85       */
86      public Set getDependencies()
87      {
88          // TODO Auto-generated method stub
89          return null;
90      }
91      
92      /***
93       * @see java.lang.Object#equals(java.lang.Object)
94       */
95      public boolean equals(Object obj)
96      {
97          if ( obj instanceof Type )
98          {
99              Type type = (Type) obj;
100 
101             if ( type.getSchemaType().equals( getSchemaType() )
102                  &&
103                  type.getTypeClass().equals( getTypeClass() ) )
104             {
105                 return true;
106             }
107         }
108         
109         return false;
110     }
111     
112     public int hashCode()
113     {
114         int hashcode = 0;
115         
116         if (getTypeClass() != null)
117         {
118             hashcode ^= getTypeClass().hashCode();
119         }
120         
121         if (getSchemaType() != null)
122         {
123             hashcode ^= getSchemaType().hashCode();
124         }
125         
126         return hashcode;
127     }
128     
129     /***
130      * @return Get the schema type.
131      */
132     public QName getSchemaType()
133     {
134         return schemaType;
135     }
136     
137     /***
138      * @param name The qName to set.
139      */
140     public void setSchemaType(QName name)
141     {
142         schemaType = name;
143     }
144 }