ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r371914 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema: BeanWriterMetaInfoHolder.java SchemaCompiler.java i18n/resource.properties template/ADBBeanTemplate.xsl writer/JavaBeanWriter.java
Date Tue, 24 Jan 2006 13:51:28 GMT
Author: ajith
Date: Tue Jan 24 05:51:17 2006
New Revision: 371914

URL: http://svn.apache.org/viewcvs?rev=371914&view=rev
Log:
Fixed the ComplexContent handling
1. Added the necesary methods to the SchemaCompiler.java
2. Added a resource to internationalize some messages
3. Updated the ADBBeanTemplate.xsl to include only the non inherited properties
4. Updated the access modifier to be protected rather than private
5. Did some minor improvements to the logic of the BeanWriterMetaInfoHolder.java

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
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.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=371914&r1=371913&r2=371914&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
Tue Jan 24 05:51:17 2006
@@ -6,6 +6,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -31,16 +33,31 @@
 public class BeanWriterMetaInfoHolder {
 
 
-    private boolean ordered = false;
-    private boolean anonymous = false;
-    private boolean extension = false;
+    protected boolean ordered = false;
+    protected boolean anonymous = false;
+    protected boolean extension = false;
     private String extensionClassName = "";
-    private Map elementToSchemaQNameMap = new HashMap();
-    private Map elementToJavaClassMap = new HashMap();
-    private Map specialTypeFlagMap = new HashMap();
-    private Map qNameMaxOccursCountMap = new HashMap();
-    private Map qNameMinOccursCountMap = new HashMap();
-    private Map qNameOrderMap = new HashMap();
+    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();
+
+
+
+    //the parent metainfo holder, useful in handling extensions and
+    //restrictions
+    protected BeanWriterMetaInfoHolder parent = null;
+
+
+    /**
+     * Gets the parent
+     * @return
+     */
+    public BeanWriterMetaInfoHolder getParent() {
+        return parent;
+    }
 
     /**
      * Gets the anonymous status.
@@ -89,6 +106,8 @@
         return extension;
     }
 
+    
+
     /**
      * Sets the extension status.
      *
@@ -320,4 +339,14 @@
           return qNameOrderMap.size();
     }
 
+
+    /**
+     * Creates link to th
+     * @param metaInfo
+     */
+    public void setAsParent(BeanWriterMetaInfoHolder metaInfo){
+        parent = metaInfo;
+
+
+    }
 }

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=371914&r1=371913&r2=371914&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
Tue Jan 24 05:51:17 2006
@@ -1,7 +1,6 @@
 package org.apache.axis2.schema;
 
 import org.apache.axis2.om.OMElement;
-import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.schema.writer.BeanWriter;
 import org.apache.ws.commons.schema.XmlSchema;
@@ -494,7 +493,7 @@
 
             //process the base type if it has not been processed yet
             if (!isAlreadyProcessed(extension.getBaseTypeName())){
-               //pick the relevant basetype from the schema and process it
+                //pick the relevant basetype from the schema and process it
                 XmlSchemaType type=  parentSchema.getTypeByName(extension.getBaseTypeName());
                 if (type instanceof XmlSchemaComplexType) {
                     XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
@@ -515,7 +514,7 @@
             // children (sometimes even preserving the order) to the metainfo holder of this
type
             // the reason is that for extensions, the prefered way is to have the sequences
of the base class
             //* before * the sequence of the child element.
-
+            copyMetaInfoHierarchy(metaInfHolder,extension.getBaseTypeName(),parentSchema);
 
 
             //process the particle of this node
@@ -526,17 +525,76 @@
             // The basetype has been processed already
             metaInfHolder.setExtension(true);
             metaInfHolder.setExtensionClassName(findClassName(extension.getBaseTypeName(),false));
-              //Note  - this is no array! so the array boolean is false
+            //Note  - this is no array! so the array boolean is false
 
         }else if (content instanceof XmlSchemaComplexContentRestriction){
             //todo handle complex restriction here
         }
     }
 
