This time with the attachment:


Chuck Williams <[EMAIL PROTECTED]> wrote on 03/26/2006 01:41:54 AM:

Hi All,

Axis2 0.95 still does not handle recursive data types properly.  The
SchemaCompiler recurses infinitely and generates a stack overflow.  I've
attached my patch to fix this upgraded for 0.95.  This is a patch
against modules/codegen/src.

I see that much of the code to implement choice particles was committed,
but that the new parser does not handle them.  I need to get them
working again.  Is there already work underway to do this, and/or was an
approach determined?  If so, I'd appreciate any information about that. 
If not, I'll figure out how to do it with the new parser and send
another patch.

Thanks,

Chuck

  

diff -urx '*~' codegen.src.orig/org/apache/axis2/schema/SchemaCompiler.java codegen.src.new/org/apache/axis2/schema/SchemaCompiler.java
--- codegen.src.orig/org/apache/axis2/schema/SchemaCompiler.java	2006-03-25 12:23:50.000000000 -1000
+++ codegen.src.new/org/apache/axis2/schema/SchemaCompiler.java	2006-03-25 21:55:26.000000000 -1000
@@ -381,7 +381,8 @@
                         //set a name
                         schemaType.setName(generatedTypeName.getLocalPart());
                         writeComplexType((XmlSchemaComplexType)schemaType,
-                                (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(xsElt));
+                                (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(xsElt),
+                                null);
                         //remove the reference from the anon list since we named the type
                         processedAnonymousComplexTypesMap.remove(xsElt);
                         innerElementMap.put(
@@ -423,7 +424,8 @@
                     referenceSchemaType.setName(generatedTypeName.getLocalPart());
 
                     writeComplexType((XmlSchemaComplexType)referenceSchemaType,
-                            (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(referencedElement));
+                            (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(referencedElement),
+                            null);
                     //remove the reference from the anon list since we named the type
                     processedAnonymousComplexTypesMap.remove(referencedElement);
 
@@ -600,12 +602,16 @@
                 || baseSchemaTypeMap.containsKey(complexType.getQName())) {
             return;
         }
+        
+        // Must do this up front to support recursive types
+        String fullyQualifiedClassName = writer.makeFullyQualifiedClassName(complexType.getQName());
+        processedTypemap.put(complexType.getQName(), fullyQualifiedClassName);
 
         BeanWriterMetaInfoHolder metaInfHolder = processComplexType(complexType,parentSchema);
 
         //write the class. This type mapping would have been populated right now
         //Note - We always write classes for named complex types
-        writeComplexType(complexType, metaInfHolder);
+        writeComplexType(complexType, metaInfHolder, fullyQualifiedClassName);
 
 
     }
@@ -614,12 +620,12 @@
      * Writes a complex type
      * @param complexType
      * @param metaInfHolder
+     * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
      * @throws SchemaCompilationException
      */
-    private void writeComplexType(XmlSchemaComplexType complexType, BeanWriterMetaInfoHolder metaInfHolder) throws SchemaCompilationException {
-        String fullyQualifiedClassName = writer.write(complexType, processedTypemap, metaInfHolder);
-        //populate the type map with the type QName
-        processedTypemap.put(complexType.getQName(), fullyQualifiedClassName);
+    private void writeComplexType(XmlSchemaComplexType complexType, BeanWriterMetaInfoHolder metaInfHolder, String fullyQualifiedClassName)
+    throws SchemaCompilationException {
+        writer.write(complexType, processedTypemap, metaInfHolder, fullyQualifiedClassName);
         processedTypeMetaInfoMap.put(complexType.getQName(),metaInfHolder);
     }
 
diff -urx '*~' codegen.src.orig/org/apache/axis2/schema/writer/BeanWriter.java codegen.src.new/org/apache/axis2/schema/writer/BeanWriter.java
--- codegen.src.orig/org/apache/axis2/schema/writer/BeanWriter.java	2006-03-25 12:23:50.000000000 -1000
+++ codegen.src.new/org/apache/axis2/schema/writer/BeanWriter.java	2006-03-25 21:55:26.000000000 -1000
@@ -1,5 +1,6 @@
 package org.apache.axis2.schema.writer;
 
+import javax.xml.namespace.QName;
 import org.apache.axis2.schema.BeanWriterMetaInfoHolder;
 import org.apache.axis2.schema.CompilerOptions;
 import org.apache.axis2.schema.SchemaCompilationException;
@@ -51,6 +52,12 @@
      * of the schema compiler may be exposed.
      */
     public Map getModelMap();
+    
+    /** Make the fully qualified class name for an element or named type
+     * @param qName the qualified Name for this element or type in the schema
+     * @return the appropriate fully qualified class name to use in generated code
+     */
+    public String makeFullyQualifiedClassName(QName qName);
 
     /**
      * Write a complex type
@@ -58,10 +65,12 @@
      * @param complexType
      * @param typeMap
      * @param metainf
+     * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
      * @return Returns String.
      * @throws SchemaCompilationException
      */
-    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException;
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf, String fullyQualifiedClassName)
+    throws SchemaCompilationException;
 
     /**
      * Write a element
diff -urx '*~' codegen.src.orig/org/apache/axis2/schema/writer/JavaBeanWriter.java codegen.src.new/org/apache/axis2/schema/writer/JavaBeanWriter.java
--- codegen.src.orig/org/apache/axis2/schema/writer/JavaBeanWriter.java	2006-03-25 12:23:50.000000000 -1000
+++ codegen.src.new/org/apache/axis2/schema/writer/JavaBeanWriter.java	2006-03-25 21:55:26.000000000 -1000
@@ -143,7 +143,7 @@
         try {
             QName qName = element.getQName();
 
-            return process(qName, metainf, typeMap, true);
+            return process(qName, metainf, typeMap, true, null);
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }
@@ -155,16 +155,18 @@
      * @param complexType
      * @param typeMap
      * @param metainf
+     * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
      * @throws org.apache.axis2.schema.SchemaCompilationException
      *
      * @see BeanWriter#write(org.apache.ws.commons.schema.XmlSchemaComplexType, java.util.Map, org.apache.axis2.schema.BeanWriterMetaInfoHolder)
      */
-    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf, String fullyQualifiedClassName)
+    throws SchemaCompilationException {
 
         try {
             //determine the package for this type.
             QName qName = complexType.getQName();
-            return process(qName, metainf, typeMap, false);
+            return process(qName, metainf, typeMap, false, fullyQualifiedClassName);
 
         } catch (SchemaCompilationException e) {
             throw e;
@@ -228,6 +230,36 @@
     }
 
 
+    /** Make the fully qualified class name for an element or named type
+     * @param qName the qualified Name for this element or type in the schema
+     * @return the appropriate fully qualified class name to use in generated code
+     */
+    public String makeFullyQualifiedClassName(QName qName) {
+
+        String nameSpaceFromURL = URLProcessor.makePackageName(qName.getNamespaceURI());
+
+        String packageName = this.packageName == null ?
+                nameSpaceFromURL :
+                this.packageName + nameSpaceFromURL;
+
+        String originalName = qName.getLocalPart();
+        String className = makeUniqueJavaClassName(this.namesList, originalName);
+
+        String packagePrefix = null;
+
+        String fullyqualifiedClassName;
+        if (wrapClasses)
+            packagePrefix =  (this.packageName == null ? DEFAULT_PACKAGE+"." : this.packageName) + WRAPPED_DATABINDING_CLASS_NAME;
+        else if (writeClasses)
+            packagePrefix = packageName;
+        if (packagePrefix!=null)
+            fullyqualifiedClassName = packagePrefix + (packagePrefix.endsWith(".")?"":".") + className;
+        else
+            fullyqualifiedClassName = className;
+        //return the fully qualified class name
+        return fullyqualifiedClassName;
+    }
+    
     /**
      * A util method that holds common code
      * for the complete schema that the generated XML complies to
@@ -237,10 +269,15 @@
      * @param metainf
      * @param typeMap
      * @param isElement
+     * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
      * @return Returns String.
      * @throws Exception
      */
-    private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap, boolean isElement) throws Exception {
+    private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap, boolean isElement, String fullyQualifiedClassName) throws Exception {
+        
+        if (fullyQualifiedClassName == null)
+            fullyQualifiedClassName = makeFullyQualifiedClassName(qName);
+        String className = fullyQualifiedClassName.substring(1+fullyQualifiedClassName.lastIndexOf('.'));
 
         String nameSpaceFromURL = URLProcessor.makePackageName(qName.getNamespaceURI());
 
@@ -249,11 +286,7 @@
                 this.packageName + nameSpaceFromURL;
 
         String originalName = qName.getLocalPart();
-        String className = makeUniqueJavaClassName(this.namesList, originalName);
-
-        String packagePrefix = null;
 
-        String fullyqualifiedClassName;
         ArrayList propertyNames = new ArrayList();
 
         if (!templateLoaded) {
@@ -266,7 +299,6 @@
             globalWrappedDocument.getDocumentElement().appendChild(
                     getBeanElement(globalWrappedDocument, className, originalName, packageName, qName, isElement, metainf, propertyNames, typeMap)
             );
-            packagePrefix =  (this.packageName == null ? DEFAULT_PACKAGE+"." : this.packageName) + WRAPPED_DATABINDING_CLASS_NAME;
 
         } else {
             //create the model
@@ -279,8 +311,6 @@
                 File out = createOutFile(packageName, className);
                 //parse with the template and create the files
                 parse(model, out);
-
-                packagePrefix = packageName ;
             }
 
             //add the model to the model map
@@ -291,13 +321,8 @@
 
         }
 
-        if (packagePrefix!=null){
-            fullyqualifiedClassName = packagePrefix + (packagePrefix.endsWith(".")?"":".") + className;
-        }else{
-            fullyqualifiedClassName = className;
-        }
         //return the fully qualified class name
-        return fullyqualifiedClassName;
+        return fullyQualifiedClassName;
 
     }
 

Reply via email to