1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wadl.inference.schema.content;
14
15 import org.apache.xmlbeans.XmlCursor;
16 import org.apache.xmlbeans.XmlException;
17
18 import com.eviware.soapui.impl.wadl.inference.schema.Content;
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.support.TypeInferrer;
22 import com.eviware.soapui.inferredSchema.EmptyContentConfig;
23
24 /***
25 * EmptyContent may not have any content, be it simpe or complex.
26 *
27 * @author Dain Nilsson
28 */
29 public class EmptyContent implements Content
30 {
31 private Schema schema;
32 private boolean completed = false;
33
34 public EmptyContent( Schema schema, boolean completed )
35 {
36 this.schema = schema;
37 this.completed = completed;
38 }
39
40 public EmptyContent( EmptyContentConfig xml, Schema schema )
41 {
42 this.schema = schema;
43 completed = xml.getCompleted();
44 }
45
46 public EmptyContentConfig save()
47 {
48 EmptyContentConfig xml = EmptyContentConfig.Factory.newInstance();
49 xml.setCompleted( completed );
50 return xml;
51 }
52
53 public String toString( String attrs )
54 {
55 return attrs;
56 }
57
58 public Content validate( Context context ) throws XmlException
59 {
60 XmlCursor cursor = context.getCursor();
61 cursor.push();
62 if( cursor.toParent() && cursor.toFirstChild() )
63 {
64
65 cursor.pop();
66 return new SequenceContent( schema, completed );
67 }
68 else if( cursor.pop() && !cursor.isEnd() )
69 {
70
71 if( completed )
72 return new SimpleContent( schema, TypeInferrer.getBlankType() );
73 else
74 return new SimpleContent( schema, cursor.getTextValue() );
75 }
76 completed = true;
77 return this;
78 }
79
80 }