diff --git a/pom.xml b/pom.xml
index 3eb6f390..630c59d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -566,6 +566,12 @@
wsdl4j
1.6.1
+
+
+ org.apache.ws.commons.schema
+ XmlSchema
+ 1.3.2
+
com.sun.xml.wss
@@ -637,20 +643,20 @@
true
- javax.mail
- mail
+ javax.mail
+ mail
- javax.jms
- jms
+ javax.jms
+ jms
-
- com.sun.jdmk
- jmxtools
+
+ com.sun.jdmk
+ jmxtools
-
- com.sun.jmx
- jmxri
+
+ com.sun.jmx
+ jmxri
diff --git a/xml/pom.xml b/xml/pom.xml
index 83560ec5..c16ea6f1 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -1,4 +1,5 @@
-
+
spring-ws
org.springframework.ws
@@ -73,6 +74,12 @@
wstx-asl
test
+
+
+ org.apache.ws.commons.schema
+ XmlSchema
+ true
+
easymock
diff --git a/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java b/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java
new file mode 100644
index 00000000..1971f845
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2007 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
+import org.springframework.xml.namespace.QNameUtils;
+import org.springframework.xml.sax.SaxUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Simple implementation of the {@link XsdSchema} interface. Only wraps a single {@link XsdSchemaDocument}, and does not
+ * follow <xsd:include/> nor <xsd:import/> elements.
+ *
+ * Allows an XSD {@link Resource resource} to be set by the {@link #setSchema(Resource) schema} property, or directly in
+ * the {@link #SimpleXsdSchema(Resource) constructor}.
+ *
+ * @author Arjen Poutsma
+ * @since 1.0.2
+ */
+public class SimpleXsdSchema implements XsdSchema, InitializingBean {
+
+ private static final String SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
+
+ /** The schema qualified name. */
+ private static final QName SCHEMA_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "schema", "xsd");
+
+ /** The element declaration qualified name. */
+ private static final QName ELEMENT_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "element", "xsd");
+
+ private final XsdSchemaDocument[] schemaDocuments = new XsdSchemaDocument[]{new SimpleXsdSchemaDocument()};
+
+ private Resource schemaResource;
+
+ private Element schemaElement;
+
+ /**
+ * Create a new instance of the {@link SimpleXsdSchema} class.
+ *
+ * A subsequent call to the {@link #setSchema(Resource)} method is required.
+ */
+ public SimpleXsdSchema() {
+ }
+
+ /**
+ * Create a new instance of the {@link SimpleXsdSchema} class with the specified resource.
+ *
+ * @param schemaResource the XSD resource; must not be null
+ * @throws IllegalArgumentException if the supplied schemaResource is null
+ */
+ public SimpleXsdSchema(Resource schemaResource) {
+ setSchema(schemaResource);
+ }
+
+ /** Set the XSD resource to be used. */
+ public void setSchema(Resource schemaResource) {
+ this.schemaResource = schemaResource;
+ }
+
+ public XsdSchemaDocument[] getSchemaDocuments() {
+ return schemaDocuments;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ Assert.notNull(schemaResource, "'schema' is required");
+ Assert.isTrue(schemaResource.exists(), "schema '" + schemaResource + "' does not exit");
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.parse(SaxUtils.createInputSource(schemaResource));
+ schemaElement = document.getDocumentElement();
+ QName name = QNameUtils.getQNameForNode(schemaElement);
+ Assert.isTrue(SCHEMA_NAME.equals(name),
+ "schema document has invalid qualified name: " + name + ". " + "Epected " + SCHEMA_NAME);
+ Assert.hasLength(schemaElement.getAttribute("targetNamespace"), "schema does not define targetNamespace");
+ }
+
+ /** Inner definition of {@link SimpleXsdSchemaDocument}. */
+ private class SimpleXsdSchemaDocument implements XsdSchemaDocument {
+
+ public String getFilename() {
+ return schemaResource.getFilename();
+ }
+
+ public Source getSource() {
+ return new DOMSource(schemaElement);
+ }
+
+ public XsdElementDeclaration[] getElementDeclarations() {
+ NodeList children = schemaElement.getChildNodes();
+ List declarations = new ArrayList(children.getLength());
+ for (int i = 0; i < children.getLength(); i++) {
+ if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
+ Element childElement = (Element) children.item(i);
+ QName childName = QNameUtils.getQNameForNode(childElement);
+ if (ELEMENT_NAME.equals(childName)) {
+ declarations.add(new SimpleXsdElementDeclaration(childElement));
+ }
+ }
+ }
+ return (XsdElementDeclaration[]) declarations.toArray(new XsdElementDeclaration[declarations.size()]);
+ }
+
+ public String getTargetNamespace() {
+ return schemaElement.getAttribute("targetNamespace");
+ }
+
+ /** Inner definition of {@link SimpleXsdElementDeclaration}. */
+ private class SimpleXsdElementDeclaration implements XsdElementDeclaration {
+
+ private final Element element;
+
+ private SimpleXsdElementDeclaration(Element element) {
+ this.element = element;
+ }
+
+ public QName getName() {
+ String attributeValue = element.getAttribute("name");
+ return StringUtils.hasLength(attributeValue) ? new QName(getTargetNamespace(), attributeValue) : null;
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/xml/src/main/java/org/springframework/xml/xsd/WsCommonsXsdSchema.java b/xml/src/main/java/org/springframework/xml/xsd/WsCommonsXsdSchema.java
new file mode 100644
index 00000000..5ee2d251
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/WsCommonsXsdSchema.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2007 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
+import org.springframework.xml.sax.SaxUtils;
+
+/**
+ * Implementation of the {@link XsdSchema} interface that uses Apache
+ * WS Commons XMLSchema. Allows for multiple {@link XsdSchemaDocument}s, and follows
+ * <xsd:include/> and <xsd:import/> elements.
+ *
+ * Allows an XSD {@link Resource resource} to be set by the {@link #setSchema(Resource) schema} or {@link
+ * #setSchemas(Resource[]) schemas} properties, or directly in the {@link #WsCommonsXsdSchema(Resource)} or {@link
+ * #WsCommonsXsdSchema(Resource[])} constructors.
+ *
+ * @author Arjen Poutsma
+ * @since 1.0.2
+ */
+public class WsCommonsXsdSchema implements XsdSchema, InitializingBean {
+
+ private Resource[] schemaResources;
+
+ private XsdSchemaDocument[] schemaDocuments;
+
+ /**
+ * Create a new instance of the {@link WsCommonsXsdSchema} class.
+ *
+ * A subsequent call to the {@link #setSchema(Resource)} or {@link #setSchemas(Resource[])} method is required.
+ */
+ public WsCommonsXsdSchema() {
+ }
+
+ /**
+ * Create a new instance of the {@link WsCommonsXsdSchema} class with the specified single resource.
+ *
+ * @param schemaResource the XSD resource; must not be null
+ * @throws IllegalArgumentException if the supplied schemaResource is null
+ */
+ public WsCommonsXsdSchema(Resource schemaResource) {
+ setSchema(schemaResource);
+ }
+
+ /**
+ * Create a new instance of the {@link WsCommonsXsdSchema} class with the specified resources.
+ *
+ * @param schemaResources the XSD resources; must not be null or empty
+ * @throws IllegalArgumentException if the supplied schemaResource is null
+ */
+ public WsCommonsXsdSchema(Resource[] schemaResources) {
+ setSchemas(schemaResources);
+ }
+
+ /** Set the XSD resource to be used. */
+ public void setSchema(Resource schemaResource) {
+ this.schemaResources = new Resource[]{schemaResource};
+ }
+
+ /** Set the XSD resources to be used. */
+ public void setSchemas(Resource[] schemaResources) {
+ this.schemaResources = schemaResources;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ Assert.notEmpty(schemaResources, "'schemaResources' must not be empty");
+ XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
+ for (int i = 0; i < schemaResources.length; i++) {
+ Resource schemaResource = schemaResources[i];
+ Assert.notNull(schemaResource, "'schemaResource' must not be null");
+ Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exist");
+ schemaCollection.read(SaxUtils.createInputSource(schemaResource), null);
+ }
+ XmlSchema[] schemas = schemaCollection.getXmlSchemas();
+ List schemaList = new ArrayList(schemaResources.length);
+ for (int i = 0; i < schemas.length; i++) {
+ if (!schemas[i].getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema")) {
+ schemaList.add(new WsCommonsXsdSchemaDocument(schemas[i]));
+ }
+ }
+ this.schemaDocuments = (XsdSchemaDocument[]) schemaList.toArray(new XsdSchemaDocument[schemaList.size()]);
+ }
+
+ public XsdSchemaDocument[] getSchemaDocuments() {
+ return schemaDocuments;
+ }
+
+ /** Inner definition of {@link WsCommonsXsdSchemaDocument}. */
+ private static class WsCommonsXsdSchemaDocument implements XsdSchemaDocument {
+
+ private final XmlSchema commonsSchema;
+
+ private WsCommonsXsdSchemaDocument(XmlSchema commonsSchema) {
+ this.commonsSchema = commonsSchema;
+ }
+
+ public String getFilename() {
+ return StringUtils.getFilename(commonsSchema.getSourceURI());
+ }
+
+ public Source getSource() {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ commonsSchema.write(bos);
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ return new StreamSource(bis);
+ }
+
+ public XsdElementDeclaration[] getElementDeclarations() {
+ XmlSchemaObjectTable elements = commonsSchema.getElements();
+ XsdElementDeclaration[] declarations = new XsdElementDeclaration[elements.getCount()];
+ int i = 0;
+ for (Iterator iterator = elements.getValues(); iterator.hasNext();) {
+ XmlSchemaElement element = (XmlSchemaElement) iterator.next();
+ declarations[i] = new WsCommonsXsdElementDeclaration(element);
+ i++;
+ }
+ return declarations;
+ }
+
+ public String getTargetNamespace() {
+ return commonsSchema.getTargetNamespace();
+ }
+
+ }
+
+ private static class WsCommonsXsdElementDeclaration implements XsdElementDeclaration {
+
+ private final XmlSchemaElement element;
+
+ private WsCommonsXsdElementDeclaration(XmlSchemaElement element) {
+ this.element = element;
+ }
+
+ public QName getName() {
+ return element.getQName();
+ }
+ }
+}
diff --git a/xml/src/main/java/org/springframework/xml/xsd/XsdElementDeclaration.java b/xml/src/main/java/org/springframework/xml/xsd/XsdElementDeclaration.java
new file mode 100644
index 00000000..8a14c289
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/XsdElementDeclaration.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2007 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Represents an abstraction for an XSD element declaration.
+ *
+ * @author Arjen Poutsma
+ * @see XsdSchemaDocument#getElementDeclarations()
+ * @since 1.0.2
+ */
+public interface XsdElementDeclaration {
+
+ /** Returns the qualified name of the element declaration. */
+ QName getName();
+
+}
diff --git a/xml/src/main/java/org/springframework/xml/xsd/XsdSchema.java b/xml/src/main/java/org/springframework/xml/xsd/XsdSchema.java
new file mode 100644
index 00000000..a51976c1
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/XsdSchema.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2007 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+/**
+ * Represents an abstraction for an XSD schema document. A schema is made up of one or more schema documents.
+ *
+ * @author Arjen Poutsma
+ * @see XsdSchemaDocument
+ * @since 1.0.2
+ */
+public interface XsdSchema {
+
+ /** Returns the {@link XsdSchemaDocument} objects this schema consists of. */
+ XsdSchemaDocument[] getSchemaDocuments();
+
+}
diff --git a/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java b/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java
new file mode 100644
index 00000000..61b217bd
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java
@@ -0,0 +1,30 @@
+package org.springframework.xml.xsd;
+
+import javax.xml.transform.Source;
+
+/**
+ * Represents an abstraction for an individual XSD schema document. A schema is made up of one or more schema
+ * documents.
+ *
+ * @author Arjen Poutsma
+ * @see XsdSchema
+ * @since 1.0.2
+ */
+public interface XsdSchemaDocument {
+
+ /** Return a filename for this schema document. For example, schema.xsd. */
+ String getFilename();
+
+ /** Returns the target namespace of the schema. */
+ String getTargetNamespace();
+
+ /**
+ * Returns the Source of the schema.
+ *
+ * @return the Source of this XSD schema
+ */
+ Source getSource();
+
+ XsdElementDeclaration[] getElementDeclarations();
+
+}
diff --git a/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaException.java b/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaException.java
new file mode 100644
index 00000000..261c2f4b
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2006 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import org.springframework.xml.XmlException;
+
+/**
+ * Base class for all XSD schema exceptions.
+ *
+ * @author Arjen Poutsma
+ * @since 1.0.2
+ */
+public class XsdSchemaException extends XmlException {
+
+ public XsdSchemaException(String reason) {
+ super(reason);
+ }
+
+ public XsdSchemaException(String reason, Throwable throwable) {
+ super(reason, throwable);
+ }
+}
\ No newline at end of file
diff --git a/xml/src/main/java/org/springframework/xml/xsd/package.html b/xml/src/main/java/org/springframework/xml/xsd/package.html
new file mode 100644
index 00000000..e7ef41ec
--- /dev/null
+++ b/xml/src/main/java/org/springframework/xml/xsd/package.html
@@ -0,0 +1,6 @@
+
+
+Provides the XSD functionality of the Spring Web Services framework. Contains the XsdSchema and XsdSchemaDocument
+interfaces.
+
+
diff --git a/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java b/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java
new file mode 100644
index 00000000..39e9db7c
--- /dev/null
+++ b/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2007 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
+
+ private DocumentBuilder documentBuilder;
+
+ private Transformer transformer;
+
+ protected final void setUp() throws Exception {
+ XMLUnit.setIgnoreWhitespace(true);
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ transformer = transformerFactory.newTransformer();
+ }
+
+ protected abstract XsdSchema createSchemaInternal(Resource[] schemaResources) throws Exception;
+
+ protected XsdSchema createSchema(Resource[] schemaResources) throws Exception {
+ XsdSchema schema = createSchemaInternal(schemaResources);
+ if (schema instanceof InitializingBean) {
+ ((InitializingBean) schema).afterPropertiesSet();
+ }
+ return schema;
+ }
+
+ public void testSingleDocument() throws Exception {
+ XsdSchema schema =
+ createSchema(new Resource[]{new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class)});
+ XsdSchemaDocument[] documents = schema.getSchemaDocuments();
+ assertEquals("Invalid amount of schema documents", 1, documents.length);
+ XsdSchemaDocument document = documents[0];
+ assertNotNull("Document is null", document);
+ assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/single",
+ document.getTargetNamespace());
+ verifyDocument("single.xsd", document);
+ XsdElementDeclaration[] declarations = document.getElementDeclarations();
+ assertEquals("Invalid amount of element declarations", 1, declarations.length);
+ XsdElementDeclaration declaration = declarations[0];
+ assertEquals("Invalid element declaration name",
+ new QName("http://www.springframework.org/spring-ws/single", "root"), declaration.getName());
+ }
+
+ public void testInclude() throws Exception {
+ XsdSchema schema =
+ createSchema(new Resource[]{new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class)});
+ XsdSchemaDocument[] documents = schema.getSchemaDocuments();
+ assertEquals("Invalid amount of schema documents", 2, documents.length);
+ assertNotNull("Document is null", documents[0]);
+ assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include",
+ documents[0].getTargetNamespace());
+ verifyDocument("including.xsd", documents[0]);
+ assertEquals("Invalid amount of element declarations", 1, documents[0].getElementDeclarations().length);
+ assertEquals("Invalid element declaration name",
+ new QName("http://www.springframework.org/spring-ws/include", "customElement"),
+ documents[0].getElementDeclarations()[0].getName());
+ assertNotNull("Document is null", documents[1]);
+ assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include",
+ documents[1].getTargetNamespace());
+ verifyDocument("included.xsd", documents[1]);
+ assertEquals("Invalid amount of element declarations", 1, documents[1].getElementDeclarations().length);
+ assertEquals("Invalid element declaration name",
+ new QName("http://www.springframework.org/spring-ws/include", "stringElement"),
+ documents[1].getElementDeclarations()[0].getName());
+ }
+
+ public void testImport() throws Exception {
+ XsdSchema schema =
+ createSchema(new Resource[]{new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class)});
+ XsdSchemaDocument[] documents = schema.getSchemaDocuments();
+ assertEquals("Invalid amount of schema documents", 2, documents.length);
+ assertNotNull("Document is null", documents[0]);
+ assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing",
+ documents[0].getTargetNamespace());
+ verifyDocument("importing.xsd", documents[0]);
+ assertEquals("Invalid amount of element declarations", 1, documents[0].getElementDeclarations().length);
+ assertEquals("Invalid element declaration name",
+ new QName("http://www.springframework.org/spring-ws/importing", "customElement"),
+ documents[0].getElementDeclarations()[0].getName());
+ assertNotNull("Document is null", documents[1]);
+ assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/imported",
+ documents[1].getTargetNamespace());
+ assertEquals("Invalid amount of element declarations", 1, documents[1].getElementDeclarations().length);
+ assertEquals("Invalid element declaration name",
+ new QName("http://www.springframework.org/spring-ws/imported", "stringElement"),
+ documents[1].getElementDeclarations()[0].getName());
+ }
+
+ private void verifyDocument(String filename, XsdSchemaDocument document)
+ throws IOException, SAXException, TransformerException {
+ assertEquals("Invalid document filename", filename, document.getFilename());
+ InputStream inputStream = AbstractXsdSchemaTestCase.class.getResourceAsStream(filename);
+ try {
+ Document expected = documentBuilder.parse(inputStream);
+ DOMResult result = new DOMResult();
+ transformer.transform(document.getSource(), result);
+ assertXMLEqual("Invalid source returned", expected, (Document) result.getNode());
+ }
+ finally {
+ inputStream.close();
+ }
+ }
+
+}
diff --git a/xml/src/test/java/org/springframework/xml/xsd/SimpleXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/xsd/SimpleXsdSchemaTest.java
new file mode 100644
index 00000000..ff04a0d9
--- /dev/null
+++ b/xml/src/test/java/org/springframework/xml/xsd/SimpleXsdSchemaTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright ${YEAR} 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import org.springframework.core.io.Resource;
+
+public class SimpleXsdSchemaTest extends AbstractXsdSchemaTestCase {
+
+ protected XsdSchema createSchemaInternal(Resource[] schemaResources) throws Exception {
+ return new SimpleXsdSchema(schemaResources[0]);
+ }
+
+ public void testInclude() throws Exception {
+ }
+
+ public void testImport() throws Exception {
+ }
+}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/xsd/WsCommonsXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/xsd/WsCommonsXsdSchemaTest.java
new file mode 100644
index 00000000..443a0937
--- /dev/null
+++ b/xml/src/test/java/org/springframework/xml/xsd/WsCommonsXsdSchemaTest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright ${YEAR} 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.xml.xsd;
+
+import java.io.IOException;
+
+import org.springframework.core.io.Resource;
+
+public class WsCommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
+
+ protected XsdSchema createSchemaInternal(Resource[] schemaResources) throws IOException {
+ return new WsCommonsXsdSchema(schemaResources);
+ }
+
+}
\ No newline at end of file
diff --git a/xml/src/test/resources/org/springframework/xml/xsd/imported.xsd b/xml/src/test/resources/org/springframework/xml/xsd/imported.xsd
new file mode 100644
index 00000000..d8fdde47
--- /dev/null
+++ b/xml/src/test/resources/org/springframework/xml/xsd/imported.xsd
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/org/springframework/xml/xsd/importing.xsd b/xml/src/test/resources/org/springframework/xml/xsd/importing.xsd
new file mode 100644
index 00000000..386e2131
--- /dev/null
+++ b/xml/src/test/resources/org/springframework/xml/xsd/importing.xsd
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/org/springframework/xml/xsd/included.xsd b/xml/src/test/resources/org/springframework/xml/xsd/included.xsd
new file mode 100644
index 00000000..11cf4341
--- /dev/null
+++ b/xml/src/test/resources/org/springframework/xml/xsd/included.xsd
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/org/springframework/xml/xsd/including.xsd b/xml/src/test/resources/org/springframework/xml/xsd/including.xsd
new file mode 100644
index 00000000..6c569d4c
--- /dev/null
+++ b/xml/src/test/resources/org/springframework/xml/xsd/including.xsd
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/org/springframework/xml/xsd/single.xsd b/xml/src/test/resources/org/springframework/xml/xsd/single.xsd
new file mode 100644
index 00000000..57935389
--- /dev/null
+++ b/xml/src/test/resources/org/springframework/xml/xsd/single.xsd
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file