SWS-162
This commit is contained in:
@@ -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 <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a concrete
|
||||
* part. Creates a <code>binding</code> that matches any present <code>portType</code>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <code><xsd:include/></code> and <code><xsd:import/></code> 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
|
||||
* <p/>
|
||||
* Default implementation sets the name of the message to the element name.
|
||||
*
|
||||
* @param message the WSDL4J <code>Message</code>
|
||||
* @param element the element
|
||||
* @param message the WSDL4J <code>Message</code>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/definitions">
|
||||
<wsdl:types>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas">
|
||||
|
||||
<element name="GetFlightsRequest">
|
||||
<complexType>
|
||||
<all>
|
||||
<element name="from" type="tns:AirportCode"/>
|
||||
<element name="to" type="tns:AirportCode"/>
|
||||
<element name="departureDate" type="date"/>
|
||||
<element minOccurs="0" name="serviceClass" type="tns:ServiceClass"/>
|
||||
</all>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="GetFlightsResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element maxOccurs="unbounded" minOccurs="0" name="flight" type="tns:Flight"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="GetFlightsFault">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="errorCode" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="BookFlightRequest">
|
||||
<complexType>
|
||||
<all>
|
||||
<element name="flightNumber" type="tns:FlightNumber"/>
|
||||
<element name="departureTime" type="dateTime"/>
|
||||
<element name="passengers">
|
||||
<complexType>
|
||||
<choice maxOccurs="9">
|
||||
<element name="passenger" type="tns:Name"/>
|
||||
<element name="username" type="tns:FrequentFlyerUsername"/>
|
||||
</choice>
|
||||
</complexType>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="BookFlightResponse" type="tns:Ticket"/>
|
||||
|
||||
<element name="GetFrequentFlyerMileageRequest"/>
|
||||
|
||||
<element name="GetFrequentFlyerMileageResponse" type="int"/>
|
||||
|
||||
|
||||
<complexType name="Flight">
|
||||
<sequence>
|
||||
<element name="number" type="tns:FlightNumber"/>
|
||||
<element name="departureTime" type="dateTime"/>
|
||||
<element name="from" type="tns:Airport"/>
|
||||
<element name="arrivalTime" type="dateTime"/>
|
||||
<element name="to" type="tns:Airport"/>
|
||||
<element name="serviceClass" type="tns:ServiceClass"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<simpleType name="FlightNumber">
|
||||
<restriction base="string">
|
||||
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
<complexType name="Name">
|
||||
<sequence>
|
||||
<element name="first" type="string"/>
|
||||
<element name="last" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<simpleType name="FrequentFlyerUsername">
|
||||
<restriction base="string"/>
|
||||
</simpleType>
|
||||
|
||||
|
||||
<complexType name="Airport">
|
||||
<all>
|
||||
<element name="code" type="tns:AirportCode"/>
|
||||
<element name="name" type="string"/>
|
||||
<element name="city" type="string"/>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<simpleType name="AirportCode">
|
||||
<restriction base="string">
|
||||
<pattern value="[A-Z][A-Z][A-Z]"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
<complexType name="Ticket">
|
||||
<all>
|
||||
<element name="id" type="long"/>
|
||||
<element name="issueDate" type="date"/>
|
||||
<element name="passengers">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element maxOccurs="9" name="passenger" type="tns:Name"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
<element name="flight" type="tns:Flight"/>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<simpleType name="ServiceClass">
|
||||
<restriction base="NCName">
|
||||
<enumeration value="economy"/>
|
||||
<enumeration value="business"/>
|
||||
<enumeration value="first"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
</schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetFlightsRequest">
|
||||
<wsdl:part element="schema:GetFlightsRequest" name="GetFlightsRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="BookFlightRequest">
|
||||
<wsdl:part element="schema:BookFlightRequest" name="BookFlightRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFlightsResponse">
|
||||
<wsdl:part element="schema:GetFlightsResponse" name="GetFlightsResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFlightsFault">
|
||||
<wsdl:part element="schema:GetFlightsFault" name="GetFlightsFault"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFrequentFlyerMileageRequest">
|
||||
<wsdl:part element="schema:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFrequentFlyerMileageResponse">
|
||||
<wsdl:part element="schema:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="BookFlightResponse">
|
||||
<wsdl:part element="schema:BookFlightResponse" name="BookFlightResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Airline">
|
||||
<wsdl:operation name="GetFlights">
|
||||
<wsdl:input message="tns:GetFlightsRequest" name="GetFlightsRequest"/>
|
||||
<wsdl:output message="tns:GetFlightsResponse" name="GetFlightsResponse"/>
|
||||
<wsdl:fault message="tns:GetFlightsFault" name="GetFlightsFault"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="BookFlight">
|
||||
<wsdl:input message="tns:BookFlightRequest" name="BookFlightRequest"/>
|
||||
<wsdl:output message="tns:BookFlightResponse" name="BookFlightResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="GetFrequentFlyerMileage">
|
||||
<wsdl:input message="tns:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
|
||||
<wsdl:output message="tns:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="AirlineBinding" type="tns:Airline">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetFlights">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetFlightsRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetFlightsResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="GetFlightsFault">
|
||||
<soap:fault name="GetFlightsFault" use="literal"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="BookFlight">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="BookFlightRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="BookFlightResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="GetFrequentFlyerMileage">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetFrequentFlyerMileageRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetFrequentFlyerMileageResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="AirlineService">
|
||||
<wsdl:port binding="tns:AirlineBinding" name="AirlinePort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/importing/schema"
|
||||
xmlns:schema0="http://www.springframework.org/spring-ws/imported/schema"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/import/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/import/definitions">
|
||||
|
||||
<wsdl:types>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/importing/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/importing/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/spring-ws/imported/schema"
|
||||
schemaLocation="imported.xsd"/>
|
||||
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetOrderResponse">
|
||||
<wsdl:part name="GetOrderResponse" element="schema0:GetOrderResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderRequest">
|
||||
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Order">
|
||||
<wsdl:operation name="GetOrder">
|
||||
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
|
||||
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="OrderBinding" type="tns:Order">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetOrder">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetOrderRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetOrderResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="OrderService">
|
||||
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/wsdl/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/wsdl/definitions">
|
||||
<wsdl:types>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
<import namespace="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||
schemaLocation="schema.xsd"/>
|
||||
</schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetFrequentFlyerMileageResponse">
|
||||
<wsdl:part element="schema:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="BookFlightResponse">
|
||||
<wsdl:part element="schema:BookFlightResponse" name="BookFlightResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFlightsRequest">
|
||||
<wsdl:part element="schema:GetFlightsRequest" name="GetFlightsRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFlightsFault">
|
||||
<wsdl:part element="schema:GetFlightsFault" name="GetFlightsFault"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFrequentFlyerMileageRequest">
|
||||
<wsdl:part element="schema:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetFlightsResponse">
|
||||
<wsdl:part element="schema:GetFlightsResponse" name="GetFlightsResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="BookFlightRequest">
|
||||
<wsdl:part element="schema:BookFlightRequest" name="BookFlightRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Airline">
|
||||
<wsdl:operation name="GetFlights">
|
||||
<wsdl:input message="tns:GetFlightsRequest" name="GetFlightsRequest"/>
|
||||
<wsdl:output message="tns:GetFlightsResponse" name="GetFlightsResponse"/>
|
||||
<wsdl:fault message="tns:GetFlightsFault" name="GetFlightsFault"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="GetFrequentFlyerMileage">
|
||||
<wsdl:input message="tns:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
|
||||
<wsdl:output message="tns:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="BookFlight">
|
||||
<wsdl:input message="tns:BookFlightRequest" name="BookFlightRequest"/>
|
||||
<wsdl:output message="tns:BookFlightResponse" name="BookFlightResponse"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="AirlineBinding" type="tns:Airline">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetFlights">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetFlightsRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetFlightsResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="GetFlightsFault">
|
||||
<soap:fault name="GetFlightsFault" use="literal"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="GetFrequentFlyerMileage">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetFrequentFlyerMileageRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetFrequentFlyerMileageResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="BookFlight">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="BookFlightRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="BookFlightResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="AirlineService">
|
||||
<wsdl:port binding="tns:AirlineBinding" name="AirlinePort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/imported/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/imported/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:element name="GetOrderResponse">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/importing/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/importing/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/spring-ws/imported/schema" schemaLocation="imported.xsd"/>
|
||||
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/include/schema"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/include/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include/definitions">
|
||||
|
||||
<wsdl:types>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/include/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:include schemaLocation="included.xsd"/>
|
||||
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetOrderResponse">
|
||||
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderRequest">
|
||||
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Order">
|
||||
<wsdl:operation name="GetOrder">
|
||||
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
|
||||
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="OrderBinding" type="tns:Order">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetOrder">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetOrderRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetOrderResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="OrderService">
|
||||
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single"
|
||||
xmlns="http://www.springframework.org/spring-ws/single" elementFormDefault="qualified"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/include/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:element name="root">
|
||||
<xsd:element name="GetOrderResponse">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child"/>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
@@ -1,11 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include"
|
||||
xmlns="http://www.springframework.org/spring-ws/include" elementFormDefault="qualified"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/include/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:include schemaLocation="included.xsd"/>
|
||||
|
||||
<xsd:element name="customElement" type="customType"/>
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/single/schema"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/single/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single/definitions">
|
||||
|
||||
<wsdl:types>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<xsd:import namespace="http://www.springframework.org/spring-ws/single/schema" schemaLocation="single.xsd"/>
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetOrderResponse">
|
||||
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderRequest">
|
||||
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderFault">
|
||||
<wsdl:part name="GetOrderFault" element="schema:GetOrderFault"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Order">
|
||||
<wsdl:operation name="GetOrder">
|
||||
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
|
||||
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
|
||||
<wsdl:fault message="tns:GetOrderFault" name="GetOrderFault"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="OrderBinding" type="tns:Order">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetOrder">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetOrderRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetOrderResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="GetOrderFault">
|
||||
<soap:fault name="GetOrderFault" use="literal"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="OrderService">
|
||||
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:schema="http://www.springframework.org/spring-ws/single/schema"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/single/definitions"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single/definitions">
|
||||
|
||||
<wsdl:types>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/single/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="GetOrderResponse">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="GetOrderFault">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="GetOrderResponse">
|
||||
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderRequest">
|
||||
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="GetOrderFault">
|
||||
<wsdl:part name="GetOrderFault" element="schema:GetOrderFault"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="Order">
|
||||
<wsdl:operation name="GetOrder">
|
||||
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
|
||||
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
|
||||
<wsdl:fault message="tns:GetOrderFault" name="GetOrderFault"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="OrderBinding" type="tns:Order">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="GetOrder">
|
||||
<soap:operation soapAction=""/>
|
||||
<wsdl:input name="GetOrderRequest">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="GetOrderResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="GetOrderFault">
|
||||
<soap:fault name="GetOrderFault" use="literal"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="OrderService">
|
||||
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
|
||||
<soap:address location="http://localhost:8080/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/single/schema"
|
||||
xmlns="http://www.springframework.org/spring-ws/single/schema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="GetOrderRequest">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="GetOrderResponse">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="GetOrderFault">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="child" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
6
pom.xml
6
pom.xml
@@ -566,12 +566,6 @@
|
||||
<artifactId>wsdl4j</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<!-- XSD dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.schema</groupId>
|
||||
<artifactId>XmlSchema</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<!-- WS-Security dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.wss</groupId>
|
||||
|
||||
@@ -74,12 +74,6 @@
|
||||
<artifactId>wstx-asl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- XSD dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.schema</groupId>
|
||||
<artifactId>XmlSchema</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Test dependencies -->
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Provides the schema functionality of the Spring Web Services framework. Contains the Schema interface.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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 <code><xsd:include/></code> nor <code><xsd:import/></code> elements.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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 <code>null</code>
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <a href="http://ws.apache.org/commons/XmlSchema/">Apache
|
||||
* WS Commons XMLSchema</a>. Allows for multiple {@link XsdSchemaDocument}s, and follows
|
||||
* <code><xsd:include/></code> and <code><xsd:import/></code> elements.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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 <code>null</code>
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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 <code>null</code> or empty
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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, <code>schema.xsd</code>. */
|
||||
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();
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Provides the XSD Schema functionality of the Spring Web Services framework. Contains the XsdSchema and XsdSchemaDocument
|
||||
interfaces.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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 <code><xsd:include/></code> nor <code><xsd:import/></code> elements.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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 <code>null</code>
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <a href="http://ws.apache.org/commons/XmlSchema/">Apache
|
||||
* WS Commons XMLSchema</a>. Allows for multiple {@link XsdSchemaDocument}s, and follows
|
||||
* <code><xsd:include/></code> and <code><xsd:import/></code> elements.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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 <code>null</code>
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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 <code>null</code> or empty
|
||||
* @throws IllegalArgumentException if the supplied <code>schemaResource</code> is <code>null</code>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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, <code>schema.xsd</code>. */
|
||||
String getFilename();
|
||||
|
||||
/** Returns the target namespace of the schema. */
|
||||
String getTargetNamespace();
|
||||
|
||||
/**
|
||||
* Returns the <code>Source</code> of the schema.
|
||||
*
|
||||
* @return the <code>Source</code> of this XSD schema
|
||||
*/
|
||||
Source getSource();
|
||||
|
||||
XsdElementDeclaration[] getElementDeclarations();
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Provides the XSD functionality of the Spring Web Services framework. Contains the XsdSchema and XsdSchemaDocument
|
||||
interfaces.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/imported"
|
||||
xmlns="http://www.springframework.org/spring-ws/imported" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="stringElement" type="xsd:string"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/importing"
|
||||
xmlns="http://www.springframework.org/spring-ws/importing" elementFormDefault="qualified"
|
||||
xmlns:imported="http://www.springframework.org/spring-ws/imported" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/spring-ws/imported" schemaLocation="imported.xsd"/>
|
||||
|
||||
<xsd:element name="customElement" type="imported:customType"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/include"
|
||||
xmlns="http://www.springframework.org/spring-ws/include" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:simpleType name="customType">
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="stringElement" type="xsd:string"/>
|
||||
|
||||
</xsd:schema>
|
||||
Reference in New Issue
Block a user