You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2006/05/12 21:16:03 UTC

svn commit: r405838 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema: BeanWriterMetaInfoHolder.java SchemaCompiler.java

Author: dims
Date: Fri May 12 12:15:42 2006
New Revision: 405838

URL: http://svn.apache.org/viewcvs?rev=405838&view=rev
Log:
Patch that fixes AXIS2-696 (actually from Ajith) and keeps the order of elements specified in the wsdl/xsd like for example in xsd:all, even though it is not necessary to keep the order, right now the code generates a random order each time because of the hashmap iterator (This is from me!)


Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=405838&r1=405837&r2=405838&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java Fri May 12 12:15:42 2006
@@ -8,6 +8,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.LinkedHashMap;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -39,12 +40,12 @@
 
     protected boolean extension = false;
     private String extensionClassName = "";
-    protected Map elementToSchemaQNameMap = new HashMap();
-    protected Map elementToJavaClassMap = new HashMap();
-    protected Map specialTypeFlagMap = new HashMap();
-    protected Map qNameMaxOccursCountMap = new HashMap();
-    protected Map qNameMinOccursCountMap = new HashMap();
-    protected Map qNameOrderMap = new HashMap();
+    protected Map elementToSchemaQNameMap = new LinkedHashMap();
+    protected Map elementToJavaClassMap = new LinkedHashMap();
+    protected Map specialTypeFlagMap = new LinkedHashMap();
+    protected Map qNameMaxOccursCountMap = new LinkedHashMap();
+    protected Map qNameMinOccursCountMap = new LinkedHashMap();
+    protected Map qNameOrderMap = new LinkedHashMap();
 
     protected List nillableQNameList  = new ArrayList();
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=405838&r1=405837&r2=405838&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java Fri May 12 12:15:42 2006
@@ -43,6 +43,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.LinkedHashMap;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -93,6 +94,11 @@
     private BeanWriter writer = null;
     private Map baseSchemaTypeMap = null;
 
+    //a map for keeping the already loaded schemas
+    //the key is the targetnamespace and the value is the schema object
+    private Map loadedSchemaMap = 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
 
@@ -197,6 +203,11 @@
         //First look for the schemas that are imported and process them
         //Note that these are processed recursively!
 
+        //add the schema to the loaded schema list
+        if (!loadedSchemaMap.containsKey(schema.getTargetNamespace())) {
+            loadedSchemaMap.put(schema.getTargetNamespace(),schema) ;
+        }
+
         XmlSchemaObjectCollection includes = schema.getIncludes();
         if (includes != null) {
             Iterator tempIterator = includes.getIterator();
@@ -226,7 +237,6 @@
             processElement((XmlSchemaElement) xmlSchemaElement1Iterator.next(), schema);
         }
 
-
         Iterator xmlSchemaElement2Iterator = elements.getValues();
 
         // re-iterate through the elements and write them one by one
@@ -446,10 +456,13 @@
             //There can be instances where the SchemaType is null but the schemaTypeName is not!
             //this specifically happens with xsd:anyType.
             QName schemaTypeName = xsElt.getSchemaTypeName();
-            XmlSchemaType typeByName = parentSchema.getTypeByName(schemaTypeName);
+
+            XmlSchema currentParentSchema = resolveParentSchema(schemaTypeName,parentSchema);
+            XmlSchemaType typeByName = currentParentSchema.getTypeByName(schemaTypeName);
+
             if (typeByName!=null){
                 //this type is found in the schema so we can process it
-                processSchema(xsElt, typeByName,parentSchema);
+                processSchema(xsElt, typeByName,currentParentSchema);
                 if (!isOuter) {
                     String className = findClassName(schemaTypeName, isArray(xsElt));
                     //since this is a inner element we should add it to the inner element map
@@ -480,6 +493,23 @@
     }
 
     /**
+     * resolve the parent schema for the given schema type name
+     *
+     * @param schemaTypeName
+     * @param currentSchema
+     * @return
+     */
+    private XmlSchema resolveParentSchema(QName schemaTypeName,XmlSchema currentSchema) {
+        String targetNamespace = schemaTypeName.getNamespaceURI();
+        Object loadedSchema = loadedSchemaMap.get(targetNamespace);
+        if (loadedSchema!=null){
+            return  (XmlSchema)loadedSchema;
+        }else{
+            return currentSchema;
+        }
+    }
+
+    /**
      * Generate a unique type Qname using an element name
      * @param referenceEltQName
      * @param parentSchema
@@ -563,9 +593,9 @@
         return className;
     }
 
+
     /**
-     * Process a schema element
-     *
+     * Process a schema element which has been refered to by an element
      * @param schemaType
      * @throws SchemaCompilationException
      */
@@ -835,7 +865,7 @@
         metainf.registerMapping(qName,
                 null,
                 DEFAULT_ATTRIB_ARRAY_CLASS_NAME,//always generate an array of
-                                                //OMAttributes
+                //OMAttributes
                 SchemaConstants.ANY_TYPE);
         metainf.addtStatus(qName, SchemaConstants.ATTRIBUTE_TYPE);
         metainf.addtStatus(qName, SchemaConstants.ARRAY_TYPE);
@@ -898,8 +928,8 @@
                          boolean order,
                          XmlSchema parentSchema) throws SchemaCompilationException {
         int count = items.getCount();
-        Map processedElementArrayStatusMap = new HashMap();
-        Map processedElementTypeMap = new HashMap();
+        Map processedElementArrayStatusMap = new LinkedHashMap();
+        Map processedElementTypeMap = new LinkedHashMap();
         List localNillableList = new ArrayList();
 
         Map elementOrderMap = new HashMap();