diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/AbstractBindingWsdl4jDefinitionBuilder.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/AbstractBindingWsdl4jDefinitionBuilder.java index bb956ef6..924bb47c 100644 --- a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/AbstractBindingWsdl4jDefinitionBuilder.java +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/AbstractBindingWsdl4jDefinitionBuilder.java @@ -33,8 +33,6 @@ import javax.wsdl.Service; import javax.wsdl.WSDLException; import javax.xml.namespace.QName; -import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinitionException; - /** * Abstract base class for Wsdl11DefinitionBuilder implementations that use WSDL4J and contain a concrete * part. Creates a binding that matches any present portType, and a service containing @@ -73,19 +71,14 @@ public abstract class AbstractBindingWsdl4jDefinitionBuilder extends AbstractWsd * @see #populateBindingFault(javax.wsdl.BindingFault,javax.wsdl.Fault) */ public void buildBindings(Definition definition) throws WSDLException { - try { - for (Iterator iterator = definition.getPortTypes().values().iterator(); iterator.hasNext();) { - PortType portType = (PortType) iterator.next(); - Binding binding = definition.createBinding(); - binding.setPortType(portType); - populateBinding(binding, portType); - createBindingOperations(definition, binding, portType); - binding.setUndefined(false); - definition.addBinding(binding); - } - } - catch (WSDLException ex) { - throw new Wsdl4jDefinitionException(ex); + for (Iterator iterator = definition.getPortTypes().values().iterator(); iterator.hasNext();) { + PortType portType = (PortType) iterator.next(); + Binding binding = definition.createBinding(); + binding.setPortType(portType); + populateBinding(binding, portType); + createBindingOperations(definition, binding, portType); + binding.setUndefined(false); + definition.addBinding(binding); } } diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java index c9bca7d7..21b71d1b 100644 --- a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java @@ -18,6 +18,7 @@ package org.springframework.ws.wsdl.wsdl11.builder; import java.io.IOException; import java.util.Iterator; +import java.util.List; import javax.wsdl.Definition; import javax.wsdl.Fault; import javax.wsdl.Input; @@ -42,10 +43,8 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition; 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.NodeList; import org.xml.sax.SAXException; /** @@ -83,14 +82,6 @@ import org.xml.sax.SAXException; public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jDefinitionBuilder implements InitializingBean { - /** The schema qualified name. */ - private static final QName SCHEMA_NAME = - QNameUtils.createQName("http://www.w3.org/2001/XMLSchema", "schema", "xsd"); - - /** The schema import qualified name. */ - private static final QName IMPORT_NAME = - QNameUtils.createQName("http://www.w3.org/2001/XMLSchema", "import", "xsd"); - /** The default suffix used to detect request elements in the schema. */ public static final String DEFAULT_REQUEST_SUFFIX = "Request"; @@ -109,12 +100,12 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD /** The suffix used to create a service name from a port type name. */ public static final String SERVICE_SUFFIX = "Service"; - private Resource schema; + private Resource schemaResource; + + private XsdSchemaHelper schemaHelper; private String schemaLocation; - private Element schemaElement; - private String targetNamespace; private String portTypeName; @@ -129,13 +120,7 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD private String faultSuffix = DEFAULT_FAULT_SUFFIX; - private String schemaTargetNamespace; - - private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - - static { - documentBuilderFactory.setNamespaceAware(true); - } + private boolean followIncludeImport = false; /** * Sets the suffix used to detect request elements in the schema. @@ -193,10 +178,10 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD } /** Sets the XSD schema to use for generating the WSDL. */ - public void setSchema(Resource schema) { - Assert.notNull(schema, "schema must not be empty or null"); - Assert.isTrue(schema.exists(), "schema \"" + schema + "\" does not exit"); - this.schema = schema; + public void setSchema(Resource schemaResource) { + Assert.notNull(schemaResource, "'schema' must not be null"); + Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit"); + this.schemaResource = schemaResource; } /** @@ -208,39 +193,29 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD this.schemaLocation = schemaLocation; } + /** + * Indicates whether schema <xsd:include/> and <xsd:import/> should be + * followed. + */ + public void setFollowIncludeImport(boolean followIncludeImport) { + this.followIncludeImport = followIncludeImport; + } + public final void afterPropertiesSet() throws IOException, ParserConfigurationException, SAXException { - Assert.notNull(schema, "schema is required"); - Assert.notNull(portTypeName, "portTypeName is required"); - parseSchema(); - } - - private void parseSchema() throws ParserConfigurationException, SAXException, IOException { - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document schemaDocument = documentBuilder.parse(SaxUtils.createInputSource(schema)); - schemaElement = schemaDocument.getDocumentElement(); - Assert.isTrue(SCHEMA_NAME.getLocalPart().equals(schemaElement.getLocalName()), - "schema document root element has invalid local name : [" + schemaElement.getLocalName() + - "] instead of [schema]"); - Assert.isTrue(SCHEMA_NAME.getNamespaceURI().equals(schemaElement.getNamespaceURI()), - "schema document root element has invalid namespace uri: [" + schemaElement.getNamespaceURI() + - "] instead of [" + SCHEMA_NAME.getNamespaceURI() + "]"); - schemaTargetNamespace = getSchemaTargetNamespace(); - Assert.hasLength(schemaTargetNamespace, "schema document has no targetNamespace"); + Assert.notNull(schemaResource, "'schema' is required"); + Assert.notNull(portTypeName, "'portTypeName' is required"); + schemaHelper = new XsdSchemaHelper(schemaResource); if (!StringUtils.hasLength(targetNamespace)) { - targetNamespace = schemaTargetNamespace; + targetNamespace = schemaHelper.getTargetNamespace(); } } - private String getSchemaTargetNamespace() { - return schemaElement.getAttribute("targetNamespace"); - } - /** Adds the target namespace and schema namespace to the definition. */ protected void populateDefinition(Definition definition) throws WSDLException { super.populateDefinition(definition); definition.setTargetNamespace(targetNamespace); - definition.addNamespace(schemaPrefix, getSchemaTargetNamespace()); - if (!targetNamespace.equals(getSchemaTargetNamespace())) { + definition.addNamespace(schemaPrefix, schemaHelper.getTargetNamespace()); + if (!targetNamespace.equals(schemaHelper.getTargetNamespace())) { definition.addNamespace(prefix, targetNamespace); } } @@ -259,28 +234,28 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD */ protected void buildTypes(Definition definition) throws WSDLException { Types types = definition.createTypes(); - Schema schema; + Schema schema = (Schema) createExtension(Types.class, XsdSchemaHelper.SCHEMA_NAME); if (!StringUtils.hasLength(schemaLocation)) { - schema = (Schema) createExtension(Types.class, QNameUtils.getQNameForNode(schemaElement)); - schema.setElement(schemaElement); + schema.setElement(schemaHelper.getSchemaElement()); } else { - schema = (Schema) createExtension(Types.class, SCHEMA_NAME); Document document; try { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); } catch (ParserConfigurationException ex) { throw new WSDLException(WSDLException.PARSER_ERROR, "Could not create DocumentBuilder", ex); } - Element importingSchemaElement = - document.createElementNS(SCHEMA_NAME.getNamespaceURI(), QNameUtils.toQualifiedName(SCHEMA_NAME)); + Element importingSchemaElement = document.createElementNS(XsdSchemaHelper.SCHEMA_NAME.getNamespaceURI(), + QNameUtils.toQualifiedName(XsdSchemaHelper.SCHEMA_NAME)); schema.setElement(importingSchemaElement); - Element importElement = - document.createElementNS(IMPORT_NAME.getNamespaceURI(), QNameUtils.toQualifiedName(IMPORT_NAME)); + Element importElement = document.createElementNS(XsdSchemaHelper.IMPORT_NAME.getNamespaceURI(), + QNameUtils.toQualifiedName(XsdSchemaHelper.IMPORT_NAME)); importingSchemaElement.appendChild(importElement); - importElement.setAttribute("namespace", schemaTargetNamespace); + importElement.setAttribute("namespace", schemaHelper.getTargetNamespace()); importElement.setAttribute("schemaLocation", schemaLocation); } types.addExtensibilityElement(schema); @@ -298,14 +273,23 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD * @see #isFaultMessage(javax.xml.namespace.QName) */ protected void buildMessages(Definition definition) throws WSDLException { - NodeList elements = schemaElement.getElementsByTagNameNS(SCHEMA_NAME.getNamespaceURI(), "element"); - for (int i = 0; i < elements.getLength(); i++) { - Element element = (Element) elements.item(i); - QName elementName = getSchemaElementName(element); + List elementDeclarations = schemaHelper.getElementDeclarations(followIncludeImport); + for (Iterator iterator = elementDeclarations.iterator(); iterator.hasNext();) { + QName elementName = (QName) iterator.next(); if (elementName != null && (isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) { + if (!StringUtils.hasLength(definition.getPrefix(elementName.getNamespaceURI()))) { + int i = 0; + while (true) { + String prefix = schemaPrefix + Integer.toString(i); + if (!StringUtils.hasLength(definition.getNamespace(prefix))) { + definition.addNamespace(prefix, elementName.getNamespaceURI()); + break; + } + } + } Message message = definition.createMessage(); - populateMessage(message, element); + populateMessage(message, elementName); Part part = definition.createPart(); populatePart(part, elementName); message.addPart(part); @@ -356,12 +340,12 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD *

* Default implementation sets the name of the message to the element name. * - * @param message the WSDL4J Message - * @param element the element + * @param message the WSDL4J Message + * @param elementName the element name * @throws WSDLException in case of errors */ - protected void populateMessage(Message message, Element element) { - message.setQName(new QName(targetNamespace, element.getAttribute("name"))); + protected void populateMessage(Message message, QName elementName) throws WSDLException { + message.setQName(new QName(targetNamespace, elementName.getLocalPart())); } /** @@ -374,7 +358,7 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD * @throws WSDLException in case of errors * @see Part#setElementName(javax.xml.namespace.QName) */ - protected void populatePart(Part part, QName elementName) { + protected void populatePart(Part part, QName elementName) throws WSDLException { part.setElementName(elementName); part.setName(elementName.getLocalPart()); } @@ -514,21 +498,4 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD protected void populateService(Service service) throws WSDLException { service.setQName(new QName(targetNamespace, portTypeName + SERVICE_SUFFIX)); } - - /** - * Returns the qualified name of the element. This is a combination of schema target namespace and the value of the - * "name" attribute value. - * - * @param element an element - * @return the value of the name attribute - */ - private QName getSchemaElementName(Element element) { - String attributeValue = element.getAttribute("name"); - if (StringUtils.hasLength(attributeValue)) { - return new QName(getSchemaTargetNamespace(), attributeValue); - } - else { - return null; - } - } } diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelper.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelper.java new file mode 100644 index 00000000..bccd9326 --- /dev/null +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelper.java @@ -0,0 +1,142 @@ +/* + * 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.ws.wsdl.wsdl11.builder; + +import java.io.IOException; +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.parsers.ParserConfigurationException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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; +import org.xml.sax.SAXException; + +/** + * Helper class for dealing with XSD schemas. Exposes the target namespace, and the list of qualified names declared in + * a schema. + * + * @author Arjen Poutsma + * @since 1.0.2 + */ +class XsdSchemaHelper { + + private static final Log logger = LogFactory.getLog(XsdSchemaHelper.class); + + private static final String SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema"; + + static final QName SCHEMA_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "schema", "xsd"); + + static final QName ELEMENT_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "element", "xsd"); + + static final QName INCLUDE_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "include", "xsd"); + + static final QName IMPORT_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "import", "xsd"); + + private final Resource schemaResource; + + private final Element schemaElement; + + private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + + static { + documentBuilderFactory.setNamespaceAware(true); + } + + public XsdSchemaHelper(Resource schemaResource) throws ParserConfigurationException, IOException, SAXException { + Assert.notNull(schemaResource, "schema must not be empty or null"); + Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit"); + this.schemaResource = schemaResource; + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Document schemaDocument = documentBuilder.parse(SaxUtils.createInputSource(schemaResource)); + schemaElement = schemaDocument.getDocumentElement(); + Assert.isTrue(SCHEMA_NAME.getLocalPart().equals(schemaElement.getLocalName()), + "schema document root element has invalid local name : [" + schemaElement.getLocalName() + + "] instead of [schema]"); + Assert.isTrue(SCHEMA_NAME.getNamespaceURI().equals(schemaElement.getNamespaceURI()), + "schema document root element has invalid namespace uri: [" + schemaElement.getNamespaceURI() + + "] instead of [" + SCHEMA_NAME.getNamespaceURI() + "]"); + Assert.hasLength(getTargetNamespace(), "schema [" + schemaResource + "] has no targetNamespace"); + } + + public String getTargetNamespace() { + return schemaElement.getAttribute("targetNamespace"); + } + + public Element getSchemaElement() { + return schemaElement; + } + + public List getElementDeclarations(boolean followIncludeImport) { + List declarations = new ArrayList(); + getElementDeclarationsInternal(declarations, followIncludeImport); + return declarations; + } + + private void getElementDeclarationsInternal(List declarations, boolean followIncludeImport) { + NodeList children = schemaElement.getChildNodes(); + 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(getElementName(childElement)); + } + else if (followIncludeImport) { + if (INCLUDE_NAME.equals(childName) || IMPORT_NAME.equals(childName)) { + String schemaLocation = childElement.getAttribute("schemaLocation"); + if (StringUtils.hasLength(schemaLocation)) { + try { + Resource resource = schemaResource.createRelative(schemaLocation); + if (resource.exists()) { + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + helper.getElementDeclarationsInternal(declarations, followIncludeImport); + } + else { + logger.warn("Imported/Includes schema with location " + schemaLocation + + " does not exist"); + } + } + catch (Exception ex) { + logger.warn(ex); + // ignore + } + } + } + } + } + } + } + + private QName getElementName(Element element) { + String attributeValue = element.getAttribute("name"); + return StringUtils.hasLength(attributeValue) ? new QName(getTargetNamespace(), attributeValue) : null; + } + + +} diff --git a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java index b8f8b0b0..42841614 100644 --- a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java +++ b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java @@ -34,15 +34,17 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase { private Transformer transformer; + private DocumentBuilder documentBuilder; + protected void setUp() throws Exception { builder = new XsdBasedSoap11Wsdl4jDefinitionBuilder(); - builder.setSchema(new ClassPathResource("schema.xsd", getClass())); - builder.setPortTypeName("Airline"); - builder.setTargetNamespace("http://www.springframework.org/spring-ws/wsdl/definitions"); builder.setLocationUri("http://localhost:8080/"); - builder.afterPropertiesSet(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + documentBuilder = documentBuilderFactory.newDocumentBuilder(); + XMLUnit.setIgnoreWhitespace(true); } public void testNonExistingSchema() throws Exception { @@ -55,30 +57,94 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase { } } - public void testInline() throws Exception { - builder.buildDefinition(); - builder.buildImports(); - builder.buildTypes(); - builder.buildMessages(); - builder.buildPortTypes(); - builder.buildBindings(); - builder.buildServices(); + public void testSingle() throws Exception { + builder.setSchema(new ClassPathResource("single.xsd", getClass())); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions"); + builder.afterPropertiesSet(); + + buildAll(); + Wsdl11Definition definition = builder.getDefinition(); DOMResult domResult = new DOMResult(); transformer.transform(definition.getSource(), domResult); Document result = (Document) domResult.getNode(); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(true); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document expected = documentBuilder.parse(getClass().getResourceAsStream("inline.wsdl")); + Document expected = documentBuilder.parse(getClass().getResourceAsStream("single-inline.wsdl")); + assertXMLEqual("Invalid WSDL built", expected, result); + } + + public void testSingleImport() throws Exception { + builder.setSchema(new ClassPathResource("single.xsd", getClass())); + builder.setSchemaLocation("single.xsd"); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions"); + builder.afterPropertiesSet(); + + buildAll(); + + Wsdl11Definition definition = builder.getDefinition(); + DOMResult domResult = new DOMResult(); + transformer.transform(definition.getSource(), domResult); + + Document result = (Document) domResult.getNode(); + Document expected = documentBuilder.parse(getClass().getResourceAsStream("single-import.wsdl")); + assertXMLEqual("Invalid WSDL built", expected, result); + } + + public void testFollowIncluding() throws Exception { + builder.setSchema(new ClassPathResource("including.xsd", getClass())); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/include/definitions"); + builder.setFollowIncludeImport(true); + builder.afterPropertiesSet(); + + buildAll(); + + Wsdl11Definition definition = builder.getDefinition(); + DOMResult domResult = new DOMResult(); + transformer.transform(definition.getSource(), domResult); + + Document result = (Document) domResult.getNode(); + Document expected = documentBuilder.parse(getClass().getResourceAsStream("include-inline.wsdl")); + assertXMLEqual("Invalid WSDL built", expected, result); + } + + public void testFollowImport() throws Exception { + builder.setSchema(new ClassPathResource("importing.xsd", getClass())); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/import/definitions"); + builder.setFollowIncludeImport(true); + builder.afterPropertiesSet(); + + buildAll(); + + Wsdl11Definition definition = builder.getDefinition(); + DOMResult domResult = new DOMResult(); + transformer.transform(definition.getSource(), domResult); + + Document result = (Document) domResult.getNode(); + Document expected = documentBuilder.parse(getClass().getResourceAsStream("import-inline.wsdl")); + assertXMLEqual("Invalid WSDL built", expected, result); + } + + public void testAirline() throws Exception { + builder.setSchema(new ClassPathResource("airline.xsd", getClass())); + builder.setPortTypeName("Airline"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/samples/airline/definitions"); + builder.afterPropertiesSet(); + buildAll(); + Wsdl11Definition definition = builder.getDefinition(); + DOMResult domResult = new DOMResult(); + transformer.transform(definition.getSource(), domResult); + + Document result = (Document) domResult.getNode(); + Document expected = documentBuilder.parse(getClass().getResourceAsStream("airline.wsdl")); XMLUnit.setIgnoreWhitespace(true); assertXMLEqual("Invalid WSDL built", expected, result); } - public void testImport() throws Exception { - builder.setSchemaLocation("schema.xsd"); - builder.buildDefinition(); + private void buildAll() { builder.buildDefinition(); builder.buildImports(); builder.buildTypes(); @@ -86,17 +152,6 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase { builder.buildPortTypes(); builder.buildBindings(); builder.buildServices(); - Wsdl11Definition definition = builder.getDefinition(); - DOMResult domResult = new DOMResult(); - transformer.transform(definition.getSource(), domResult); - - Document result = (Document) domResult.getNode(); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(true); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document expected = documentBuilder.parse(getClass().getResourceAsStream("import.wsdl")); - XMLUnit.setIgnoreWhitespace(true); - assertXMLEqual("Invalid WSDL built", expected, result); } diff --git a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelperTest.java b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelperTest.java new file mode 100644 index 00000000..9939ea24 --- /dev/null +++ b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdSchemaHelperTest.java @@ -0,0 +1,99 @@ +/* + * 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.ws.wsdl.wsdl11.builder; + +import java.util.List; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +public class XsdSchemaHelperTest extends TestCase { + + public void testSingle() throws Exception { + Resource resource = new ClassPathResource("single.xsd", getClass()); + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/single/schema", + helper.getTargetNamespace()); + List elementDeclarations = helper.getElementDeclarations(true); + assertEquals("Invalid amount of elements", 3, elementDeclarations.size()); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderRequest"), + elementDeclarations.get(0)); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderResponse"), + elementDeclarations.get(1)); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderFault"), + elementDeclarations.get(2)); + } + + public void testFollowInclude() throws Exception { + Resource resource = new ClassPathResource("including.xsd", getClass()); + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema", + helper.getTargetNamespace()); + List elementDeclarations = helper.getElementDeclarations(true); + assertEquals("Invalid amount of elements", 2, elementDeclarations.size()); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderResponse"), + elementDeclarations.get(0)); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"), + elementDeclarations.get(1)); + } + + public void testNotFollowInclude() throws Exception { + Resource resource = new ClassPathResource("including.xsd", getClass()); + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema", + helper.getTargetNamespace()); + List elementDeclarations = helper.getElementDeclarations(false); + assertEquals("Invalid amount of elements", 1, elementDeclarations.size()); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"), + elementDeclarations.get(0)); + } + + public void testFollowImport() throws Exception { + Resource resource = new ClassPathResource("importing.xsd", getClass()); + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema", + helper.getTargetNamespace()); + List elementDeclarations = helper.getElementDeclarations(true); + assertEquals("Invalid amount of elements", 2, elementDeclarations.size()); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/imported/schema", "GetOrderResponse"), + elementDeclarations.get(0)); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"), + elementDeclarations.get(1)); + } + + public void testNotFollowImport() throws Exception { + Resource resource = new ClassPathResource("importing.xsd", getClass()); + XsdSchemaHelper helper = new XsdSchemaHelper(resource); + assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema", + helper.getTargetNamespace()); + List elementDeclarations = helper.getElementDeclarations(false); + assertEquals("Invalid amount of elements", 1, elementDeclarations.size()); + assertEquals("Invalid element declaration name", + new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"), + elementDeclarations.get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/airline.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/airline.wsdl new file mode 100644 index 00000000..81e9111a --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/airline.wsdl @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import-inline.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import-inline.wsdl new file mode 100644 index 00000000..e675b108 --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import-inline.wsdl @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import.wsdl deleted file mode 100644 index 0fc12e14..00000000 --- a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/import.wsdl +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/imported.xsd b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/imported.xsd new file mode 100644 index 00000000..22dcb834 --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/imported.xsd @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/importing.xsd b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/importing.xsd new file mode 100644 index 00000000..421f6aa7 --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/importing.xsd @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/include-inline.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/include-inline.wsdl new file mode 100644 index 00000000..f585942c --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/include-inline.wsdl @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xml/src/test/resources/org/springframework/xml/schema/xsd/single.xsd b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/included.xsd similarity index 60% rename from xml/src/test/resources/org/springframework/xml/schema/xsd/single.xsd rename to core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/included.xsd index 57935389..fc508ca7 100644 --- a/xml/src/test/resources/org/springframework/xml/schema/xsd/single.xsd +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/included.xsd @@ -1,13 +1,13 @@ - + - + diff --git a/xml/src/test/resources/org/springframework/xml/schema/xsd/including.xsd b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/including.xsd similarity index 53% rename from xml/src/test/resources/org/springframework/xml/schema/xsd/including.xsd rename to core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/including.xsd index 6c569d4c..78dd1daf 100644 --- a/xml/src/test/resources/org/springframework/xml/schema/xsd/including.xsd +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/including.xsd @@ -1,11 +1,18 @@ - + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-import.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-import.wsdl new file mode 100644 index 00000000..43810717 --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-import.wsdl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-inline.wsdl b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-inline.wsdl new file mode 100644 index 00000000..64526aea --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single-inline.wsdl @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single.xsd b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single.xsd new file mode 100644 index 00000000..df338465 --- /dev/null +++ b/core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/single.xsd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7cd5382e..8c5b8f4e 100644 --- a/pom.xml +++ b/pom.xml @@ -566,12 +566,6 @@ wsdl4j 1.6.1 - - - org.apache.ws.commons.schema - XmlSchema - 1.3.2 - com.sun.xml.wss diff --git a/xml/pom.xml b/xml/pom.xml index c16ea6f1..a1e91192 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -74,12 +74,6 @@ wstx-asl test - - - org.apache.ws.commons.schema - XmlSchema - true - easymock diff --git a/xml/src/main/java/org/springframework/xml/schema/Schema.java b/xml/src/main/java/org/springframework/xml/schema/Schema.java deleted file mode 100644 index fd1901b4..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/Schema.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.schema; - -import org.springframework.xml.validation.XmlValidator; - -/** - * Represents an abstraction for XML schemas. - * - * @author Arjen Poutsma - * @since 1.0.2 - */ -public interface Schema { - - /** Returns the {@link XmlValidator} based on this schema. */ - XmlValidator getValidator(); -} diff --git a/xml/src/main/java/org/springframework/xml/schema/SchemaException.java b/xml/src/main/java/org/springframework/xml/schema/SchemaException.java deleted file mode 100644 index f2e7e77c..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/SchemaException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.schema; - -import org.springframework.xml.XmlException; - -/** - * Base class for all schema exceptions. - * - * @author Arjen Poutsma - * @since 1.0.2 - */ -public class SchemaException extends XmlException { - - public SchemaException(String message) { - super(message); - } - - public SchemaException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/xml/src/main/java/org/springframework/xml/schema/package.html b/xml/src/main/java/org/springframework/xml/schema/package.html deleted file mode 100644 index 73890526..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Provides the schema functionality of the Spring Web Services framework. Contains the Schema interface. - - diff --git a/xml/src/main/java/org/springframework/xml/schema/xsd/SimpleXsdSchema.java b/xml/src/main/java/org/springframework/xml/schema/xsd/SimpleXsdSchema.java deleted file mode 100644 index 87aab214..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/SimpleXsdSchema.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.schema.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.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; -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; - - private XmlValidator validator; - - /** - * 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 XmlValidator getValidator() { - return validator; - } - - 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"); - validator = XmlValidatorFactory.createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML); - } - - /** Inner definition of {@link SimpleXsdSchemaDocument}. */ - private class SimpleXsdSchemaDocument implements XsdSchemaDocument { - - public String getFilename() { - return schemaResource.getFilename(); - } - - public Source getSource() { - return new DOMSource(schemaElement); - } - - public XsdElement[] getElements() { - 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 SimpleXsdElement(childElement)); - } - } - } - return (XsdElement[]) declarations.toArray(new XsdElement[declarations.size()]); - } - - public String getTargetNamespace() { - return schemaElement.getAttribute("targetNamespace"); - } - - /** Inner definition of {@link SimpleXsdElement}. */ - private class SimpleXsdElement implements XsdElement { - - private final Element element; - - private SimpleXsdElement(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/schema/xsd/WsCommonsXsdSchema.java b/xml/src/main/java/org/springframework/xml/schema/xsd/WsCommonsXsdSchema.java deleted file mode 100644 index e5adac9a..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/WsCommonsXsdSchema.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.schema.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; -import org.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; - -/** - * 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; - - private XmlValidator validator; - - /** - * 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 XmlValidator getValidator() { - return validator; - } - - 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()]); - validator = XmlValidatorFactory.createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML); - } - - 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 XsdElement[] getElements() { - XmlSchemaObjectTable elements = commonsSchema.getElements(); - XsdElement[] declarations = new XsdElement[elements.getCount()]; - int i = 0; - for (Iterator iterator = elements.getValues(); iterator.hasNext();) { - XmlSchemaElement element = (XmlSchemaElement) iterator.next(); - declarations[i] = new WsCommonsXsdElement(element); - i++; - } - return declarations; - } - - public String getTargetNamespace() { - return commonsSchema.getTargetNamespace(); - } - - } - - private static class WsCommonsXsdElement implements XsdElement { - - private final XmlSchemaElement element; - - private WsCommonsXsdElement(XmlSchemaElement element) { - this.element = element; - } - - public QName getName() { - return element.getQName(); - } - } -} diff --git a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdElement.java b/xml/src/main/java/org/springframework/xml/schema/xsd/XsdElement.java deleted file mode 100644 index d010a50a..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdElement.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.schema.xsd; - -import javax.xml.namespace.QName; - -/** - * Represents an abstraction for an XSD element declaration. - * - * @author Arjen Poutsma - * @see XsdSchemaDocument#getElements() - * @since 1.0.2 - */ -public interface XsdElement { - - /** Returns the qualified name of the element declaration. */ - QName getName(); - -} diff --git a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchema.java b/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchema.java deleted file mode 100644 index a76b0b35..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchema.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.schema.xsd; - -import org.springframework.xml.schema.Schema; - -/** - * Represents an abstraction for an XSD schema. An XSD schema is made up of one or more schema documents. - * - * @author Arjen Poutsma - * @see XsdSchemaDocument - * @since 1.0.2 - */ -public interface XsdSchema extends Schema { - - /** Returns the {@link XsdSchemaDocument} objects this schema consists of. */ - XsdSchemaDocument[] getSchemaDocuments(); - -} diff --git a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaDocument.java b/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaDocument.java deleted file mode 100644 index 84bf8536..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaDocument.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.springframework.xml.schema.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 document. */ - String getTargetNamespace(); - - /** Returns the {@link Source} of the schema document. */ - Source getSource(); - - /** Returns the {@link XsdElement} objects of the schema document. */ - XsdElement[] getElements(); - -} diff --git a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaException.java b/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaException.java deleted file mode 100644 index 25b5d6f3..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/XsdSchemaException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.schema.xsd; - -import org.springframework.xml.schema.SchemaException; - -/** - * Base class for all XSD schema exceptions. - * - * @author Arjen Poutsma - * @since 1.0.2 - */ -public class XsdSchemaException extends SchemaException { - - 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/schema/xsd/package.html b/xml/src/main/java/org/springframework/xml/schema/xsd/package.html deleted file mode 100644 index 31fa13c5..00000000 --- a/xml/src/main/java/org/springframework/xml/schema/xsd/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - -Provides the XSD Schema functionality of the Spring Web Services framework. Contains the XsdSchema and XsdSchemaDocument -interfaces. - - diff --git a/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java b/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java deleted file mode 100644 index f3270b27..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; -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; - - private XmlValidator validator; - - /** - * 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 XmlValidator getValidator() { - return validator; - } - - 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"); - validator = XmlValidatorFactory.createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML); - } - - /** 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 deleted file mode 100644 index 26f5d3fa..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/WsCommonsXsdSchema.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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; -import org.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; - -/** - * 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; - - private XmlValidator validator; - - /** - * 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 XmlValidator getValidator() { - return validator; - } - - 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()]); - validator = XmlValidatorFactory.createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML); - } - - 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 deleted file mode 100644 index 8a14c289..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/XsdElementDeclaration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 deleted file mode 100644 index 7995f47a..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/XsdSchema.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 org.springframework.xml.validation.XmlValidator; - -/** - * 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(); - - /** Returns the {@link XmlValidator} based on this schema. */ - XmlValidator getValidator(); - -} diff --git a/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java b/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java deleted file mode 100644 index 61b217bd..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaDocument.java +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 261c2f4b..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/XsdSchemaException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 deleted file mode 100644 index e7ef41ec..00000000 --- a/xml/src/main/java/org/springframework/xml/xsd/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - -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/schema/xsd/AbstractXsdSchemaTestCase.java b/xml/src/test/java/org/springframework/xml/schema/xsd/AbstractXsdSchemaTestCase.java deleted file mode 100644 index 537e9912..00000000 --- a/xml/src/test/java/org/springframework/xml/schema/xsd/AbstractXsdSchemaTestCase.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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.schema.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.springframework.xml.validation.XmlValidator; -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)}); - XmlValidator validator = schema.getValidator(); - assertNotNull("No validator returned", validator); - 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); - XsdElement[] declarations = document.getElements(); - assertEquals("Invalid amount of element declarations", 1, declarations.length); - XsdElement 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)}); - XmlValidator validator = schema.getValidator(); - assertNotNull("No validator returned", validator); - XsdSchemaDocument[] documents = schema.getSchemaDocuments(); - assertEquals("Invalid amount of schema documents", 2, documents.length); - for (int i = 0; i < documents.length; i++) { - XsdSchemaDocument document = documents[i]; - assertNotNull("Document is null", document); - XsdElement[] elements = document.getElements(); - if ("including.xsd".equals(document.getFilename())) { - assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include", - document.getTargetNamespace()); - verifyDocument("including.xsd", document); - assertEquals("Invalid amount of element declarations", 1, elements.length); - assertEquals("Invalid element declaration name", - new QName("http://www.springframework.org/spring-ws/include", "customElement"), - elements[0].getName()); - } - else if ("included.xsd".equals(document.getFilename())) { - assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include", - document.getTargetNamespace()); - verifyDocument("included.xsd", document); - assertEquals("Invalid amount of element declarations", 1, elements.length); - assertEquals("Invalid element declaration name", - new QName("http://www.springframework.org/spring-ws/include", "stringElement"), - elements[0].getName()); - } - else { - fail("Invalid filename: " + document.getFilename()); - } - } - } - - public void testImport() throws Exception { - XsdSchema schema = - createSchema(new Resource[]{new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class)}); - XmlValidator validator = schema.getValidator(); - assertNotNull("No validator returned", validator); - XsdSchemaDocument[] documents = schema.getSchemaDocuments(); - assertEquals("Invalid amount of schema documents", 2, documents.length); - for (int i = 0; i < documents.length; i++) { - XsdSchemaDocument document = documents[i]; - assertNotNull("Document is null", document); - XsdElement[] elements = document.getElements(); - if ("importing.xsd".equals(document.getFilename())) { - assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing", - document.getTargetNamespace()); - verifyDocument("importing.xsd", document); - assertEquals("Invalid amount of element declarations", 1, elements.length); - assertEquals("Invalid element declaration name", - new QName("http://www.springframework.org/spring-ws/importing", "customElement"), - elements[0].getName()); - } - else if ("imported.xsd".equals(document.getFilename())) { - assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/imported", - document.getTargetNamespace()); - verifyDocument("imported.xsd", document); - assertEquals("Invalid amount of element declarations", 1, elements.length); - assertEquals("Invalid element declaration name", - new QName("http://www.springframework.org/spring-ws/imported", "stringElement"), - elements[0].getName()); - } - else { - fail("Invalid filename: " + document.getFilename()); - } - } - } - - 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/schema/xsd/SimpleXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/schema/xsd/SimpleXsdSchemaTest.java deleted file mode 100644 index 75c5e404..00000000 --- a/xml/src/test/java/org/springframework/xml/schema/xsd/SimpleXsdSchemaTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.schema.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/schema/xsd/WsCommonsXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/schema/xsd/WsCommonsXsdSchemaTest.java deleted file mode 100644 index a93aa240..00000000 --- a/xml/src/test/java/org/springframework/xml/schema/xsd/WsCommonsXsdSchemaTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.schema.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/schema/xsd/imported.xsd b/xml/src/test/resources/org/springframework/xml/schema/xsd/imported.xsd deleted file mode 100644 index d8fdde47..00000000 --- a/xml/src/test/resources/org/springframework/xml/schema/xsd/imported.xsd +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/xml/src/test/resources/org/springframework/xml/schema/xsd/importing.xsd b/xml/src/test/resources/org/springframework/xml/schema/xsd/importing.xsd deleted file mode 100644 index 386e2131..00000000 --- a/xml/src/test/resources/org/springframework/xml/schema/xsd/importing.xsd +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/xml/src/test/resources/org/springframework/xml/schema/xsd/included.xsd b/xml/src/test/resources/org/springframework/xml/schema/xsd/included.xsd deleted file mode 100644 index 11cf4341..00000000 --- a/xml/src/test/resources/org/springframework/xml/schema/xsd/included.xsd +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - \ No newline at end of file