diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-11-06 11:02:12 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-11-06 11:02:12 +0000 |
commit | dea1131853d154b2e9276a911565bd73ac2e403d (patch) | |
tree | bc18736031917ac5d05644703b168da80958333e /sca-java-2.x/trunk/modules | |
parent | 808c6465648ffa117d2a8ff6b0f253678b38f007 (diff) |
TUSCANY-4072: Fix from Robin Yu for Tuscany fails to retrieve XSD type/element for nested WSDL with diff namespace(wsdl resolver issue)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1406093 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index e419179c6e..031c967142 100644 --- a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.interfacedef.wsdl.xml; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -530,6 +531,7 @@ public class WSDLModelResolver implements ModelResolver { // with the URI of the top level WSDL which is set from the // relative location of the artifact that represents the WSDL wsdlDefinition.setURI(new URI(imp.getLocationURI())); + indexRead(wsdlDefinition.getLocation().toURL(), context); resolved = resolveImports(WSDLDefinition.class, wsdlDefinition, context); if (!resolved.isUnresolved()) { if (resolved.getImportedDefinitions().isEmpty()) { @@ -688,4 +690,52 @@ public class WSDLModelResolver implements ModelResolver { is.close(); } } + + protected Map<String, String> indexRead(URL doc, ProcessorContext context) throws IOException, XMLStreamException { + + Map<String, String> wsdlImports = new HashMap<String, String>(); + InputStream is = doc.openStream(); + try { + // Set up a StreamSource for the composite file, since this has an associated URL that + // can be used by the parser to find references to other files such as DTDs + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + StreamSource wsdlSource = new StreamSource(is, doc.toString()); + XMLStreamReader reader = inputFactory.createXMLStreamReader(wsdlSource); + + int eventType = reader.getEventType(); + int index = 0; + while (true) { + if (eventType == XMLStreamConstants.START_ELEMENT) { + if (WSDLDocumentProcessor.XSD.equals(reader.getName())) { + String tns = reader.getAttributeValue(null, "targetNamespace"); + XSDefinition xsd = xsdFactory.createXSDefinition(); + xsd.setUnresolved(true); + xsd.setNamespace(tns); + try { + xsd.setLocation(URI.create(doc.toURI() + "#" + index)); + } catch (URISyntaxException e) { + //TODO + e.printStackTrace(); + } + index ++; + // The definition is marked as resolved but not loaded + xsd.setUnresolved(false); + xsd.setSchema(null); + if (contribution != null) { + contribution.getModelResolver().addModel(xsd, context); + } + } + } + if (reader.hasNext()) { + eventType = reader.next(); + } else { + break; + } + } + return wsdlImports; + } finally { + is.close(); + } + } + } |