From edd87337caed8414eadd9ff03339e9d3e534be3e Mon Sep 17 00:00:00 2001 From: ramkumar Date: Tue, 23 Jun 2009 06:56:56 +0000 Subject: Fixes for TUSCANY-3117 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@787566 13f79535-47bb-0310-9956-ffa450edef68 --- .../interfacedef/wsdl/xml/WSDLModelResolver.java | 3 + .../tuscany/sca/xsd/xml/XSDModelResolver.java | 111 ++++++++++++--------- 2 files changed, 67 insertions(+), 47 deletions(-) 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 686236d1c2..e5a485a7c9 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 @@ -182,6 +182,8 @@ public class WSDLModelResolver implements ModelResolver { if (importLocation == null) { throw new IllegalArgumentException("Required attribute 'location' is missing."); } + if (importLocation.trim().equals("")) + throw new IllegalArgumentException("Required attribute 'location' is empty."); URL url = null; if (importLocation.startsWith("/")) { @@ -311,6 +313,7 @@ public class WSDLModelResolver implements ModelResolver { // We might have multiple imports for the same namespace, // need to search them in lexical order. locations.add(namespaceImport.getLocation()); + locationMap.put(namespaceImport.getLocation(), namespaceImport); } } } else if (import_ instanceof DefaultImport) { diff --git a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index d201ce5b80..3853873896 100644 --- a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.xsd.xml; import java.io.IOException; import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -38,6 +40,7 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.xsd.DefaultXSDFactory; import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.tuscany.sca.xsd.impl.XSDefinitionImpl; import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaCollection; import org.apache.ws.commons.schema.XmlSchemaInclude; @@ -89,51 +92,6 @@ public class XSDModelResolver implements ModelResolver { String namespace = definition.getNamespace(); XSDefinition resolved = null; - // FIXME - We should not be using import resolvers for inline schema. - /* // Lookup a definition for the given namespace, from imports - List locations = new ArrayList(); - // Collection of namespace imports with location - Map locationMap = new HashMap(); - for (Import import_ : this.contribution.getImports()) { - if (import_ instanceof NamespaceImport) { - NamespaceImport namespaceImport = (NamespaceImport)import_; - if (namespaceImport.getNamespace().equals(namespace)) { - if (namespaceImport.getLocation() == null) { - // Delegate the resolution to the namespace import resolver - resolved = - namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } else { - // We might have multiple imports for the same namespace, - // need to search them in lexical order. - locations.add(namespaceImport.getLocation()); - } - } - } - else if (import_ instanceof DefaultImport) { - - // Delegate the resolution to the default import resolver - resolved = - import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } - } - // Search namespace imports with location in lexical order - Collections.sort(locations); - for (String location : locations) { - NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); - // Delegate the resolution to the namespace import resolver - resolved = - namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } */ - // Lookup a definition for the given namespace, within the contribution List list = map.get(namespace); XSDefinition modelXSD = null; @@ -276,11 +234,64 @@ public class XSDModelResolver implements ModelResolver { public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, java.lang.String schemaLocation, java.lang.String baseUri) { - try { + try + { if (schemaLocation == null) { return null; } URL url = null; + + // Delegate the resolution to namespace imports + XSDefinition resolved = null; + XSDefinition unresolved = new XSDefinitionImpl(); + unresolved.setUnresolved(true); + unresolved.setLocation(new URI(schemaLocation)); + unresolved.setNamespace(targetNamespace); + + // Collection of namespace imports with location + List locations = new ArrayList(); + Map locationMap = new HashMap(); + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + if (namespaceImport.getNamespace().equals(targetNamespace)) { + if (namespaceImport.getLocation() == null) { + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); + } + } else { + // We might have multiple imports for the same namespace, + // need to search them in lexical order. + locations.add(namespaceImport.getLocation()); + locationMap.put(namespaceImport.getLocation(), namespaceImport); + } + } + } else if (import_ instanceof DefaultImport) { + // Delegate the resolution to the default import resolver + resolved = + import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); + } + } + } + // Search namespace imports with location in lexical order + Collections.sort(locations); + for (String location : locations) { + NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); + } + } + + // Not found, lookup a definition for the given namespace + // within the current contribution. if (schemaLocation.startsWith("/")) { // The URI is relative to the contribution String uri = schemaLocation.substring(1); @@ -295,7 +306,13 @@ public class XSDModelResolver implements ModelResolver { } return XMLDocumentHelper.getInputSource(url); } catch (IOException e) { - return null; + // Invalid URI; return a default InputSource so that the + // XmlSchema code will produce a useful diagnostic + return new InputSource(schemaLocation); + } catch (URISyntaxException e) { + // Invalid URI; return a default InputSource so that the + // XmlSchema code will produce a useful diagnostic + return new InputSource(schemaLocation); } } } -- cgit v1.2.3