Skip to content

Commit 2cb0b52

Browse files
committed
SWS-353
1 parent 59ff43e commit 2cb0b52

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import java.io.IOException;
2020
import java.util.ArrayList;
21+
import java.util.HashSet;
2122
import java.util.List;
23+
import java.util.Set;
2224

2325
import org.apache.ws.commons.schema.ValidationEventHandler;
2426
import org.apache.ws.commons.schema.XmlSchema;
@@ -104,14 +106,19 @@ public void setValidationEventHandler(ValidationEventHandler validationEventHand
104106

105107
public void afterPropertiesSet() throws IOException {
106108
Assert.notEmpty(xsdResources, "'xsds' must not be empty");
109+
110+
Set processedIncludes = new HashSet();
111+
Set processedImports = new HashSet();
112+
107113
for (int i = 0; i < xsdResources.length; i++) {
108114
Assert.isTrue(xsdResources[i].exists(), xsdResources[i] + " does not exit");
109-
XmlSchema xmlSchema =
110-
schemaCollection.read(SaxUtils.createInputSource(xsdResources[i]), validationEventHandler);
115+
XmlSchema xmlSchema = schemaCollection
116+
.read(SaxUtils.createInputSource(xsdResources[i]), validationEventHandler);
111117
xmlSchemas.add(xmlSchema);
118+
112119
if (inline) {
113-
inlineIncludes(xmlSchema, new ArrayList());
114-
findImports(xmlSchema, new ArrayList());
120+
inlineIncludes(xmlSchema, processedIncludes, processedImports);
121+
findImports(xmlSchema, processedImports, processedIncludes);
115122
}
116123
}
117124
}
@@ -134,18 +141,20 @@ public XmlValidator createValidator() throws IOException {
134141
return XmlValidatorFactory.createValidator(resources, XmlValidatorFactory.SCHEMA_W3C_XML);
135142
}
136143

137-
private void inlineIncludes(XmlSchema schema, List processedSchemas) {
138-
processedSchemas.add(schema);
144+
private void inlineIncludes(XmlSchema schema, Set processedIncludes, Set processedImports) {
145+
processedIncludes.add(schema);
139146
XmlSchemaObjectCollection includes = schema.getIncludes();
140147
for (int i = 0; i < includes.getCount(); i++) {
141-
XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i);
148+
XmlSchemaExternal external = (XmlSchemaExternal) includes
149+
.getItem(i);
142150
if (external instanceof XmlSchemaInclude) {
143151
XmlSchema includedSchema = external.getSchema();
144152
XmlSchemaObjectCollection items = schema.getItems();
145-
if (!processedSchemas.contains(includedSchema)) {
146-
inlineIncludes(includedSchema, processedSchemas);
147-
findImports(includedSchema, new ArrayList());
148-
XmlSchemaObjectCollection includeItems = includedSchema.getItems();
153+
if (!processedIncludes.contains(includedSchema)) {
154+
inlineIncludes(includedSchema, processedIncludes, processedImports);
155+
findImports(includedSchema, processedImports, processedIncludes);
156+
XmlSchemaObjectCollection includeItems = includedSchema
157+
.getItems();
149158
for (int j = 0; j < includeItems.getCount(); j++) {
150159
XmlSchemaObject includedItem = includeItems.getItem(j);
151160
items.add(includedItem);
@@ -157,18 +166,18 @@ private void inlineIncludes(XmlSchema schema, List processedSchemas) {
157166
}
158167
}
159168

160-
private void findImports(XmlSchema schema, List processedSchemas) {
161-
processedSchemas.add(schema);
162-
XmlSchemaObjectCollection imports = schema.getIncludes();
163-
for (int i = 0; i < imports.getCount(); i++) {
164-
XmlSchemaExternal external = (XmlSchemaExternal) imports.getItem(i);
169+
private void findImports(XmlSchema schema, Set processedImports, Set processedIncludes) {
170+
processedImports.add(schema);
171+
XmlSchemaObjectCollection includes = schema.getIncludes();
172+
for (int i = 0; i < includes.getCount(); i++) {
173+
XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i);
165174
if (external instanceof XmlSchemaImport) {
166175
XmlSchemaImport schemaImport = (XmlSchemaImport) external;
167176
XmlSchema importedSchema = schemaImport.getSchema();
168177
if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace()) &&
169-
importedSchema != null && !processedSchemas.contains(importedSchema)) {
170-
inlineIncludes(importedSchema, processedSchemas);
171-
findImports(importedSchema, processedSchemas);
178+
importedSchema != null && !processedImports.contains(importedSchema)) {
179+
inlineIncludes(importedSchema, processedIncludes, processedImports);
180+
findImports(importedSchema, processedImports, processedIncludes);
172181
xmlSchemas.add(importedSchema);
173182
}
174183
// remove the schemaLocation
@@ -191,5 +200,4 @@ public String toString() {
191200
return buffer.toString();
192201
}
193202

194-
195203
}

0 commit comments

Comments
 (0)