View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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;
14  
15  import java.io.IOException;
16  import java.io.InputStream;
17  import java.io.OutputStream;
18  
19  import org.apache.xmlbeans.SchemaTypeSystem;
20  import org.apache.xmlbeans.XmlException;
21  import org.apache.xmlbeans.XmlObject;
22  
23  import com.eviware.soapui.impl.wadl.inference.support.InferredSchemaImpl;
24  
25  /***
26   * XML Schema inferred from gathered XML data.
27   * 
28   * @author Dain Nilsson
29   */
30  public interface InferredSchema
31  {
32  
33  	/***
34  	 * Method for reading out the inferred schema, in its current form.
35  	 * 
36  	 * @return The inferred schema.
37  	 */
38  	public SchemaTypeSystem getSchemaTypeSystem();
39  
40  	/***
41  	 * Expands the inferred schema to accept the input XML as valid.
42  	 * 
43  	 * @param xml
44  	 *           An XmlObject that is assumed to be valid.
45  	 * @throws XmlException
46  	 */
47  	public void processValidXml( XmlObject xml ) throws XmlException;
48  
49  	/***
50  	 * Attempts to validate the given XML against the inferred schema. Any errors
51  	 * detected will cause validation to halt and return false.
52  	 * 
53  	 * @param xml
54  	 * @return Returns true if the content validated successfully, false if not.
55  	 */
56  	public boolean validate( XmlObject xml );
57  
58  	/***
59  	 * Attempts to validate the given XML against the inferred schema. Any errors
60  	 * detected need to be resolved to either expand the schema, or the input
61  	 * will cause an XmlException to be thrown.
62  	 * 
63  	 * @param xml
64  	 * @param handler
65  	 * @throws XmlException
66  	 *            for validation error.
67  	 */
68  	public void learningValidate( XmlObject xml, ConflictHandler handler ) throws XmlException;
69  
70  	/***
71  	 * Writes the XML represented by this InferredSchema.
72  	 * 
73  	 * @param os
74  	 * @throws IOException
75  	 */
76  	public void save( OutputStream os ) throws IOException;
77  
78  	/***
79  	 * Returns a string representation of the XML Schema for a particular
80  	 * namespace, if available.
81  	 * 
82  	 * @param namespace
83  	 * @return A String representation of the XML Schema describing the
84  	 *         namespace.
85  	 */
86  	public String getXsdForNamespace( String namespace );
87  
88  	/***
89  	 * Returns a list of inferred namespaces.
90  	 * 
91  	 * @return A Set containing all inferred namespaces.
92  	 */
93  	public String[] getNamespaces();
94  
95  	/***
96  	 * Static factory class for creating new instances.
97  	 * 
98  	 * @author Dain Nilsson
99  	 */
100 	static class Factory
101 	{
102 
103 		/***
104 		 * Creates a new empty schema.
105 		 * 
106 		 * @return A new, blank InferredSchema.
107 		 * 
108 		 */
109 		public static InferredSchema newInstance()
110 		{
111 			return new InferredSchemaImpl();
112 		}
113 
114 		/***
115 		 * Decodes and parses the given InputStream as a serialized
116 		 * InferredSchema.
117 		 * 
118 		 * @param is
119 		 * @return An InferredSchema containing previously saved data.
120 		 * @throws XmlException
121 		 * @throws IOException
122 		 */
123 		public static InferredSchema parse( InputStream is ) throws XmlException, IOException
124 		{
125 			return new InferredSchemaImpl( is );
126 		}
127 	}
128 
129 	public void deleteNamespace( String ns );
130 
131 	public SchemaTypeSystem getSchemaTypeSystem( SchemaTypeSystem schemaTypeSystem );
132 
133 }