You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2006/09/01 14:10:08 UTC

svn commit: r439285 - in /webservices/axis2/trunk/java/modules: adb-codegen/src/org/apache/axis2/schema/ kernel/src/org/apache/axis2/description/ kernel/src/org/apache/axis2/transport/http/

Author: dims
Date: Fri Sep  1 05:10:07 2006
New Revision: 439285

URL: http://svn.apache.org/viewvc?rev=439285&view=rev
Log:
fix for AXIS2-1083 - WSDL2Java: SchemaLocation and circular imports / StackOverflowError 

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=439285&r1=439284&r2=439285&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Fri Sep  1 05:10:07 2006
@@ -7,6 +7,8 @@
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.schema.writer.BeanWriter;
 import org.apache.axis2.util.URLProcessor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAll;
 import org.apache.ws.commons.schema.XmlSchemaAny;
@@ -20,12 +22,21 @@
 import org.apache.ws.commons.schema.XmlSchemaContent;
 import org.apache.ws.commons.schema.XmlSchemaContentModel;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
 import org.apache.ws.commons.schema.XmlSchemaImport;
 import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinLengthFacet;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaPatternFacet;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
 import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
@@ -36,17 +47,6 @@
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeUnion;
 import org.apache.ws.commons.schema.XmlSchemaType;
-import org.apache.ws.commons.schema.XmlSchemaPatternFacet;
-import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
-import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
-import org.apache.ws.commons.schema.XmlSchemaMinLengthFacet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
@@ -118,7 +118,7 @@
     //are fed to the schema compiler!
     private Map availableSchemaMap = new HashMap();
 
-
+    private Map loadedSourceURI = new HashMap();
 
     // a list of externally identified QNames to be processed. This becomes
     // useful when  only a list of external elements need to be processed
@@ -281,6 +281,16 @@
         //add the schema to the loaded schema list
         if (!loadedSchemaMap.containsKey(schema.getTargetNamespace())) {
             loadedSchemaMap.put(schema.getTargetNamespace(), schema);
+        }
+        
+        // If we have/are loading a schema with a specific targetnamespace from a certain URI,
+        // then just return back to the caller to avoid recursion.
+        if (schema.getSourceURI() != null){
+            String key = schema.getTargetNamespace() + ":" + schema.getSourceURI();
+            if(loadedSourceURI.containsKey(key)){
+                return;
+            }
+            loadedSourceURI.put(key, key);
         }
 
         XmlSchemaObjectCollection includes = schema.getIncludes();

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?rev=439285&r1=439284&r2=439285&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Fri Sep  1 05:10:07 2006
@@ -134,7 +134,7 @@
      * instance the schemas are asked for and then used to serve
      * the subsequent requests
      */
