View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *  See the GNU Lesser General Public License for more details at gnu.org.
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.content.EmptyContent;
18  import com.eviware.soapui.impl.wadl.inference.schema.content.SequenceContent;
19  import com.eviware.soapui.impl.wadl.inference.schema.content.SimpleContent;
20  import com.eviware.soapui.inferredSchema.ContentConfig;
21  import com.eviware.soapui.inferredSchema.EmptyContentConfig;
22  import com.eviware.soapui.inferredSchema.SequenceContentConfig;
23  import com.eviware.soapui.inferredSchema.SimpleContentConfig;
24  
25  /***
26   * This class represents the content of an XML element. It does not take into
27   * account any attributes that the element may have.
28   * 
29   * @author Dain Nilsson
30   */
31  public interface Content
32  {
33  
34  	/***
35  	 * Validates an XML document contained in a given Context object.
36  	 * 
37  	 * @param context
38  	 *           A Context object containing the XML data to be validated, and
39  	 *           other needed contextual variables.
40  	 * @return Returns a Content object that is valid for the element/attribute,
41  	 *         quite possibly this Content instance itself.
42  	 * @throws XmlException
43  	 */
44  	public Content validate( Context context ) throws XmlException;
45  
46  	public String toString( String attrs );
47  
48  	/***
49  	 * Save the Content to an XmlObject.
50  	 */
51  	public ContentConfig save();
52  
53  	/***
54  	 * A static factory class for creating new instances.
55  	 * 
56  	 * @author Dain Nilsson
57  	 */
58  	public class Factory
59  	{
60  
61  		/***
62  		 * Creates a new, empty, Content.
63  		 * 
64  		 * @param schema
65  		 *           The Schema in which the Content will live.
66  		 * @return Returns the newly created Content.
67  		 */
68  		public static Content newContent( Schema schema )
69  		{
70  			return new EmptyContent( schema, false );
71  		}
72  
73  		/***
74  		 * Constructs a Content object using previously saved data.
75  		 * 
76  		 * @param xml
77  		 *           XmlObject to which data has previously been saved.
78  		 * @param schema
79  		 *           The Schema in which to place the newly constructed Content.
80  		 * @return Returns the newly constructed Content.
81  		 */
82  		public static Content parse( ContentConfig xml, Schema schema )
83  		{
84  			if( xml instanceof EmptyContentConfig )
85  				return new EmptyContent( ( EmptyContentConfig )xml, schema );
86  			if( xml instanceof SimpleContentConfig )
87  				return new SimpleContent( ( SimpleContentConfig )xml, schema );
88  			if( xml instanceof SequenceContentConfig )
89  				return new SequenceContent( ( SequenceContentConfig )xml, schema );
90  			return null;
91  		}
92  	}
93  }