37
37
38
38
import org .apache .commons .logging .Log ;
39
39
import org .apache .commons .logging .LogFactory ;
40
- import org .apache .ws .commons .schema .ValidationEventHandler ;
41
40
import org .apache .ws .commons .schema .XmlSchema ;
42
41
import org .apache .ws .commons .schema .XmlSchemaCollection ;
43
42
import org .apache .ws .commons .schema .XmlSchemaExternal ;
44
43
import org .apache .ws .commons .schema .XmlSchemaImport ;
45
44
import org .apache .ws .commons .schema .XmlSchemaInclude ;
46
45
import org .apache .ws .commons .schema .XmlSchemaObject ;
47
- import org .apache .ws .commons .schema .XmlSchemaObjectCollection ;
48
46
import org .apache .ws .commons .schema .resolver .DefaultURIResolver ;
49
47
import org .apache .ws .commons .schema .resolver .URIResolver ;
50
48
import org .xml .sax .InputSource ;
54
52
* <p/>
55
53
* Setting the {@link #setInline(boolean) inline} flag to <code>true</code> will result in all referenced schemas
56
54
* (included and imported) being merged into the referred schema. When including the schemas into a WSDL, this greatly
57
- * simplifies the deloyment of the schemas.
55
+ * simplifies the deployment of the schemas.
58
56
*
59
57
* @author Arjen Poutsma
60
58
* @see <a href="http://ws.apache.org/commons/XmlSchema/">Commons XML Schema</a>
@@ -72,8 +70,6 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
72
70
73
71
private boolean inline = false ;
74
72
75
- private ValidationEventHandler validationEventHandler ;
76
-
77
73
private URIResolver uriResolver = new ClasspathUriResolver ();
78
74
79
75
private ResourceLoader resourceLoader ;
@@ -105,21 +101,14 @@ public void setXsds(Resource[] xsdResources) {
105
101
}
106
102
107
103
/**
108
- * Defines whether included schemas should be inlinded into the including schema.
104
+ * Defines whether included schemas should be inlined into the including schema.
109
105
* <p/>
110
106
* Defaults to <code>false</code>.
111
107
*/
112
108
public void setInline (boolean inline ) {
113
109
this .inline = inline ;
114
110
}
115
111
116
- /**
117
- * Sets the WS-Commons validation event handler to use while parsing schemas.
118
- */
119
- public void setValidationEventHandler (ValidationEventHandler validationEventHandler ) {
120
- this .validationEventHandler = validationEventHandler ;
121
- }
122
-
123
112
/**
124
113
* Sets the WS-Commons uri resolver to use when resolving (relative) schemas.
125
114
* <p/>
@@ -146,7 +135,7 @@ public void afterPropertiesSet() throws IOException {
146
135
Assert .isTrue (xsdResource .exists (), xsdResource + " does not exit" );
147
136
try {
148
137
XmlSchema xmlSchema =
149
- schemaCollection .read (SaxUtils .createInputSource (xsdResource ), validationEventHandler );
138
+ schemaCollection .read (SaxUtils .createInputSource (xsdResource ));
150
139
xmlSchemas .add (xmlSchema );
151
140
152
141
if (inline ) {
@@ -188,32 +177,30 @@ public XmlValidator createValidator() throws IOException {
188
177
private void inlineIncludes (XmlSchema schema , Set <XmlSchema > processedIncludes , Set <XmlSchema > processedImports ) {
189
178
processedIncludes .add (schema );
190
179
191
- XmlSchemaObjectCollection schemaItems = schema .getItems ();
192
- for (int i = 0 ; i < schemaItems .getCount (); i ++) {
193
- XmlSchemaObject schemaObject = schemaItems .getItem (i );
180
+ List < XmlSchemaObject > schemaItems = schema .getItems ();
181
+ for (int i = 0 ; i < schemaItems .size (); i ++) {
182
+ XmlSchemaObject schemaObject = schemaItems .get (i );
194
183
if (schemaObject instanceof XmlSchemaInclude ) {
195
184
XmlSchema includedSchema = ((XmlSchemaInclude ) schemaObject ).getSchema ();
196
185
if (!processedIncludes .contains (includedSchema )) {
197
186
inlineIncludes (includedSchema , processedIncludes , processedImports );
198
187
findImports (includedSchema , processedImports , processedIncludes );
199
- XmlSchemaObjectCollection includeItems = includedSchema .getItems ();
200
- for (int j = 0 ; j < includeItems .getCount (); j ++) {
201
- XmlSchemaObject includedItem = includeItems .getItem (j );
188
+ List <XmlSchemaObject > includeItems = includedSchema .getItems ();
189
+ for (XmlSchemaObject includedItem : includeItems ) {
202
190
schemaItems .add (includedItem );
203
191
}
204
192
}
205
193
// remove the <include/>
206
- schemaItems .removeAt (i );
194
+ schemaItems .remove (i );
207
195
i --;
208
196
}
209
197
}
210
198
}
211
199
212
200
private void findImports (XmlSchema schema , Set <XmlSchema > processedImports , Set <XmlSchema > processedIncludes ) {
213
201
processedImports .add (schema );
214
- XmlSchemaObjectCollection includes = schema .getIncludes ();
215
- for (int i = 0 ; i < includes .getCount (); i ++) {
216
- XmlSchemaExternal external = (XmlSchemaExternal ) includes .getItem (i );
202
+ List <XmlSchemaExternal > externals = schema .getExternals ();
203
+ for (XmlSchemaExternal external : externals ) {
217
204
if (external instanceof XmlSchemaImport ) {
218
205
XmlSchemaImport schemaImport = (XmlSchemaImport ) external ;
219
206
XmlSchema importedSchema = schemaImport .getSchema ();
0 commit comments