diff --git a/core/pom.xml b/core/pom.xml index 9d6f0749..98b1bd1b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -106,8 +106,8 @@ test - org.apache.ws.commons.schema - XmlSchema + org.apache.ws.xmlschema + xmlschema-core test diff --git a/parent/pom.xml b/parent/pom.xml index 8af0a204..35412aa0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -408,9 +408,9 @@ 1.1.3.4.O - org.apache.ws.commons.schema - XmlSchema - 1.4.7 + org.apache.ws.xmlschema + xmlschema-core + 2.0.2 diff --git a/xml/pom.xml b/xml/pom.xml index 302cc188..fc26d749 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -58,8 +58,8 @@ test - org.apache.ws.commons.schema - XmlSchema + org.apache.ws.xmlschema + xmlschema-core true diff --git a/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchema.java b/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchema.java index ebe0c5b6..ad466a28 100644 --- a/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchema.java +++ b/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchema.java @@ -19,8 +19,8 @@ package org.springframework.xml.xsd.commons; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; import javax.xml.transform.Source; @@ -55,7 +55,7 @@ public class CommonsXsdSchema implements XsdSchema { private final XmlSchemaCollection collection; /** - * Create a new instance of the {@link CommonsXsdSchema} class with the specified {@link XmlSchema} reference. + * Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} reference. * * @param schema the Commons XmlSchema object; must not be null * @throws IllegalArgumentException if the supplied schema is null @@ -65,7 +65,7 @@ public class CommonsXsdSchema implements XsdSchema { } /** - * Create a new instance of the {@link CommonsXsdSchema} class with the specified {@link XmlSchema} and {@link + * Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} and {@link * XmlSchemaCollection} reference. * * @param schema the Commons XmlSchema object; must not be null @@ -83,12 +83,7 @@ public class CommonsXsdSchema implements XsdSchema { } public QName[] getElementNames() { - List result = new ArrayList(); - Iterator iterator = schema.getElements().getNames(); - while (iterator.hasNext()) { - QName name = (QName) iterator.next(); - result.add(name); - } + List result = new ArrayList(schema.getElements().keySet()); return result.toArray(new QName[result.size()]); } @@ -109,7 +104,12 @@ public class CommonsXsdSchema implements XsdSchema { // ignore } ByteArrayOutputStream bos = new ByteArrayOutputStream(); - schema.write(bos); + try { + schema.write(bos); + } + catch (UnsupportedEncodingException ex) { + throw new CommonsXsdSchemaException(ex.getMessage(), ex); + } ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); return new StreamSource(bis); } diff --git a/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java b/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java index d1a96d15..f6a3d609 100644 --- a/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java +++ b/xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java @@ -37,14 +37,12 @@ import org.springframework.xml.xsd.XsdSchemaCollection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.ws.commons.schema.ValidationEventHandler; import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaCollection; import org.apache.ws.commons.schema.XmlSchemaExternal; import org.apache.ws.commons.schema.XmlSchemaImport; import org.apache.ws.commons.schema.XmlSchemaInclude; import org.apache.ws.commons.schema.XmlSchemaObject; -import org.apache.ws.commons.schema.XmlSchemaObjectCollection; import org.apache.ws.commons.schema.resolver.DefaultURIResolver; import org.apache.ws.commons.schema.resolver.URIResolver; import org.xml.sax.InputSource; @@ -54,7 +52,7 @@ import org.xml.sax.InputSource; *

* Setting the {@link #setInline(boolean) inline} flag to true will result in all referenced schemas * (included and imported) being merged into the referred schema. When including the schemas into a WSDL, this greatly - * simplifies the deloyment of the schemas. + * simplifies the deployment of the schemas. * * @author Arjen Poutsma * @see Commons XML Schema @@ -72,8 +70,6 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali private boolean inline = false; - private ValidationEventHandler validationEventHandler; - private URIResolver uriResolver = new ClasspathUriResolver(); private ResourceLoader resourceLoader; @@ -105,7 +101,7 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali } /** - * Defines whether included schemas should be inlinded into the including schema. + * Defines whether included schemas should be inlined into the including schema. *

* Defaults to false. */ @@ -113,13 +109,6 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali this.inline = inline; } - /** - * Sets the WS-Commons validation event handler to use while parsing schemas. - */ - public void setValidationEventHandler(ValidationEventHandler validationEventHandler) { - this.validationEventHandler = validationEventHandler; - } - /** * Sets the WS-Commons uri resolver to use when resolving (relative) schemas. *

@@ -146,7 +135,7 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali Assert.isTrue(xsdResource.exists(), xsdResource + " does not exit"); try { XmlSchema xmlSchema = - schemaCollection.read(SaxUtils.createInputSource(xsdResource), validationEventHandler); + schemaCollection.read(SaxUtils.createInputSource(xsdResource)); xmlSchemas.add(xmlSchema); if (inline) { @@ -188,22 +177,21 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali private void inlineIncludes(XmlSchema schema, Set processedIncludes, Set processedImports) { processedIncludes.add(schema); - XmlSchemaObjectCollection schemaItems = schema.getItems(); - for (int i = 0; i < schemaItems.getCount(); i++) { - XmlSchemaObject schemaObject = schemaItems.getItem(i); + List schemaItems = schema.getItems(); + for (int i = 0; i < schemaItems.size(); i++) { + XmlSchemaObject schemaObject = schemaItems.get(i); if (schemaObject instanceof XmlSchemaInclude) { XmlSchema includedSchema = ((XmlSchemaInclude) schemaObject).getSchema(); if (!processedIncludes.contains(includedSchema)) { inlineIncludes(includedSchema, processedIncludes, processedImports); findImports(includedSchema, processedImports, processedIncludes); - XmlSchemaObjectCollection includeItems = includedSchema.getItems(); - for (int j = 0; j < includeItems.getCount(); j++) { - XmlSchemaObject includedItem = includeItems.getItem(j); + List includeItems = includedSchema.getItems(); + for (XmlSchemaObject includedItem : includeItems) { schemaItems.add(includedItem); } } // remove the - schemaItems.removeAt(i); + schemaItems.remove(i); i--; } } @@ -211,9 +199,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali private void findImports(XmlSchema schema, Set processedImports, Set processedIncludes) { processedImports.add(schema); - XmlSchemaObjectCollection includes = schema.getIncludes(); - for (int i = 0; i < includes.getCount(); i++) { - XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i); + List externals = schema.getExternals(); + for (XmlSchemaExternal external : externals) { if (external instanceof XmlSchemaImport) { XmlSchemaImport schemaImport = (XmlSchemaImport) external; XmlSchema importedSchema = schemaImport.getSchema(); diff --git a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java index af87f9f5..eb65969b 100644 --- a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java +++ b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,7 +38,7 @@ public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase { @Override protected XsdSchema createSchema(Resource resource) throws Exception { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); - XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource), null); + XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource)); return new CommonsXsdSchema(schema); }