You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ra...@apache.org on 2009/08/05 11:46:31 UTC

svn commit: r801108 - /tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java

Author: ramkumar
Date: Wed Aug  5 09:46:30 2009
New Revision: 801108

URL: http://svn.apache.org/viewvc?rev=801108&view=rev
Log:
Fixes for TUSCANY-2906 - resolve xsd:imports by namespace

Modified:
    tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java

Modified: tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java?rev=801108&r1=801107&r2=801108&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java (original)
+++ tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java Wed Aug  5 09:46:30 2009
@@ -37,6 +37,7 @@
 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;
@@ -314,7 +315,24 @@
                     url = new URL(new URL(baseUri), schemaLocation);
                 }
                 return XMLDocumentHelper.getInputSource(url);
-            } catch (IOException e) {
+            } catch (IOException e) {               
+            	// If we are not able to resolve the imports using location, then 
+            	// try resolving them using the namespace.
+            	try {
+	                for (Artifact artifact : contribution.getArtifacts()) {
+	        			if (artifact.getModel() instanceof XSDefinitionImpl) {
+	        				String artifactNamespace = ((XSDefinitionImpl)artifact.getModel()).getNamespace();
+	        				if (targetNamespace.equals(artifactNamespace)) {
+	        					URL artifactLocation = ((XSDefinitionImpl)artifact.getModel()).getLocation().toURL();            					
+	        					return XMLDocumentHelper.getInputSource(artifactLocation);
+	        				}
+	        			}
+	        	    }
+                } catch (IOException ex) {
+                	// Invalid URI; return a default InputSource so that the
+                    // XmlSchema code will produce a useful diagnostic
+                    return new InputSource(schemaLocation);
+                }
                 // Invalid URI; return a default InputSource so that the
                 // XmlSchema code will produce a useful diagnostic
                 return new InputSource(schemaLocation);