SWS-758 - Upgrade XmlSchemaCollection
This commit is contained in:
@@ -106,8 +106,8 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.schema</groupId>
|
||||
<artifactId>XmlSchema</artifactId>
|
||||
<groupId>org.apache.ws.xmlschema</groupId>
|
||||
<artifactId>xmlschema-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- SOAP dependencies -->
|
||||
|
||||
@@ -408,9 +408,9 @@
|
||||
<version>1.1.3.4.O</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.schema</groupId>
|
||||
<artifactId>XmlSchema</artifactId>
|
||||
<version>1.4.7</version>
|
||||
<groupId>org.apache.ws.xmlschema</groupId>
|
||||
<artifactId>xmlschema-core</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<!-- O/X Mapping dependencies -->
|
||||
<!-- XMLBeans -->
|
||||
|
||||
@@ -58,8 +58,8 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.schema</groupId>
|
||||
<artifactId>XmlSchema</artifactId>
|
||||
<groupId>org.apache.ws.xmlschema</groupId>
|
||||
<artifactId>xmlschema-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -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 <code>XmlSchema</code> object; must not be <code>null</code>
|
||||
* @throws IllegalArgumentException if the supplied <code>schema</code> is <code>null</code>
|
||||
@@ -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 <code>XmlSchema</code> object; must not be <code>null</code>
|
||||
@@ -83,12 +83,7 @@ public class CommonsXsdSchema implements XsdSchema {
|
||||
}
|
||||
|
||||
public QName[] getElementNames() {
|
||||
List<QName> result = new ArrayList<QName>();
|
||||
Iterator<?> iterator = schema.getElements().getNames();
|
||||
while (iterator.hasNext()) {
|
||||
QName name = (QName) iterator.next();
|
||||
result.add(name);
|
||||
}
|
||||
List<QName> result = new ArrayList<QName>(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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
* <p/>
|
||||
* Setting the {@link #setInline(boolean) inline} flag to <code>true</code> 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 <a href="http://ws.apache.org/commons/XmlSchema/">Commons XML Schema</a>
|
||||
@@ -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.
|
||||
* <p/>
|
||||
* Defaults to <code>false</code>.
|
||||
*/
|
||||
@@ -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.
|
||||
* <p/>
|
||||
@@ -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<XmlSchema> processedIncludes, Set<XmlSchema> processedImports) {
|
||||
processedIncludes.add(schema);
|
||||
|
||||
XmlSchemaObjectCollection schemaItems = schema.getItems();
|
||||
for (int i = 0; i < schemaItems.getCount(); i++) {
|
||||
XmlSchemaObject schemaObject = schemaItems.getItem(i);
|
||||
List<XmlSchemaObject> 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<XmlSchemaObject> includeItems = includedSchema.getItems();
|
||||
for (XmlSchemaObject includedItem : includeItems) {
|
||||
schemaItems.add(includedItem);
|
||||
}
|
||||
}
|
||||
// remove the <include/>
|
||||
schemaItems.removeAt(i);
|
||||
schemaItems.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -211,9 +199,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
|
||||
|
||||
private void findImports(XmlSchema schema, Set<XmlSchema> processedImports, Set<XmlSchema> processedIncludes) {
|
||||
processedImports.add(schema);
|
||||
XmlSchemaObjectCollection includes = schema.getIncludes();
|
||||
for (int i = 0; i < includes.getCount(); i++) {
|
||||
XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i);
|
||||
List<XmlSchemaExternal> externals = schema.getExternals();
|
||||
for (XmlSchemaExternal external : externals) {
|
||||
if (external instanceof XmlSchemaImport) {
|
||||
XmlSchemaImport schemaImport = (XmlSchemaImport) external;
|
||||
XmlSchema importedSchema = schemaImport.getSchema();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user