-    private Hashtable schemaMappingTable = null;
+    private Map schemaMappingTable = null;
 
     /**
      * counter variable for naming the schemas
@@ -184,11 +184,11 @@
         this.schemaLocationsAdjusted = schemaLocationsAdjusted;
     }
 
-    public Hashtable getSchemaMappingTable() {
+    public Map getSchemaMappingTable() {
         return schemaMappingTable;
     }
 
-    public void setSchemaMappingTable(Hashtable schemaMappingTable) {
+    public void setSchemaMappingTable(Map schemaMappingTable) {
         this.schemaMappingTable = schemaMappingTable;
     }
 
@@ -1368,17 +1368,16 @@
                     //recursively call the calculating
                     XmlSchemaExternal externalSchema = (XmlSchemaExternal) item;
                     s = externalSchema.getSchema();
-                    if (s != null) {
-                        calcualteSchemaNames(Arrays.asList(
-                                new XmlSchema[]{s}),
-                                             nameTable);
+                    if (s != null && nameTable.get(s) == null) {
                         nameTable.put(s,
                                       ("xsd" + count++)
                                       + (customSchemaNameSuffix != null ?
                                          customSchemaNameSuffix :
                                          ""));
+                        calcualteSchemaNames(Arrays.asList(
+                                new XmlSchema[]{s}),
+                                             nameTable);
                     }
-
                 }
             }
         }
@@ -1390,10 +1389,9 @@
      * @param schemas
      */
     private void adjustSchemaNames(List schemas, Hashtable nameTable) {
-        //first traversal - fill the hashtable
-        for (int i = 0; i < schemas.size(); i++) {
-            XmlSchema schema = (XmlSchema) schemas.get(i);
-
+        Enumeration enumeration = nameTable.keys();
+        while (enumeration.hasMoreElements()) {
+            XmlSchema schema = (XmlSchema) enumeration.nextElement();
             XmlSchemaObjectCollection includes = schema.getIncludes();
             for (int j = 0; j < includes.getCount(); j++) {
                 Object item = includes.getItem(j);
@@ -1402,31 +1400,27 @@
                     XmlSchemaExternal xmlSchemaExternal = (XmlSchemaExternal) item;
                     XmlSchema s = xmlSchemaExternal.getSchema();
                     if (s != null) {
-                        adjustSchemaNames(Arrays.asList(
-                                new XmlSchema[]{s}), nameTable);
                         xmlSchemaExternal.setSchemaLocation(
                                 customSchemaNamePrefix == null ?
-                                //use the default mode
-                                (getName() +
-                                 "?xsd=" +
-                                 nameTable.get(s)) :
-                                                   //custom prefix is present - add the custom prefix
-                                                   (customSchemaNamePrefix +
-                                                    nameTable.get(s)));
+                                        //use the default mode
+                                        (getName() +
+                                                "?xsd=" +
+                                                nameTable.get(s)) :
+                                        //custom prefix is present - add the custom prefix
+                                        (customSchemaNamePrefix +
+                                                nameTable.get(s)));
                     }
                 }
             }
-
         }
     }
-
     /**
      * Swap the key,value pairs
      *
      * @param originalTable
      */
-    private Hashtable swapMappingTable(Hashtable originalTable) {
-        Hashtable swappedTable = new Hashtable(originalTable.size());
+    private Map swapMappingTable(Map originalTable) {
+        HashMap swappedTable = new HashMap(originalTable.size());
         Iterator keys = originalTable.keySet().iterator();
         Object key;
         while (keys.hasNext()) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=439285&r1=439284&r2=439285&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java Fri Sep  1 05:10:07 2006
@@ -16,11 +16,6 @@
 
 package org.apache.axis2.transport.http;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Hashtable;
-
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
@@ -45,6 +40,11 @@
 import org.apache.http.entity.StringEntity;
 import org.apache.ws.commons.schema.XmlSchema;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
 public class HTTPWorker implements Worker {
 
     public HTTPWorker() {
@@ -175,7 +175,7 @@
                     //run the population logic just to be sure
                     service.populateSchemaMappings();
                     //write out the correct schema
-                    Hashtable schemaTable = service.getSchemaMappingTable();
+                    Map schemaTable = service.getSchemaMappingTable();
                     final XmlSchema schema = (XmlSchema)schemaTable.get(schemaName);
                     //schema found - write it to the stream
                     if (schema != null) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java?rev=439285&r1=439284&r2=439285&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java Fri Sep  1 05:10:07 2006
@@ -34,8 +34,7 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Hashtable;
-
+import java.util.Map;
 public class ListingAgent extends AbstractAgent {
 
     private static final String LIST_MULTIPLE_SERVICE_JSP_NAME =
@@ -116,7 +115,7 @@
     }
 
     public void processListService(HttpServletRequest req,
-                                      HttpServletResponse res)
+                                   HttpServletResponse res)
             throws IOException, ServletException {
 
         String filePart = req.getRequestURL().toString();
@@ -180,7 +179,7 @@
                     AxisService axisService = (AxisService) serviceObj;
                     //call the populator
                     axisService.populateSchemaMappings();
-                    Hashtable schemaMappingtable =
+                    Map schemaMappingtable =
                             axisService.getSchemaMappingTable();
                     ArrayList schemas = axisService.getSchema();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org