diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-11 05:13:15 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-11 05:13:15 +0000 |
commit | da54af6fa3cbdc88a5c07451697e071710a500ad (patch) | |
tree | 7a425b53d8439c8eecc7f9f85df14e6b73514e6a /java/sca/modules/interface-wsdl/src | |
parent | d4bbe6fa031a26a4b3d86f455174a6cc0ed1cdd3 (diff) |
Improve the XML schema validation to enable XSDs in other modules
Fix an issue to write to XMLStreamWriter from SUN JDK 1.6
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@802988 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/interface-wsdl/src')
3 files changed, 32 insertions, 96 deletions
diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java index 11e8472166..10c909a548 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.interfacedef.wsdl.xml; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.List; @@ -29,14 +28,16 @@ import javax.wsdl.Definition; import javax.wsdl.Import; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper.Attribute; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; @@ -58,16 +59,18 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio public static final QName XSD = new QName("http://www.w3.org/2001/XMLSchema", "schema"); private XMLInputFactory inputFactory; - + private StAXHelper helper; private WSDLFactory factory; private XSDFactory xsdFactory; private Monitor monitor; - public WSDLDocumentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WSDLDocumentProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor, Monitor monitor) { + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.factory = modelFactories.getFactory(WSDLFactory.class); this.xsdFactory = modelFactories.getFactory(XSDFactory.class); this.inputFactory = modelFactories.getFactory(XMLInputFactory.class); this.monitor = monitor; + this.helper = StAXHelper.getInstance(registry); } /** @@ -191,43 +194,28 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio wsdlDefinition.setUnresolved(true); wsdlDefinition.setLocation(doc.toURI()); - InputStream is = doc.openStream(); - try { - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - int eventType = reader.getEventType(); - int index = 0; - while (true) { - if (eventType == XMLStreamConstants.START_ELEMENT) { - if (WSDL11.equals(reader.getName())) { - String tns = reader.getAttributeValue(null, "targetNamespace"); - wsdlDefinition.setNamespace(tns); - // The definition is marked as resolved but not loaded - wsdlDefinition.setUnresolved(false); - wsdlDefinition.setDefinition(null); - } - if (XSD.equals(reader.getName())) { - String tns = reader.getAttributeValue(null, "targetNamespace"); - XSDefinition xsd = xsdFactory.createXSDefinition(); - xsd.setUnresolved(true); - xsd.setNamespace(tns); - xsd.setLocation(URI.create(doc.toURI() + "#" + index)); - index++; - // The definition is marked as resolved but not loaded - xsd.setUnresolved(false); - xsd.setSchema(null); - wsdlDefinition.getXmlSchemas().add(xsd); - } - } - if (reader.hasNext()) { - eventType = reader.next(); - } else { - break; - } - } - return wsdlDefinition; - } finally { - is.close(); + Attribute attr1 = new Attribute(WSDL11, "targetNamespace"); + Attribute attr2 = new Attribute(XSD, "targetNamespace"); + Attribute[] attrs = helper.readAttributes(doc, attr1, attr2); + + wsdlDefinition.setNamespace(attr1.getValues().get(0)); + // The definition is marked as resolved but not loaded + wsdlDefinition.setUnresolved(false); + wsdlDefinition.setDefinition(null); + + int index = 0; + for (String tns : attr2.getValues()) { + XSDefinition xsd = xsdFactory.createXSDefinition(); + xsd.setUnresolved(true); + xsd.setNamespace(tns); + xsd.setLocation(URI.create(doc.toURI() + "#" + index)); + index++; + // The definition is marked as resolved but not loaded + xsd.setUnresolved(false); + xsd.setSchema(null); + wsdlDefinition.getXmlSchemas().add(xsd); } + return wsdlDefinition; } } diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index 2e14c4885c..6f6a5a2302 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -25,10 +25,10 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Collections; import javax.wsdl.Definition; import javax.wsdl.Operation; @@ -48,6 +48,7 @@ import javax.wsdl.xml.WSDLLocator; import javax.wsdl.xml.WSDLReader; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; @@ -62,7 +63,6 @@ import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; -import org.apache.tuscany.sca.xsd.xml.XMLDocumentHelper; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -211,7 +211,7 @@ public class WSDLModelResolver implements ModelResolver { return null; } latestImportURI = url.toString(); - return XMLDocumentHelper.getInputSource(url); + return XMLDocumentHelper.getInputSource(url); } catch (Exception e) { throw new ContributionRuntimeException(e); } diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java deleted file mode 100644 index 4558bafdb8..0000000000 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tuscany.sca.interfacedef.wsdl.xml; - -import java.net.URL; - -import javax.xml.stream.XMLInputFactory; - -import org.apache.tuscany.sca.xsd.xml.XMLDocumentHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * @version $Rev$ $Date$ - */ -public class XMLDocumentHelperTestCase { - private URL wsdl; - private URL xsd; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - wsdl = getClass().getResource("/wsdl/helloworld-interface.wsdl"); - } - - @Test - public void testReadTNS() throws Exception { - String tns = XMLDocumentHelper.readTargetNamespace(wsdl, XMLDocumentHelper.WSDL11, true, "targetNamespace", XMLInputFactory.newInstance()); - Assert.assertEquals("http://helloworld", tns); - } - -} |