Skip to content

Commit 42dce0b

Browse files
committed
SWS-758 - Upgrade XmlSchemaCollection
1 parent b33d4a1 commit 42dce0b

File tree

6 files changed

+31
-44
lines changed

6 files changed

+31
-44
lines changed

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
<scope>test</scope>
107107
</dependency>
108108
<dependency>
109-
<groupId>org.apache.ws.commons.schema</groupId>
110-
<artifactId>XmlSchema</artifactId>
109+
<groupId>org.apache.ws.xmlschema</groupId>
110+
<artifactId>xmlschema-core</artifactId>
111111
<scope>test</scope>
112112
</dependency>
113113
<!-- SOAP dependencies -->

parent/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@
408408
<version>1.1.3.4.O</version>
409409
</dependency>
410410
<dependency>
411-
<groupId>org.apache.ws.commons.schema</groupId>
412-
<artifactId>XmlSchema</artifactId>
413-
<version>1.4.7</version>
411+
<groupId>org.apache.ws.xmlschema</groupId>
412+
<artifactId>xmlschema-core</artifactId>
413+
<version>2.0.2</version>
414414
</dependency>
415415
<!-- O/X Mapping dependencies -->
416416
<!-- XMLBeans -->

xml/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
<scope>test</scope>
5959
</dependency>
6060
<dependency>
61-
<groupId>org.apache.ws.commons.schema</groupId>
62-
<artifactId>XmlSchema</artifactId>
61+
<groupId>org.apache.ws.xmlschema</groupId>
62+
<artifactId>xmlschema-core</artifactId>
6363
<optional>true</optional>
6464
</dependency>
6565
</dependencies>

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.io.ByteArrayInputStream;
2020
import java.io.ByteArrayOutputStream;
2121
import java.io.IOException;
22+
import java.io.UnsupportedEncodingException;
2223
import java.util.ArrayList;
23-
import java.util.Iterator;
2424
import java.util.List;
2525
import javax.xml.namespace.QName;
2626
import javax.xml.transform.Source;
@@ -55,7 +55,7 @@ public class CommonsXsdSchema implements XsdSchema {
5555
private final XmlSchemaCollection collection;
5656

5757
/**
58-
* Create a new instance of the {@link CommonsXsdSchema} class with the specified {@link XmlSchema} reference.
58+
* Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} reference.
5959
*
6060
* @param schema the Commons <code>XmlSchema</code> object; must not be <code>null</code>
6161
* @throws IllegalArgumentException if the supplied <code>schema</code> is <code>null</code>
@@ -65,7 +65,7 @@ protected CommonsXsdSchema(XmlSchema schema) {
6565
}
6666

6767
/**
68-
* Create a new instance of the {@link CommonsXsdSchema} class with the specified {@link XmlSchema} and {@link
68+
* Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} and {@link
6969
* XmlSchemaCollection} reference.
7070
*
7171
* @param schema the Commons <code>XmlSchema</code> object; must not be <code>null</code>
@@ -83,12 +83,7 @@ public String getTargetNamespace() {
8383
}
8484

8585
public QName[] getElementNames() {
86-
List<QName> result = new ArrayList<QName>();
87-
Iterator<?> iterator = schema.getElements().getNames();
88-
while (iterator.hasNext()) {
89-
QName name = (QName) iterator.next();
90-
result.add(name);
91-
}
86+
List<QName> result = new ArrayList<QName>(schema.getElements().keySet());
9287
return result.toArray(new QName[result.size()]);
9388
}
9489

@@ -109,7 +104,12 @@ public Source getSource() {
109104
// ignore
110105
}
111106
ByteArrayOutputStream bos = new ByteArrayOutputStream();
112-
schema.write(bos);
107+
try {
108+
schema.write(bos);
109+
}
110+
catch (UnsupportedEncodingException ex) {
111+
throw new CommonsXsdSchemaException(ex.getMessage(), ex);
112+
}
113113
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
114114
return new StreamSource(bis);
115115
}

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@
3737

3838
import org.apache.commons.logging.Log;
3939
import org.apache.commons.logging.LogFactory;
40-
import org.apache.ws.commons.schema.ValidationEventHandler;
4140
import org.apache.ws.commons.schema.XmlSchema;
4241
import org.apache.ws.commons.schema.XmlSchemaCollection;
4342
import org.apache.ws.commons.schema.XmlSchemaExternal;
4443
import org.apache.ws.commons.schema.XmlSchemaImport;
4544
import org.apache.ws.commons.schema.XmlSchemaInclude;
4645
import org.apache.ws.commons.schema.XmlSchemaObject;
47-
import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
4846
import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
4947
import org.apache.ws.commons.schema.resolver.URIResolver;
5048
import org.xml.sax.InputSource;
@@ -54,7 +52,7 @@
5452
* <p/>
5553
* Setting the {@link #setInline(boolean) inline} flag to <code>true</code> will result in all referenced schemas
5654
* (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.
5856
*
5957
* @author Arjen Poutsma
6058
* @see <a href="http://ws.apache.org/commons/XmlSchema/">Commons XML Schema</a>
@@ -72,8 +70,6 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
7270

7371
private boolean inline = false;
7472

75-
private ValidationEventHandler validationEventHandler;
76-
7773
private URIResolver uriResolver = new ClasspathUriResolver();
7874

7975
private ResourceLoader resourceLoader;
@@ -105,21 +101,14 @@ public void setXsds(Resource[] xsdResources) {
105101
}
106102

107103
/**
108-
* Defines whether included schemas should be inlinded into the including schema.
104+
* Defines whether included schemas should be inlined into the including schema.
109105
* <p/>
110106
* Defaults to <code>false</code>.
111107
*/
112108
public void setInline(boolean inline) {
113109
this.inline = inline;
114110
}
115111

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-
123112
/**
124113
* Sets the WS-Commons uri resolver to use when resolving (relative) schemas.
125114
* <p/>
@@ -146,7 +135,7 @@ public void afterPropertiesSet() throws IOException {
146135
Assert.isTrue(xsdResource.exists(), xsdResource + " does not exit");
147136
try {
148137
XmlSchema xmlSchema =
149-
schemaCollection.read(SaxUtils.createInputSource(xsdResource), validationEventHandler);
138+
schemaCollection.read(SaxUtils.createInputSource(xsdResource));
150139
xmlSchemas.add(xmlSchema);
151140

152141
if (inline) {
@@ -188,32 +177,30 @@ public XmlValidator createValidator() throws IOException {
188177
private void inlineIncludes(XmlSchema schema, Set<XmlSchema> processedIncludes, Set<XmlSchema> processedImports) {
189178
processedIncludes.add(schema);
190179

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);
194183
if (schemaObject instanceof XmlSchemaInclude) {
195184
XmlSchema includedSchema = ((XmlSchemaInclude) schemaObject).getSchema();
196185
if (!processedIncludes.contains(includedSchema)) {
197186
inlineIncludes(includedSchema, processedIncludes, processedImports);
198187
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) {
202190
schemaItems.add(includedItem);
203191
}
204192
}
205193
// remove the <include/>
206-
schemaItems.removeAt(i);
194+
schemaItems.remove(i);
207195
i--;
208196
}
209197
}
210198
}
211199

212200
private void findImports(XmlSchema schema, Set<XmlSchema> processedImports, Set<XmlSchema> processedIncludes) {
213201
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) {
217204
if (external instanceof XmlSchemaImport) {
218205
XmlSchemaImport schemaImport = (XmlSchemaImport) external;
219206
XmlSchema importedSchema = schemaImport.getSchema();

xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -38,7 +38,7 @@ public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
3838
@Override
3939
protected XsdSchema createSchema(Resource resource) throws Exception {
4040
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
41-
XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource), null);
41+
XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource));
4242
return new CommonsXsdSchema(schema);
4343
}
4444

0 commit comments

Comments
 (0)