[jbossws-commits] JBossWS SVN: r10807 - stack/native/branches/dlofthouse/JBWS-2777/src/main/java/org/jboss/ws/tools/wsdl.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Sep 30 11:05:14 EDT 2009


Author: darran.lofthouse at jboss.com
Date: 2009-09-30 11:05:14 -0400 (Wed, 30 Sep 2009)
New Revision: 10807

Modified:
   stack/native/branches/dlofthouse/JBWS-2777/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
Log:
Prototype fix.

Modified: stack/native/branches/dlofthouse/JBWS-2777/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
===================================================================
--- stack/native/branches/dlofthouse/JBWS-2777/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java	2009-09-30 14:57:07 UTC (rev 10806)
+++ stack/native/branches/dlofthouse/JBWS-2777/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java	2009-09-30 15:05:14 UTC (rev 10807)
@@ -33,7 +33,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -370,21 +369,19 @@
             String localname = domElementClone.getLocalName();
             try
             {
-               List<URL> published = new LinkedList<URL>();
+               Map<URL,URL> publishedMapping = new HashMap<URL, URL>();
                if ("import".equals(localname))
                {
-                  processSchemaImport(destTypes, wsdlLoc, domElementClone, published);
+                  processSchemaImport(destTypes, wsdlLoc, domElementClone, publishedMapping);
                }
                else if ("schema".equals(localname))
                {
-                  processSchemaInclude(destTypes, wsdlLoc, domElementClone, published);
+                  processSchemaInclude(destTypes, wsdlLoc, domElementClone, publishedMapping);
                }
                else
                {
                   throw new IllegalArgumentException("Unsuported schema element: " + localname);
                }
-               published.clear();
-               published = null;
             }
             catch (IOException e)
             {
@@ -476,7 +473,7 @@
       }
    }
 
-   private void processSchemaImport(WSDLTypes types, URL wsdlLoc, Element importEl, List<URL> published) throws IOException, WSDLException
+   private void processSchemaImport(WSDLTypes types, URL wsdlLoc, Element importEl, Map<URL, URL> publishedLocations) throws IOException, WSDLException
    {
       if (wsdlLoc == null)
          throw new IllegalArgumentException("Cannot process import, parent location not set");
@@ -488,22 +485,21 @@
          throw new IllegalArgumentException("schemaLocation is null for xsd:import");
 
       URL locationURL = getLocationURL(wsdlLoc, location);
-      Element rootElement = DOMUtils.parse(new ResourceURL(locationURL).openStream());
-      if (!published.contains(locationURL))
+      if (!publishedLocations.containsKey(locationURL))
       {
-         published.add(locationURL);
-         URL newloc = processSchemaInclude(types, locationURL, rootElement,  published);
-         if (newloc != null)
-            importEl.setAttribute("schemaLocation", newloc.toExternalForm());
+         Element rootElement = DOMUtils.parse(new ResourceURL(locationURL).openStream());
+         processSchemaInclude(types, locationURL, rootElement, publishedLocations);
       }
+      URL newLoc = publishedLocations.get(locationURL);
+      if (newLoc != null)
+         importEl.setAttribute("schemaLocation", newLoc.toExternalForm());
    }
 
-   private URL processSchemaInclude(WSDLTypes types, URL wsdlLoc, Element schemaEl, List<URL> published) throws IOException, WSDLException
+   private void processSchemaInclude(WSDLTypes types, URL wsdlLoc, Element schemaEl, Map<URL, URL> publishedLocations) throws IOException, WSDLException
    {
       if (wsdlLoc == null)
          throw new IllegalArgumentException("Cannot process iclude, parent location not set");
 
-      File tmpFile = null;
       if (wsdlLoc == null)
          throw new IllegalArgumentException("Cannot process include, parent location not set");
 
@@ -516,6 +512,26 @@
       importElement.setAttribute("namespace", Constants.URI_SOAP11_ENC);
       schemaEl.insertBefore(importElement, DOMUtils.getFirstChildElement(schemaEl));
 
+      String targetNS = getOptionalAttribute(schemaEl, "targetNamespace");
+      File tmpFile = null;
+
+      if (targetNS != null)
+      {
+         log.trace("processSchemaInclude: [targetNS=" + targetNS + ",parentURL=" + wsdlLoc + "]");
+
+         tmpFile = SchemaUtils.getSchemaTempFile(targetNS);
+         tempFiles.add(tmpFile);
+
+         publishedLocations.put(wsdlLoc, tmpFile.toURL());
+      }
+      else
+      {
+         tmpFile = SchemaUtils.getSchemaTempFile("no_namespace");
+         tempFiles.add(tmpFile);
+
+         publishedLocations.put(wsdlLoc, tmpFile.toURL());
+      }
+
       // Handle schema includes
       Iterator it = DOMUtils.getChildElements(schemaEl, new QName(Constants.NS_SCHEMA_XSD, "include"));
       while (it.hasNext())
@@ -527,44 +543,36 @@
 
          URL locationURL = getLocationURL(wsdlLoc, location);
          Element rootElement = DOMUtils.parse(new ResourceURL(locationURL).openStream());
-         if (!published.contains(locationURL))
+         if (!publishedLocations.containsKey(locationURL))
          {
-            published.add(locationURL);
-            URL newloc = processSchemaInclude(types, locationURL, rootElement, published);
-            if (newloc != null)
-               includeEl.setAttribute("schemaLocation", newloc.toExternalForm());
+            processSchemaInclude(types, locationURL, rootElement, publishedLocations);
          }
+
+         URL newLoc = publishedLocations.get(locationURL);
+         if (newLoc != null)
+         {
+            includeEl.setAttribute("schemaLocation", newLoc.toExternalForm());
+         }
       }
 
-      String targetNS = getOptionalAttribute(schemaEl, "targetNamespace");
-      if (targetNS != null)
+      if (tmpFile != null)
       {
-         log.trace("processSchemaInclude: [targetNS=" + targetNS + ",parentURL=" + wsdlLoc + "]");
-
-         tmpFile = SchemaUtils.getSchemaTempFile(targetNS);
-         tempFiles.add(tmpFile);
-
          FileWriter fwrite = new FileWriter(tmpFile);
          new DOMWriter(fwrite).setPrettyprint(true).print(schemaEl);
          fwrite.close();
 
-         schemaLocationsMap.put(targetNS, tmpFile.toURL());
       }
 
-      // schema elements that have no target namespace are skipped
-      //
-      //  <xsd:schema>
-      //    <xsd:import namespace="http://org.jboss.webservice/example/types" schemaLocation="Hello.xsd"/>
-      //    <xsd:import namespace="http://org.jboss.webservice/example/types/arrays/org/jboss/test/webservice/admindevel" schemaLocation="subdir/HelloArr.xsd"/>
-      //  </xsd:schema>
-      if (targetNS == null)
+      if (targetNS != null)
       {
+         schemaLocationsMap.put(targetNS, tmpFile.toURL());
+      }
+      else
+      {
          log.trace("Schema element without target namespace in: " + wsdlLoc);
       }
 
       handleSchemaImports(schemaEl, wsdlLoc);
-
-      return tmpFile != null ? tmpFile.toURL() : null;
    }
 
    private void handleSchemaImports(Element schemaEl, URL parentURL) throws WSDLException, IOException



More information about the jbossws-commits mailing list