tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramku...@apache.org
Subject svn commit: r787566 - in /tuscany/java/sca/modules: interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Date Tue, 23 Jun 2009 06:56:56 GMT
Author: ramkumar
Date: Tue Jun 23 06:56:56 2009
New Revision: 787566

URL: http://svn.apache.org/viewvc?rev=787566&view=rev
Log:
Fixes for TUSCANY-3117

Modified:
    tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
    tuscany/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java

Modified: tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java?rev=787566&r1=787565&r2=787566&view=diff
==============================================================================
--- tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
(original)
+++ tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java
Tue Jun 23 06:56:56 2009
@@ -182,6 +182,8 @@
                 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 @@
                     	// 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) {

Modified: tuscany/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java?rev=787566&r1=787565&r2=787566&view=diff
==============================================================================
--- tuscany/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
(original)
+++ tuscany/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Tue Jun 23 06:56:56 2009
@@ -21,6 +21,8 @@
 
 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.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 @@
         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<String> locations = new ArrayList<String>();
-        // Collection of namespace imports with location
-        Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>();
-        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<XSDefinition> list = map.get(namespace);
         XSDefinition modelXSD = null;
@@ -276,11 +234,64 @@
         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<String> locations = new ArrayList<String>();           
    
+                Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>();
               
+                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 @@
                 }
                 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);
             }
         }
     }



Mime
View raw message