1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wadl.inference.schema;
14
15 import org.apache.xmlbeans.XmlException;
16
17 import com.eviware.soapui.impl.wadl.inference.schema.types.CustomType;
18 import com.eviware.soapui.impl.wadl.inference.schema.types.EmptyType;
19 import com.eviware.soapui.impl.wadl.inference.schema.types.SimpleType;
20 import com.eviware.soapui.impl.wadl.inference.schema.types.TypeReferenceType;
21 import com.eviware.soapui.inferredSchema.CustomTypeConfig;
22 import com.eviware.soapui.inferredSchema.EmptyTypeConfig;
23 import com.eviware.soapui.inferredSchema.SimpleTypeConfig;
24 import com.eviware.soapui.inferredSchema.TypeConfig;
25 import com.eviware.soapui.inferredSchema.TypeReferenceConfig;
26
27 /***
28 * An instance of an XML Schema type.
29 *
30 * @author Dain Nilsson
31 */
32 public interface Type
33 {
34
35 /***
36 * Return the name for the type, not including namespace prefix.
37 *
38 * @return The name of the type.
39 */
40 public String getName();
41
42 /***
43 * Getter for the schema in which the element/attribute with this type lives.
44 *
45 * @return The Schema for the type.
46 */
47 public Schema getSchema();
48
49 /***
50 * Validate an element/attribute with this type.
51 *
52 * @param context
53 * A Context object holding the current
54 * @return Returns a Type that is valid for the element/attribute, quite
55 * possibly this Type instance itself.
56 * @throws XmlException
57 */
58 public Type validate( Context context ) throws XmlException;
59
60 public String toString();
61
62 /***
63 * Setter for the schema in which this type lives.
64 *
65 * @param schema
66 */
67 public void setSchema( Schema schema );
68
69 /***
70 * Serialize instance to XmlObject.
71 *
72 * @return Returns an XmlObject storing the variables of this instance.
73 */
74 public TypeConfig save();
75
76 /***
77 * A static factory class for creating new instances.
78 *
79 * @author Dain Nilsson
80 */
81 public class Factory
82 {
83
84 /***
85 * Creates a new empty Type object.
86 *
87 * @param schema
88 * The Schema in which to place the type.
89 * @return The newly created Type.
90 */
91 public static Type newType( Schema schema )
92 {
93 return new EmptyType( schema );
94 }
95
96 /***
97 * Parses the given XmlObject into a Type instance.
98 *
99 * @param xml
100 * The XmlObject storing the saved type.
101 * @param schema
102 * The schema in which to place the type.
103 * @return The loaded type.
104 */
105 public static Type parse( TypeConfig xml, Schema schema )
106 {
107 if( xml instanceof TypeReferenceConfig )
108 return new TypeReferenceType( ( TypeReferenceConfig )xml, schema );
109 if( xml instanceof SimpleTypeConfig )
110 return new SimpleType( ( SimpleTypeConfig )xml, schema );
111 if( xml instanceof EmptyTypeConfig )
112 return new EmptyType( ( EmptyTypeConfig )xml, schema );
113 if( xml instanceof CustomTypeConfig )
114 return new CustomType( ( CustomTypeConfig )xml, schema );
115 return null;
116 }
117 }
118 }