1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wadl.inference.schema.types;
14
15 import org.apache.xmlbeans.XmlAnySimpleType;
16 import org.apache.xmlbeans.XmlCursor;
17 import org.apache.xmlbeans.XmlException;
18
19 import com.eviware.soapui.impl.wadl.inference.schema.Context;
20 import com.eviware.soapui.impl.wadl.inference.schema.Schema;
21 import com.eviware.soapui.impl.wadl.inference.schema.Settings;
22 import com.eviware.soapui.impl.wadl.inference.schema.Type;
23 import com.eviware.soapui.impl.wadl.inference.schema.content.EmptyContent;
24 import com.eviware.soapui.impl.wadl.inference.support.TypeInferrer;
25 import com.eviware.soapui.inferredSchema.EmptyTypeConfig;
26
27 /***
28 * EmptyRtpe corresponds to an instance of a type with no attributes, nor any
29 * content.
30 *
31 * @author Dain Nilsson
32 */
33 public class EmptyType implements Type
34 {
35 private Schema schema;
36 private EmptyContent empty;
37 private boolean completed = false;
38
39 public EmptyType( Schema schema )
40 {
41 this.schema = schema;
42 empty = new EmptyContent( schema, false );
43 }
44
45 public EmptyType( EmptyTypeConfig xml, Schema schema )
46 {
47 this.schema = schema;
48 empty = new EmptyContent( schema, xml.getCompleted() );
49 completed = xml.getCompleted();
50 }
51
52 public EmptyTypeConfig save()
53 {
54 EmptyTypeConfig xml = EmptyTypeConfig.Factory.newInstance();
55 xml.setCompleted( completed );
56 return xml;
57 }
58
59 public String getName()
60 {
61 return "empty_element";
62 }
63
64 public Schema getSchema()
65 {
66 return schema;
67 }
68
69 public void setSchema( Schema schema )
70 {
71 this.schema = schema;
72 }
73
74 public Type validate( Context context ) throws XmlException
75 {
76 XmlCursor cursor = context.getCursor();
77 if( !cursor.isAttr() && ( cursor.toFirstAttribute() || cursor.toFirstChild() ) )
78 {
79
80 ComplexType newType = new ComplexType( schema, context.getName(), completed );
81 newType.setContent( empty );
82 return newType;
83 }
84 cursor.toFirstContentToken();
85 if( empty.validate( context ) != empty )
86 {
87
88 String value = cursor.getTextValue();
89 XmlAnySimpleType simpleType;
90 if( completed )
91 simpleType = TypeInferrer.getBlankType();
92 else
93 simpleType = TypeInferrer.inferSimpleType( value );
94
95
96 return new SimpleType( schema, simpleType, completed );
97 }
98 completed = true;
99 return this;
100 }
101
102 public String toString()
103 {
104 String xsdns = schema.getPrefixForNamespace( Settings.xsdns );
105 StringBuilder s = new StringBuilder( "<" + xsdns + ":complexType name=\"" + getName() + "\"/>" );
106 return s.toString();
107 }
108
109 }