+    /**
+     * Recursive method to populate the metainfo holders with info from the base types
+     * @param metaInfHolder
+     * @param baseTypeName
+     * @param parentSchema
+     */
+    private void copyMetaInfoHierarchy(BeanWriterMetaInfoHolder metaInfHolder,
+                                       QName baseTypeName,
+                                       XmlSchema parentSchema)
+                                                throws SchemaCompilationException {
+        XmlSchemaType type = parentSchema.getTypeByName(baseTypeName);
+        BeanWriterMetaInfoHolder baseMetaInfoHolder = (BeanWriterMetaInfoHolder)
+                processedTypeMetaInfoMap.get(baseTypeName);
+
+        if (baseMetaInfoHolder!= null){
+
+            // see whether this type is also extended from some other type first
+            // if so proceed to set their parents as well.
+            if (type instanceof XmlSchemaComplexType){
+                XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
+                if (complexType.getContentModel()!= null){
+                    XmlSchemaContentModel content = complexType.getContentModel();
+                    if (content instanceof XmlSchemaComplexContent){
+                        XmlSchemaComplexContent complexContent =
+                                (XmlSchemaComplexContent)content;
+                        if (complexContent.getContent() instanceof XmlSchemaComplexContentExtension){
+                            XmlSchemaComplexContentExtension extension =
+                                    (XmlSchemaComplexContentExtension)complexContent.getContent();
+                            //recursively call the copyMetaInfoHierarchy method
+                            copyMetaInfoHierarchy(baseMetaInfoHolder,
+                                    extension.getBaseTypeName(),
+                                    parentSchema);
+
+                        }else  if (complexContent.getContent() instanceof XmlSchemaComplexContentRestriction){
+                            
+                            XmlSchemaComplexContentRestriction restriction =
+                                    (XmlSchemaComplexContentRestriction)complexContent.getContent();
+                            //recursively call the copyMetaInfoHierarchy method
+                            copyMetaInfoHierarchy(baseMetaInfoHolder,
+                                    restriction.getBaseTypeName(),
+                                    parentSchema);
+
+                        }else{
+                            throw new SchemaCompilationException(); //todo put the right
message
+                        }
+
+                    }else if (content instanceof XmlSchemaSimpleContent){
+                        //todo
+                    }else{
+                        throw new SchemaCompilationException();
+                    }
+                }
+
+                //Do the actual parent setting
+                metaInfHolder.setAsParent(baseMetaInfoHolder);
+            }
+        }
+    }
+
     private void processSimpleContent(XmlSchemaSimpleContent simpleContent,BeanWriterMetaInfoHolder
metaInfHolder){
         XmlSchemaContent content = simpleContent.getContent();
         if (content instanceof XmlSchemaSimpleContentExtension){
-             //todo - handle simple type extension here
+            //todo - handle simple type extension here
         }else if (content instanceof XmlSchemaSimpleContentRestriction){
             //todo - Handle simple type restriction here
         }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties?rev=371914&r1=371913&r2=371914&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
Tue Jan 24 05:51:17 2006
@@ -28,4 +28,5 @@
 schema.rootnotfolderexception=Root location needs to be a directory!
 schema.notimplementedxception=Not implemented yet
 schema.templateLoadException=Error loading the template
-schema.templateNotFoundException=template for this writer is not found
\ No newline at end of file
+schema.templateNotFoundException=template for this writer is not found
+schema.typeMissing=Type missing!
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=371914&r1=371913&r2=371914&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
Tue Jan 24 05:51:17 2006
@@ -67,18 +67,22 @@
 
 
         <xsl:for-each select="property">
+            <!-- Write only the NOT inherited properties-->
+            <xsl:if test="not(@inherited)">
             <xsl:variable name="propertyType"><xsl:value-of select="@type"></xsl:value-of></xsl:variable>
             <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable>
             <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
             <xsl:variable name="min"><xsl:value-of select="@minOccurs"/></xsl:variable>
             <xsl:variable name="varName">local<xsl:value-of select="$javaName"/></xsl:variable>
             <xsl:variable name="settingTracker">local<xsl:value-of select="$javaName"/>Tracker</xsl:variable>
+
+
             /**
             * field for <xsl:value-of select="$javaName"/>
             <xsl:if test="@attribute">* This was an Attribute!</xsl:if>
             <xsl:if test="@array">* This was an Array!</xsl:if>
             */
-            private <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of
select="$varName" /> ;
+            protected <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of
select="$varName" /> ;
             <!-- Generate a tracker only if the min occurs is zero, which means if the
user does
                  not bother to set that value, we do not send it -->
             <xsl:if test="$min=0">
@@ -86,7 +90,7 @@
                 for this attribute. It will be used to determine whether to include this
field
                 in the serialized XML
             */
-            private boolean <xsl:value-of select="$settingTracker"/> = false ;
+            protected boolean <xsl:value-of select="$settingTracker"/> = false ;
             </xsl:if>
 
             /**
@@ -121,6 +125,7 @@
              </xsl:if>
             this.<xsl:value-of select="$varName"/>=param;
             }
+            </xsl:if>
         </xsl:for-each>
 
         /**

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=371914&r1=371913&r2=371914&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Tue Jan 24 05:51:17 2006
@@ -4,6 +4,7 @@
 import org.apache.axis2.schema.CompilerOptions;
 import org.apache.axis2.schema.SchemaCompilationException;
 import org.apache.axis2.schema.SchemaCompiler;
+import org.apache.axis2.schema.typemap.JavaTypeMap;
 import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.util.JavaUtils;
@@ -73,6 +74,8 @@
     private Map modelMap = new HashMap();
     private static final String DEFAULT_PACKAGE = "adb";
 
+    private Map baseTypeMap = new JavaTypeMap().getTypeMap();
+
     /**
      * Default constructor
      */
@@ -343,6 +346,47 @@
         if (metainf.isExtension()) {
             XSLTUtils.addAttribute(model, "extension", metainf.getExtensionClassName(), rootElt);
         }
+
+        //populate all the information
+        populateInfo(metainf, model, rootElt, propertyNames, typeMap,false);
+
+       
+        return rootElt;
+    }
+
+    /**
+     *
+     * @param metainf
+     * @param model
+     * @param rootElt
+     * @param propertyNames
+     * @param typeMap
+     * @throws SchemaCompilationException
+     */
+    private void populateInfo(BeanWriterMetaInfoHolder metainf,
+                              Document model,
+                              Element rootElt,
+                              ArrayList propertyNames,
+                              Map typeMap,boolean isInherited)throws SchemaCompilationException{
+        if (metainf.getParent()!=null){
+            populateInfo(metainf.getParent(),model,rootElt,propertyNames,typeMap,true);
+        }
+        addPropertyEntries(metainf, model, rootElt, propertyNames, typeMap,isInherited);
+
+    }
+
+    /**
+     *
+     * @param metainf
+     * @param model
+     * @param rootElt
+     * @param propertyNames
+     * @param typeMap
+     * @throws SchemaCompilationException
+     */
+    private void addPropertyEntries(BeanWriterMetaInfoHolder metainf, Document model, Element
rootElt, ArrayList propertyNames,
+                                    Map typeMap,
+                                    boolean isInherited) throws SchemaCompilationException
{
         // go in the loop and add the part elements
         QName[] qNames;
         if (metainf.isOrdered()) {
@@ -363,13 +407,9 @@
 
             String javaClassNameForElement = metainf.getClassNameForQName(name);
 
-            String shortTypeName = "";
-            if (metainf.getSchemaQNameForQName(name) != null) {
-                shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
-            }
 
             if (javaClassNameForElement == null) {
-                throw new SchemaCompilationException("Type missing!");
+                throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.typeMissing"));
             }
 
             XSLTUtils.addAttribute(model, "type", javaClassNameForElement, property);
@@ -380,15 +420,30 @@
             }
 
             if (typeMap.containsKey(metainf.getSchemaQNameForQName(name))) {
-                XSLTUtils.addAttribute(model, "ours", "yes", property); //todo introduce
a better name for this
+                XSLTUtils.addAttribute(model, "ours", "yes", property);
             }
 
             if (metainf.getAttributeStatusForQName(name)) {
                 XSLTUtils.addAttribute(model, "attribute", "yes", property);
             }
 
+            String shortTypeName = "";
+             if (metainf.getSchemaQNameForQName(name) != null) {
+                 //see whether the QName is a basetype
+                 if (baseTypeMap.containsKey(metainf.getSchemaQNameForQName(name))){
+                    shortTypeName= metainf.getSchemaQNameForQName(name).getLocalPart();
+                 }else{
+                     shortTypeName =  getShortTypeName(javaClassNameForElement);
+                 }
+            }else{
+                 shortTypeName =  getShortTypeName(javaClassNameForElement);
+             }
             XSLTUtils.addAttribute(model, "shorttypename", shortTypeName, property);
 
+            if (isInherited){
+                XSLTUtils.addAttribute(model, "inherited", "yes", property);
+            }
+
             if (metainf.getAnyStatusForQName(name)) {
                 XSLTUtils.addAttribute(model, "any", "yes", property);
             }
@@ -401,7 +456,7 @@
             long minOccurs = metainf.getMinOccurs(name);
             XSLTUtils.addAttribute(model, "minOccurs", minOccurs + "", property);
 
-            
+
             if (metainf.getArrayStatusForQName(name)) {
 
                 XSLTUtils.addAttribute(model, "array", "yes", property);
@@ -419,11 +474,6 @@
                 }
             }
         }
-
-        /////////////////////////////////////
-        //System.out.println("rootElt = " + rootElt);
-        /////////////////////////////////////
-        return rootElt;
     }
 
     /**
@@ -566,5 +616,15 @@
             mapURItoPrefix.put(uri, prefix);
         }
         return prefix;
+    }
+
+    private String getShortTypeName(String typeClassName){
+         if (typeClassName.endsWith("[]")){
+             typeClassName = typeClassName.substring(0,typeClassName.lastIndexOf("["));
+         }
+        String s = typeClassName.substring(typeClassName.lastIndexOf(".")+1, typeClassName.length());
+
+        return s;
+
     }
 }



Mime
View raw message