axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r424585 - in /webservices/axis2/trunk/java/modules: adb-codegen/src/org/apache/axis2/schema/ adb-codegen/src/org/apache/axis2/schema/i18n/ adb-codegen/src/org/apache/axis2/schema/template/ adb-codegen/src/org/apache/axis2/schema/writer/ cod...
Date Sat, 22 Jul 2006 14:32:11 GMT
Author: ajith
Date: Sat Jul 22 07:32:10 2006
New Revision: 424585

URL: http://svn.apache.org/viewvc?rev=424585&view=rev
Log:
1. Added xsi:type based deserialization support to ADB
  I. Changed the BeanWriter interface to have a new method -writeExtensionMapper
  II. Added the code to the JavaBeanWriter.java to implement that fucntionality
  III. Added a new piece of template to the ADBBeanTemplate.xsl
  IV. Changed the CompilerOptions.java to include the mapper package name as a field. This however needs to be populated into the writer properly

Now there is an extesion mapper class generated and the parsing logic always delegates the task of producing the right type of object to the mapper when a type attribute is encountered

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/CompilerOptions.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/BeanWriter.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
    webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/ant/AntCodegenTask.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java Sat Jul 22 07:32:10 2006
@@ -3,7 +3,6 @@
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +45,8 @@
     protected Map qNameMaxOccursCountMap = new LinkedHashMap();
     protected Map qNameMinOccursCountMap = new LinkedHashMap();
     protected Map qNameOrderMap = new LinkedHashMap();
+    protected QName ownQname = null;
+    protected String ownClassName = null;
 
     protected List nillableQNameList  = new ArrayList();
 
@@ -62,6 +63,22 @@
 
     public void setChoice(boolean choice) {
         this.choice = choice;
+    }
+
+    public String getOwnClassName() {
+        return ownClassName;
+    }
+
+    public void setOwnClassName(String ownClassName) {
+        this.ownClassName = ownClassName;
+    }
+
+    public QName getOwnQname() {
+        return ownQname;
+    }
+
+    public void setOwnQname(QName ownQname) {
+        this.ownQname = ownQname;
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/CompilerOptions.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/CompilerOptions.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/CompilerOptions.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/CompilerOptions.java Sat Jul 22 07:32:10 2006
@@ -40,6 +40,18 @@
      */
     private File outputLocation;
     private String packageName = null;
+    /**
+     * Package for the mapper
+     */
+    private String mapperClassPackage = null;
+
+    public String getMapperClassPackage() {
+        return mapperClassPackage;
+    }
+
+    public void setMapperClassPackage(String mapperClassPackage) {
+        this.mapperClassPackage = mapperClassPackage;
+    }
 
     /**
      * The flag keeping whether seperate helpers

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=424585&r1=424584&r2=424585&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 Sat Jul 22 07:32:10 2006
@@ -6,6 +6,7 @@
 import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.schema.writer.BeanWriter;
+import org.apache.axis2.util.URLProcessor;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAll;
 import org.apache.ws.commons.schema.XmlSchemaAny;
@@ -91,6 +92,7 @@
     //a list of nillable elements - used to generate code
     //for nillable elements
     private List nillableElementList;
+    // writee reference
     private BeanWriter writer = null;
     private Map baseSchemaTypeMap = null;
 
@@ -187,9 +189,12 @@
      * @see #compile(org.apache.ws.commons.schema.XmlSchema)
      */
     public void compile(List schemalist) throws SchemaCompilationException {
+        try {
 
+            if (schemalist.isEmpty()){
+                return;
+            }
 
-        try {
             //clear the loaded and available maps
             loadedSchemaMap.clear();
             availableSchemaMap.clear();
@@ -204,11 +209,19 @@
                 );
             }
 
+            //get the first schema from the list and take that namespace as the
+            //mapper namespace
+            writer.registerExtensionMapperPackageName(
+                    URLProcessor.makePackageName(((XmlSchema) schemalist.get(0)).getTargetNamespace()));
+
             // second round - call the schema compiler one by one
             for (int i = 0; i < schemalist.size(); i++) {
-                compile((XmlSchema) schemalist.get(i));
+                compile((XmlSchema) schemalist.get(i),true);
             }
 
+            //finish up
+            finalizeSchemaCompilation();
+
         } catch (SchemaCompilationException e) {
             throw e;
         } catch (Exception e) {
@@ -222,6 +235,16 @@
      * @throws SchemaCompilationException
      */
     public void compile(XmlSchema schema) throws SchemaCompilationException {
+        compile(schema,false);
+    }
+
+    /**
+     * Compile (rather codegen) a single schema element
+     * @param schema
+     * @param isPartofGroup
+     * @throws SchemaCompilationException
+     */
+    private void compile(XmlSchema schema,boolean isPartofGroup) throws SchemaCompilationException {
 
         // some documents explicitly imports the schema of built in types. We don't actually need to compile
         // the built-in types. So check the target namespace here and ignore it.
@@ -229,6 +252,12 @@
             return;
         }
 
+        //register the package from this namespace as the mapper classes package
+        if (!isPartofGroup){
+            writer.registerExtensionMapperPackageName(
+                    URLProcessor.makePackageName(schema.getTargetNamespace()));
+        }
+
         //First look for the schemas that are imported and process them
         //Note that these are processed recursively!
 
@@ -268,7 +297,7 @@
         Iterator xmlSchemaElement2Iterator = elements.getValues();
 
         // re-iterate through the elements and write them one by one
-        // if the mode is unwrap this process will not really write the
+        // if the mode is unpack this process will not really write the
         // classes but will accumilate the models for a final single shot
         // write
         while (xmlSchemaElement2Iterator.hasNext()) {
@@ -276,6 +305,24 @@
             writeElement((XmlSchemaElement) xmlSchemaElement2Iterator.next());
         }
 
+        if (!isPartofGroup){
+            //complete the compilation
+            finalizeSchemaCompilation();
+        }
+    }
+
+    /**
+     * Completes the schema compilation process by writing the
+     * mappers and the classes in a batch if needed
+     * @throws SchemaCompilationException
+     */
+    private void finalizeSchemaCompilation() throws SchemaCompilationException {
+        //write the extension mapping class
+        writer.writeExtensionMapper(
+                (BeanWriterMetaInfoHolder[])
+                        processedTypeMetaInfoMap.values().toArray(
+                                new BeanWriterMetaInfoHolder[processedTypeMetaInfoMap.size()]));
+
 
         if (options.isWrapClasses()) {
             writer.writeBatch();
@@ -448,8 +495,7 @@
                         //set a name
                         schemaType.setName(generatedTypeName.getLocalPart());
                         writeComplexType((XmlSchemaComplexType)schemaType,
-                                (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(xsElt),
-                                null);
+                                (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(xsElt));
                         //remove the reference from the anon list since we named the type
                         processedAnonymousComplexTypesMap.remove(xsElt);
                         String className = findClassName(schemaType.getQName(), isArray(xsElt));
@@ -501,8 +547,8 @@
                     referenceSchemaType.setName(generatedTypeName.getLocalPart());
 
                     writeComplexType((XmlSchemaComplexType)referenceSchemaType,
-                            (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(referencedElement),
-                            null);
+                            (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(referencedElement)
+                    );
                     //remove the reference from the anon list since we named the type
                     processedAnonymousComplexTypesMap.remove(referencedElement);
 
@@ -716,10 +762,12 @@
                 fullyQualifiedClassName);
 
         BeanWriterMetaInfoHolder metaInfHolder = processComplexType(complexType,parentSchema);
-
+        //add this information to the metainfo holder
+        metaInfHolder.setOwnQname(complexType.getQName());
+        metaInfHolder.setOwnClassName(fullyQualifiedClassName);
         //write the class. This type mapping would have been populated right now
         //Note - We always write classes for named complex types
-        writeComplexType(complexType, metaInfHolder, fullyQualifiedClassName);
+        writeComplexType(complexType, metaInfHolder);
 
 
     }
@@ -731,9 +779,9 @@
      * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
      * @throws SchemaCompilationException
      */
-    private void writeComplexType(XmlSchemaComplexType complexType, BeanWriterMetaInfoHolder metaInfHolder, String fullyQualifiedClassName)
+    private void writeComplexType(XmlSchemaComplexType complexType, BeanWriterMetaInfoHolder metaInfHolder)
             throws SchemaCompilationException {
-        writer.write(complexType, processedTypemap, metaInfHolder, fullyQualifiedClassName);
+        writer.write(complexType, processedTypemap, metaInfHolder);
         processedTypeMetaInfoMap.put(complexType.getQName(),metaInfHolder);
     }
 
@@ -856,10 +904,13 @@
                                        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
@@ -908,6 +959,12 @@
         }
     }
 
+    /**
+     *
+     * @param simpleContent
+     * @param metaInfHolder
+     * @throws SchemaCompilationException
+     */
     private void processSimpleContent(XmlSchemaSimpleContent simpleContent,BeanWriterMetaInfoHolder metaInfHolder)
             throws SchemaCompilationException{
         XmlSchemaContent content;

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties Sat Jul 22 07:32:10 2006
@@ -30,4 +30,5 @@
 schema.notimplementedxception=Not implemented yet
 schema.templateLoadException=Error loading the template
 schema.templateNotFoundException=template for this writer is not found
-schema.typeMissing=Type missing!
\ No newline at end of file
+schema.typeMissing=Type missing!
+schema.docuement.error=Error in creating the document
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Sat Jul 22 07:32:10 2006
@@ -30,12 +30,18 @@
 
     <xsl:template match="bean[not(@helperMode)]">
 
-        <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable>
+        <xsl:variable name="name" select="@name"/>
         <xsl:variable name="choice" select="@choice"/>
         <xsl:variable name="ordered" select="@ordered"/>
         <xsl:variable name="unordered" select="not($ordered)"/>  <!-- for convenience -->
         <xsl:variable name="isType" select="@type"/>
         <xsl:variable name="anon" select="@anon"/>
+
+        <xsl:variable name="nsuri" select="@nsuri"/>
+        <xsl:variable name="originalName" select="@originalName"/>
+        <xsl:variable name="nsprefix" select="@nsprefix"/>
+        <xsl:variable name="extension" select="@extension"/>
+        <xsl:variable name="mapperClass" select="@mapperClass"/>
     <!-- write the class header. this should be done only when unwrapped -->
 
         <xsl:if test="not(not(@unwrapped) or (@skip-write))">
@@ -51,20 +57,20 @@
             *  <xsl:value-of select="$name"/> bean class
             */
         </xsl:if>
-        public <xsl:if test="not(@unwrapped) or (@skip-write)">static</xsl:if> class <xsl:value-of select="$name"/> <xsl:if test="@extension"> extends <xsl:value-of select="@extension"/></xsl:if>
+        public <xsl:if test="not(@unwrapped) or (@skip-write)">static</xsl:if> class <xsl:value-of select="$name"/> <xsl:if test="$extension"> extends <xsl:value-of select="$extension"/></xsl:if>
         implements org.apache.axis2.databinding.ADBBean{
         <xsl:choose>
             <xsl:when test="@type">/* This type was generated from the piece of schema that had
-                name = <xsl:value-of select="@originalName"/>
-                Namespace URI = <xsl:value-of select="@nsuri"/>
-                Namespace Prefix = <xsl:value-of select="@nsprefix"/>
+                name = <xsl:value-of select="$originalName"/>
+                Namespace URI = <xsl:value-of select="$nsuri"/>
+                Namespace Prefix = <xsl:value-of select="$nsprefix"/>
                 */
             </xsl:when>
             <xsl:otherwise>
                 public static final javax.xml.namespace.QName MY_QNAME = new javax.xml.namespace.QName(
-                "<xsl:value-of select="@nsuri"/>",
-                "<xsl:value-of select="@originalName"/>",
-                "<xsl:value-of select="@nsprefix"/>");
+                "<xsl:value-of select="$nsuri"/>",
+                "<xsl:value-of select="$originalName"/>",
+                "<xsl:value-of select="$nsprefix"/>");
 
             </xsl:otherwise>
         </xsl:choose>
@@ -284,6 +290,12 @@
 		    xmlWriter.writeStartElement(parentQName.getLocalPart());
 		}
 
+                <!-- write the type attribute if needed -->
+               <xsl:if test="$extension">
+               writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                       registerPrefix(xmlWriter,"<xsl:value-of select="$nsuri"/>")+":<xsl:value-of select="$originalName"/>",
+                       xmlWriter);
+               </xsl:if>
                 <!--First serialize the attributes!-->
                 <xsl:for-each select="property[@attribute]">
                     <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
@@ -292,22 +304,25 @@
                     <xsl:choose>
                         <!-- Note - It is assumed that any attributes are OMAttributes-->
                         <xsl:when test="@any and not(@array)">
-                            xmlWriter.writeAttribute(<xsl:value-of select="$varName"/>.getNamespace().getName(),
+                           writeAttribute(<xsl:value-of select="$varName"/>.getNamespace().getName(),
                                                      <xsl:value-of select="$varName"/>.getLocalName(),
-                                                     <xsl:value-of select="$varName"/>.getAttributeValue());
+                                                     <xsl:value-of select="$varName"/>.getAttributeValue(),
+                                                     xmlWriter);
                         </xsl:when>
                          <xsl:when test="@any and @array">
                              for (int i=0;i &lt;<xsl:value-of select="$varName"/>.length;i++){
-                              xmlWriter.writeAttribute(<xsl:value-of select="$varName"/>[i].getNamespace().getName(),
+                              writeAttribute(<xsl:value-of select="$varName"/>[i].getNamespace().getName(),
                                                      <xsl:value-of select="$varName"/>[i].getLocalName(),
-                                                     <xsl:value-of select="$varName"/>[i].getAttributeValue());
+                                                     <xsl:value-of select="$varName"/>[i].getAttributeValue(),
+                                                  xmlWriter);
                              }
                          </xsl:when>
                         <!-- there can never be attribute arrays in the normal case-->
                         <xsl:otherwise>
-                             xmlWriter.writeAttribute("<xsl:value-of select="$namespace"/>",
+                             writeAttribute("<xsl:value-of select="$namespace"/>",
                                                      "<xsl:value-of select="$propertyName"/>",
-                                                      org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>));
+                                                      org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>),
+                            xmlWriter);
                         </xsl:otherwise>
                     </xsl:choose>
                 </xsl:for-each>
@@ -348,19 +363,10 @@
 						xmlWriter.writeStartElement("<xsl:value-of select="$propertyName"/>");
 					}
 					
-					<!-- TODO remove the following line -->
-                                       //xmlWriter.writeStartElement("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
+
                                        // write the nil attribute
-                                    java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                                          java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
-                                       xmlWriter.writeAttribute(schemaNS,
-                                                     "nil",
-                                                     "true");
-                                       xmlWriter.writeEndElement();
+                                      writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
+                                      xmlWriter.writeEndElement();
                                     }else{
                                      <xsl:value-of select="$varName"/>.getOMElement(
                                        new javax.xml.namespace.QName("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>"),
@@ -456,38 +462,33 @@
                                     }
                                 </xsl:otherwise>
                             </xsl:choose>
-			    
+
                             for (int i = 0;i &lt; <xsl:value-of select="$varName"/>.length;i++){
                             	        namespace = "<xsl:value-of select="$namespace"/>";
-			
+
 					if (! namespace.equals("")) {
 						prefix = xmlWriter.getPrefix(namespace);
-				    
+
 						if (prefix == null) {
 							prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrifix();
-					
+
 							xmlWriter.writeStartElement(prefix,"<xsl:value-of select="$propertyName"/>", namespace);
 							xmlWriter.writeNamespace(prefix, namespace);
 							xmlWriter.setPrefix(prefix, namespace);
-					    
+
 						} else {
 							xmlWriter.writeStartElement(namespace,"<xsl:value-of select="$propertyName"/>");
 						}
-				    
+
 					} else {
 						xmlWriter.writeStartElement("<xsl:value-of select="$propertyName"/>");
 					}
-					
-					<!-- TODO remove the following -->
-			      // xmlWriter.writeStartElement("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
-                            java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                            java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
+
+
+
                               if (<xsl:value-of select="$varName"/>[i]==null){
-                                  xmlWriter.writeAttribute(schemaNS,"nil","true");
+                                  // write the nil attribute
+                                  writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
                               }else{
                                  xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>[i]));
                               }
@@ -514,26 +515,26 @@
                         <!-- handle all other cases including the binary case -->
                          <xsl:otherwise>
 			 		namespace = "<xsl:value-of select="$namespace"/>";
-			
+
 					if (! namespace.equals("")) {
 						prefix = xmlWriter.getPrefix(namespace);
-				    
+
 						if (prefix == null) {
 							prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrifix();
-					
+
 							xmlWriter.writeStartElement(prefix,"<xsl:value-of select="$propertyName"/>", namespace);
 							xmlWriter.writeNamespace(prefix, namespace);
 							xmlWriter.setPrefix(prefix, namespace);
-					    
+
 						} else {
 							xmlWriter.writeStartElement(namespace,"<xsl:value-of select="$propertyName"/>");
 						}
-				    
+
 					} else {
 						xmlWriter.writeStartElement("<xsl:value-of select="$propertyName"/>");
 					}
-					
-				<!-- TODO remove the following line -->	
+
+				<!-- TODO remove the following line -->
                             //xmlWriter.writeStartElement("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
                             xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>));
                             xmlWriter.writeEndElement();
@@ -563,37 +564,28 @@
                             <xsl:when test="$nillable">
                                       if (<xsl:value-of select="$varName"/>==null){
 				        java.lang.String namespace = "<xsl:value-of select="property/@nsuri"/>";
-			
+
 						if (! namespace.equals("")) {
 							java.lang.String prefix = xmlWriter.getPrefix(namespace);
-					    
+
 							if (prefix == null) {
 								prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrifix();
-						
+
 								xmlWriter.writeStartElement(prefix,"<xsl:value-of select="property/@name"/>", namespace);
 								xmlWriter.writeNamespace(prefix, namespace);
 								xmlWriter.setPrefix(prefix, namespace);
-						    
+
 							} else {
 								xmlWriter.writeStartElement(namespace,"<xsl:value-of select="property/@name"/>");
 							}
-					    
+
 						} else {
 							xmlWriter.writeStartElement("<xsl:value-of select="property/@name"/>");
 						}
-						<!--TODO remove the following line -->
-                                          //xmlWriter.writeStartElement("<xsl:value-of select="property/@namespace"/>","<xsl:value-of select="property/@name"/>");
-                                          // write the nil attribute
-                                          java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                                          java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
-                                          xmlWriter.writeAttribute(schemaNS,
-                                                     "nil",
-                                                     "true");
-                                          xmlWriter.writeEndElement();
+
+                                        // write the nil attribute
+                                        writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
+                                        xmlWriter.writeEndElement();
                                        }else{
                                          <xsl:value-of select="$varName"/>.getOMElement(
                                          MY_QNAME,
@@ -613,30 +605,26 @@
                     <!-- end of ours block-->
                     <xsl:otherwise>
 		        java.lang.String namespace = "<xsl:value-of select="property/@nsuri"/>";
-			
+
 			if (! namespace.equals("")) {
 				java.lang.String prefix = xmlWriter.getPrefix(namespace);
-                    
+
 				if (prefix == null) {
 					prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrifix();
-                        
+
 					xmlWriter.writeStartElement(prefix,"<xsl:value-of select="property/@name"/>", namespace);
 					xmlWriter.writeNamespace(prefix, namespace);
 					xmlWriter.setPrefix(prefix, namespace);
-                            
+
 				} else {
 					xmlWriter.writeStartElement(namespace,"<xsl:value-of select="property/@name"/>");
 				}
-                    
+
 			} else {
 				xmlWriter.writeStartElement("<xsl:value-of select="property/@name"/>");
 			}
-			
-			<!--TODO remove the following line -->
-						
-                       //xmlWriter.writeStartElement(
-                       //"<xsl:value-of select="property/@namespace"/>","<xsl:value-of select="property/@name"/>");
-                       xmlWriter.writeCharacters(
+
+			xmlWriter.writeCharacters(
                         org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>));
                        xmlWriter.writeEndElement();
                     </xsl:otherwise>
@@ -646,6 +634,58 @@
 
         }
 
+         /**
+          * Util method to write an attribute with the ns prefix
+          */
+          private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
+                                      java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
+              if (xmlWriter.getPrefix(namespace) == null) {
+                       xmlWriter.writeNamespace(prefix, namespace);
+                       xmlWriter.setPrefix(prefix, namespace);
+
+              }
+
+              xmlWriter.writeAttribute(namespace,attName,attValue);
+
+         }
+
+         /**
+          * Util method to write an attribute without the ns prefix
+          */
+          private void writeAttribute(java.lang.String namespace,java.lang.String attName,
+                                      java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
+
+           registerPrefix(xmlWriter, namespace);
+
+            xmlWriter.writeAttribute(namespace,attName,attValue);
+          }
+
+         /**
+         * Register a namespace prefix
+         */
+         private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
+                java.lang.String prefix = xmlWriter.getPrefix(namespace);
+
+                if (prefix == null) {
+                    prefix = createPrefix();
+
+                    while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
+                        prefix = createPrefix();
+                    }
+
+                    xmlWriter.writeNamespace(prefix, namespace);
+                    xmlWriter.setPrefix(prefix, namespace);
+                }
+
+                return prefix;
+            }
+
+         /**
+          * Create a prefix
+          */
+          private String createPrefix() {
+                return "ns" + (int)Math.random();
+          }
         };
 
         <xsl:choose>
@@ -910,14 +950,35 @@
                          return null;
                    }
                 </xsl:if>
+                  <xsl:if test="$isType or $anon">
+                if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){
+                  java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
+                        "type");
+                  if (fullTypeName!=null){
+                    java.lang.String nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
+                    nsPrefix = nsPrefix==null?"":nsPrefix;
+
+                    java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":")+1);
+                    if (!"<xsl:value-of select="$originalName"/>".equals(type)){
+                        //find namespace for the prefix
+                        java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
+                        return (<xsl:value-of select="$name"/>)<xsl:value-of select="$mapperClass"/>.getTypeObject(
+                             nsUri,type,reader);
+                      }
+
+                  }
+
+                }
+                </xsl:if>
 
                 <!-- populate attributes here!!!. The attributes are part of an element, not part of a type -->
                 <xsl:for-each select="property[@attribute]">
-                    <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
-                    <xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
-                    <xsl:variable name="shortTypeName"><xsl:value-of select="@shorttypename"/></xsl:variable>
-                    <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
-                    <xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
+                    <xsl:variable name="propertyName" select="@name"/>
+                    <xsl:variable name="propertyType" select="@type"/>
+                    <xsl:variable name="shortTypeNameUncapped"  select="@shorttypename"/>
+                    <xsl:variable name="shortTypeName"  select="@shorttypename"/>
+                    <xsl:variable name="javaName" select="@javaname"/>
+                    <xsl:variable name="namespace" select="@nsuri"/>
                     <xsl:variable name="attribName">tempAttrib<xsl:value-of select="$propertyName"/></xsl:variable>
 
                     java.lang.String <xsl:value-of select="$attribName"/> =
@@ -1196,7 +1257,7 @@
                                 }
                             </xsl:if>
                         </xsl:for-each>
-                        
+
                         <xsl:if test="$ordered">  <!-- pick up trailing cruft after final property before outer endElement and verify no trailing properties -->
                             while (!reader.isStartElement() &amp;&amp; !reader.isEndElement())
                                 reader.next();
@@ -1230,8 +1291,16 @@
 
         }
            <!-- end of main template -->
-          </xsl:template>  
-    
+          </xsl:template>
+
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-->
+
+
     <!-- this is the common template -->
     <xsl:template match="bean[@helperMode]">
 
@@ -1241,6 +1310,12 @@
         <xsl:variable name="unordered" select="not($ordered)"/>  <!-- for convenience -->
         <xsl:variable name="isType" select="@type"/>
         <xsl:variable name="anon" select="@anon"/>
+
+        <xsl:variable name="nsuri" select="@nsuri"/>
+        <xsl:variable name="originalName" select="@originalName"/>
+        <xsl:variable name="nsprefix" select="@nsprefix"/>
+        <xsl:variable name="extension" select="@extension"/>
+         <xsl:variable name="mapperClass" select="@mapperClass"/>
     <!-- write the class header. this should be done only when unwrapped -->
 
         <xsl:if test="not(not(@unwrapped) or (@skip-write))">
@@ -1256,12 +1331,12 @@
             *  <xsl:value-of select="$name"/> bean class
             */
         </xsl:if>
-	
-	
+
+
 	<xsl:choose>
 	<xsl:when test="not(@helper)">
-	
-	public <xsl:if test="not(@unwrapped) or (@skip-write)">static</xsl:if> class <xsl:value-of select="$name"/> <xsl:if test="@extension"> extends <xsl:value-of select="@extension"/></xsl:if>
+
+	public <xsl:if test="not(@unwrapped) or (@skip-write)">static</xsl:if> class <xsl:value-of select="$name"/> <xsl:if test="$extension"> extends <xsl:value-of select="$extension"/></xsl:if>
         implements org.apache.axis2.databinding.ADBBean{
         <xsl:choose>
             <xsl:when test="@type">/* This type was generated from the piece of schema that had
@@ -1472,6 +1547,12 @@
                 xmlWriter.writeStartElement(parentQName.getNamespaceURI(),
                                             parentQName.getLocalPart());
 
+               <!-- write the type attribute if needed -->
+               <xsl:if test="$extension">
+               writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                       registerPrefix(xmlWriter,"<xsl:value-of select="$nsuri"/>")+":<xsl:value-of select="$originalName"/>",
+                       xmlWriter);
+               </xsl:if>
                 <!--First serialize the attributes!-->
                 <xsl:for-each select="property[@attribute]">
                     <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
@@ -1480,22 +1561,22 @@
                     <xsl:choose>
                         <!-- Note - It is assumed that any attributes are OMAttributes-->
                         <xsl:when test="@any and not(@array)">
-                            xmlWriter.writeAttribute(<xsl:value-of select="$varName"/>.getNamespace().getName(),
+                            writeAttribute(<xsl:value-of select="$varName"/>.getNamespace().getName(),
                                                      <xsl:value-of select="$varName"/>.getLocalName(),
-                                                     <xsl:value-of select="$varName"/>.getAttributeValue());
+                                                     <xsl:value-of select="$varName"/>.getAttributeValue(),xmlWriter);
                         </xsl:when>
                          <xsl:when test="@any and @array">
                              for (int i=0;i &lt;<xsl:value-of select="$varName"/>.length;i++){
-                              xmlWriter.writeAttribute(<xsl:value-of select="$varName"/>[i].getNamespace().getName(),
+                              writeAttribute(<xsl:value-of select="$varName"/>[i].getNamespace().getName(),
                                                      <xsl:value-of select="$varName"/>[i].getLocalName(),
-                                                     <xsl:value-of select="$varName"/>[i].getAttributeValue());
+                                                     <xsl:value-of select="$varName"/>[i].getAttributeValue(),xmlWriter);
                              }
                          </xsl:when>
                         <!-- there can never be attribute arrays in the normal case-->
                         <xsl:otherwise>
-                             xmlWriter.writeAttribute("<xsl:value-of select="$namespace"/>",
+                             writeAttribute("<xsl:value-of select="$namespace"/>",
                                                      "<xsl:value-of select="$propertyName"/>",
-                                                      org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>));
+                                                      org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>),xmlWriter);
                         </xsl:otherwise>
                     </xsl:choose>
                 </xsl:for-each>
@@ -1516,16 +1597,8 @@
                                 <xsl:when test="@nillable">
                                     if (<xsl:value-of select="$varName"/>==null){
                                        xmlWriter.writeStartElement("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
-                                       // write the nil attribute
-                                       java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                                          java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
-                                       xmlWriter.writeAttribute(schemaNS,
-                                                     "nil",
-                                                     "true");
+                                      // write the nil attribute
+                                      writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
                                        xmlWriter.writeEndElement();
                                     }else{
                                      <xsl:value-of select="$varName"/>.getOMElement(
@@ -1625,15 +1698,8 @@
                             for (int i = 0;i &lt; <xsl:value-of select="$varName"/>.length;i++){
                               xmlWriter.writeStartElement("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>");
                               if (<xsl:value-of select="$varName"/>[i]==null){
-                                  java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                                          java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
-                                  xmlWriter.writeAttribute(schemaNS,
-                                                     "nil",
-                                                     "true");
+                                  // write the nil attribute
+                                  writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
                               }else{
                                  xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>[i]));
                               }
@@ -1688,17 +1754,11 @@
                             <xsl:when test="$nillable">
                                       if (<xsl:value-of select="$varName"/>==null){
                                           xmlWriter.writeStartElement("<xsl:value-of select="property/@namespace"/>","<xsl:value-of select="property/@name"/>");
-                                          // write the nil attribute
-                                         java.lang.String schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
-                                          java.lang.String schemaPrefix = "xsi";
-                                          if (xmlWriter.getPrefix(schemaNS) == null) {
-                                              xmlWriter.writeNamespace(schemaPrefix, schemaNS);
-                                              xmlWriter.setPrefix(schemaPrefix, schemaNS);
-                                          }
-                                          xmlWriter.writeAttribute(schemaNS,
-                                                     "nil",
-                                                     "true");
-                                          xmlWriter.writeEndElement();
+
+                                         // write the nil attribute
+                                        writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","nil","true",xmlWriter);
+
+                                        xmlWriter.writeEndElement();
                                        }else{
                                          <xsl:value-of select="$varName"/>.getOMElement(
                                          MY_QNAME,
@@ -1729,6 +1789,58 @@
 
         }
 
+         /**
+          * Util method to write an attribute with the ns prefix
+          */
+          private void writeAttribute(java.lang.String prefix,java.lang.String namespace,java.lang.String attName,
+                                      java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
+              if (xmlWriter.getPrefix(namespace) == null) {
+                       xmlWriter.writeNamespace(prefix, namespace);
+                       xmlWriter.setPrefix(prefix, namespace);
+
+              }
+
+              xmlWriter.writeAttribute(namespace,attName,attValue);
+
+         }
+
+          /**
+          * Util method to write an attribute without the ns prefix
+          */
+          private void writeAttribute(java.lang.String namespace,java.lang.String attName,
+                                      java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
+
+           registerPrefix(xmlWriter, namespace);
+
+            xmlWriter.writeAttribute(namespace,attName,attValue);
+          }
+
+         /**
+         * Register a namespace prefix
+         */
+         private java.lang.String registerPrefix(javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace) throws javax.xml.stream.XMLStreamException {
+                java.lang.String prefix = xmlWriter.getPrefix(namespace);
+
+                if (prefix == null) {
+                    prefix = createPrefix();
+
+                    while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
+                        prefix = createPrefix();
+                    }
+
+                    xmlWriter.writeNamespace(prefix, namespace);
+                    xmlWriter.setPrefix(prefix, namespace);
+                }
+
+                return prefix;
+            }
+
+         /**
+          * Create a prefix
+          */
+          private String createPrefix() {
+                return "ns" + (int)Math.random();
+          }
         };
 
         <xsl:choose>
@@ -1789,6 +1901,25 @@
                    }
                 </xsl:if>
 
+                if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){
+                  java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
+                        "type");
+                  if (fullTypeName!=null){
+                    java.lang.String nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
+                    nsPrefix = nsPrefix==null?"":nsPrefix;
+
+                    java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":")+1);
+
+                     if (!"<xsl:value-of select="$originalName"/>".equals(type)){
+                        //find namespace for the prefix
+                        java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
+                        return (<xsl:value-of select="$name"/>)<xsl:value-of select="$mapperClass"/>.getTypeObject(
+                             nsUri,type,reader);
+                      }
+
+                  }
+
+                }
                 <!-- populate attributes here!!!. The attributes are part of an element, not part of a type -->
                 <xsl:for-each select="property[@attribute]">
                     <xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
@@ -2306,5 +2437,41 @@
 	</xsl:otherwise>
 	</xsl:choose>
            <!-- end of main template -->
-          </xsl:template>
+  </xsl:template>
+
+  <xsl:template match="mapper">
+        <xsl:variable name="name"><xsl:value-of select="@name"/></xsl:variable>
+       
+         <xsl:if test="not(not(@unwrapped) or (@skip-write))">
+            /**
+            * <xsl:value-of select="$name"/>.java
+            *
+            * This file was auto-generated from WSDL
+            * by the Apache Axis2 version: #axisVersion# #today#
+            */
+
+            package <xsl:value-of select="@package"/>;
+            /**
+            *  <xsl:value-of select="$name"/> bean class
+            */
+        </xsl:if>
+        public <xsl:if test="not(@unwrapped) or (@skip-write)">static</xsl:if> class <xsl:value-of select="$name"/>{
+
+          public static java.lang.Object getTypeObject(java.lang.String namespaceURI,
+                                                       java.lang.String typeName,
+                                                       javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
+
+              <xsl:for-each select="type">
+                <xsl:if test="position() &gt; 1">else </xsl:if> if (
+                  "<xsl:value-of select="@nsuri"/>".equals(namespaceURI) &amp;&amp;
+                  "<xsl:value-of select="@shortname"/>".equals(typeName)){
+                     return  <xsl:value-of select="@classname"/>.Factory.parse(reader);
+                  }
+
+              </xsl:for-each>
+             return null;
+          }
+
+        }
+    </xsl:template>
 </xsl:stylesheet>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/BeanWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/BeanWriter.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/BeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/BeanWriter.java Sat Jul 22 07:32:10 2006
@@ -52,7 +52,7 @@
      * 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
@@ -69,8 +69,8 @@
      * @return Returns String.
      * @throws SchemaCompilationException
      */
-    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf, String fullyQualifiedClassName)
-    throws SchemaCompilationException;
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf)
+            throws SchemaCompilationException;
 
     /**
      * Write a element
@@ -95,4 +95,22 @@
      */
     public String write(XmlSchemaSimpleType simpleType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException;
 
+
+    /**
+     * Registers the mapper package name - this is relevant to languages
+     * that enforce packaging such as Java or C#. May be ignored in other
+     * languages
+     * @param mapperPackageName
+     */
+    public void registerExtensionMapperPackageName(String mapperPackageName);
+
+
+    /**
+     * Write the extensions mapper component - this is relevant to only the OOP languages
+     * and a particular implementation may ignore this
+     * @param metainfArray
+     * @param namespaceToUse
+     * @return
+     */
+    public void writeExtensionMapper(BeanWriterMetaInfoHolder[] metainfArray) throws SchemaCompilationException;
 }

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java Sat Jul 22 07:32:10 2006
@@ -11,7 +11,6 @@
 import org.apache.axis2.schema.util.PrimitiveTypeFinder;
 import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.util.XSLTUtils;
-import org.apache.axis2.util.URLProcessor;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.XSLTTemplateProcessor;
 import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -122,7 +121,7 @@
         try {
             QName qName = element.getQName();
 
-            return process(qName, metainf, typeMap, true, null);
+            return process(qName, metainf, typeMap, true);
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }
@@ -139,13 +138,13 @@
      *
      * @see org.apache.axis2.schema.writer.BeanWriter
      */
-    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf, String fullyQualifiedClassName)
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf)
             throws SchemaCompilationException {
 
         try {
             //determine the package for this type.
             QName qName = complexType.getQName();
-            return process(qName, metainf, typeMap, false, fullyQualifiedClassName);
+            return process(qName, metainf, typeMap, false);
 
         } catch (SchemaCompilationException e) {
             throw e;
@@ -230,8 +229,8 @@
      * @return Returns String.
      * @throws Exception
      */
-    private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap, boolean isElement, String fullyQualifiedClassName) throws Exception {
-
+    private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap, boolean isElement) throws Exception {
+        String fullyQualifiedClassName = metainf.getOwnClassName();
         if (fullyQualifiedClassName == null)
             fullyQualifiedClassName = makeFullyQualifiedClassName(qName);
         String className = fullyQualifiedClassName;
@@ -681,5 +680,23 @@
 
         return typeClassName.substring(typeClassName.lastIndexOf(".")+1, typeClassName.length());
 
+    }
+
+    /**
+     * Keep unimplemented
+     * @see BeanWriter#registerExtensionMapperPackageName(String)
+     * @param mapperPackageName
+     */
+    public void registerExtensionMapperPackageName(String mapperPackageName) {
+        //unimplemented
+    }
+
+    /**
+     * Keep unimplemented
+     * @see BeanWriter#writeExtensionMapper(org.apache.axis2.schema.BeanWriterMetaInfoHolder[])
+     * @param metainfArray
+     */
+    public void writeExtensionMapper(BeanWriterMetaInfoHolder[] metainfArray) throws SchemaCompilationException{
+        //unimplemented
     }
 }

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java Sat Jul 22 07:32:10 2006
@@ -90,6 +90,13 @@
     private boolean isHelperMode = false;
 
     /**
+     * package for the mapping class
+     */
+    private String mappingClassPackage = null;
+
+    public static final String EXTENSION_MAPPER_CLASSNAME = "ExtensionMapper";
+
+    /**
      * Default constructor
      */
     public JavaBeanWriter() {
@@ -151,8 +158,8 @@
             throw new SchemaCompilationException(e);
         } catch (ParserConfigurationException e) {
             throw new SchemaCompilationException(e); // todo need to put
-                                                        // correct error
-                                                        // messages
+            // correct error
+            // messages
         }
     }
 
@@ -164,12 +171,12 @@
      * @throws SchemaCompilationException
      */
     public String write(XmlSchemaElement element, Map typeMap,
-            BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
+                        BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
 
         try {
             QName qName = element.getQName();
 
-            return process(qName, metainf, typeMap, true, null);
+            return process(qName, metainf, typeMap, true);
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }
@@ -189,14 +196,13 @@
      *      java.util.Map, org.apache.axis2.schema.BeanWriterMetaInfoHolder)
      */
     public String write(XmlSchemaComplexType complexType, Map typeMap,
-            BeanWriterMetaInfoHolder metainf, String fullyQualifiedClassName)
+                        BeanWriterMetaInfoHolder metainf)
             throws SchemaCompilationException {
 
         try {
             // determine the package for this type.
             QName qName = complexType.getQName();
-            return process(qName, metainf, typeMap, false,
-                    fullyQualifiedClassName);
+            return process(qName, metainf, typeMap, false);
 
         } catch (SchemaCompilationException e) {
             throw e;
@@ -240,7 +246,7 @@
      *      java.util.Map, org.apache.axis2.schema.BeanWriterMetaInfoHolder)
      */
     public String write(XmlSchemaSimpleType simpleType, Map typeMap,
-            BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
+                        BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
         throw new SchemaCompilationException(SchemaCompilerMessages
                 .getMessage("schema.notimplementedxception"));
     }
@@ -277,14 +283,7 @@
         String namespaceURI = qName.getNamespaceURI();
         String basePackageName;
 
-        if (ns2packageNameMap.containsKey(namespaceURI)) {
-            basePackageName = (String) ns2packageNameMap.get(namespaceURI);
-        } else {
-            basePackageName = URLProcessor.makePackageName(namespaceURI);
-        }
-
-        String packageName = this.packageName == null ? basePackageName
-                : this.packageName + basePackageName;
+        String packageName = getPackage(namespaceURI);
 
         String originalName = qName.getLocalPart();
         String className = makeUniqueJavaClassName(this.namesList, originalName);
@@ -308,6 +307,19 @@
         return fullyqualifiedClassName;
     }
 
+    private String getPackage(String namespaceURI) {
+        String basePackageName;
+        if (ns2packageNameMap.containsKey(namespaceURI)) {
+            basePackageName = (String) ns2packageNameMap.get(namespaceURI);
+        } else {
+            basePackageName = URLProcessor.makePackageName(namespaceURI);
+        }
+
+        String packageName = this.packageName == null ? basePackageName
+                : this.packageName + basePackageName;
+        return packageName;
+    }
+
     /**
      * A util method that holds common code for the complete schema that the
      * generated XML complies to look under other/beanGenerationSchema.xsd
@@ -323,17 +335,17 @@
      * @throws Exception
      */
     private String process(QName qName, BeanWriterMetaInfoHolder metainf,
-            Map typeMap, boolean isElement, String fullyQualifiedClassName)
+                           Map typeMap, boolean isElement)
             throws Exception {
-
+        String fullyQualifiedClassName = metainf.getOwnClassName();
         if (fullyQualifiedClassName == null)
             fullyQualifiedClassName = makeFullyQualifiedClassName(qName);
         String className = fullyQualifiedClassName
                 .substring(1 + fullyQualifiedClassName.lastIndexOf('.'));
         String basePackageName;
         if (fullyQualifiedClassName.lastIndexOf('.') == -1) {// no 'dots' so
-                                                                // the package
-                                                                // is not there
+            // the package
+            // is not there
             basePackageName = "";
         } else {
             basePackageName = fullyQualifiedClassName.substring(0,
@@ -369,11 +381,11 @@
                 // create the file
                 File out = createOutFile(basePackageName, className);
                 // parse with the template and create the files
-   
+
                 if (isHelperMode) {
 
                     XSLTUtils.addAttribute(model, "helperMode", "yes", model.getDocumentElement());
-                    
+
                     // Generate bean classes
                     parse(model, out);
 
@@ -384,6 +396,7 @@
                     parse(model, out);
 
                 } else {
+                    //No helper mode - just generate the classes
                     parse(model, out);
                 }
             }
@@ -411,10 +424,15 @@
      * @return Returns Element.
      * @throws SchemaCompilationException
      */
-    private Element getBeanElement(Document model, String className,
-            String originalName, String packageName, QName qName,
-            boolean isElement, BeanWriterMetaInfoHolder metainf,
-            ArrayList propertyNames, Map typeMap)
+    private Element getBeanElement(Document model,
+                                   String className,
+                                   String originalName,
+                                   String packageName,
+                                   QName qName,
+                                   boolean isElement,
+                                   BeanWriterMetaInfoHolder metainf,
+                                   ArrayList propertyNames,
+                                   Map typeMap)
             throws SchemaCompilationException {
 
         Element rootElt = XSLTUtils.getElement(model, "bean");
@@ -445,7 +463,10 @@
         if (metainf.isExtension()) {
             XSLTUtils.addAttribute(model, "extension", metainf
                     .getExtensionClassName(), rootElt);
+
         }
+        //add the mapper class name
+        XSLTUtils.addAttribute(model, "mapperClass", getFullyQualifiedMapperClassName(), rootElt);
 
         if (metainf.isChoice()) {
             XSLTUtils.addAttribute(model, "choice", "yes", rootElt);
@@ -462,6 +483,7 @@
         // populate all the information
         populateInfo(metainf, model, rootElt, propertyNames, typeMap, false);
 
+
         return rootElt;
     }
 
@@ -475,8 +497,8 @@
      * @throws SchemaCompilationException
      */
     private void populateInfo(BeanWriterMetaInfoHolder metainf, Document model,
-            Element rootElt, ArrayList propertyNames, Map typeMap,
-            boolean isInherited) throws SchemaCompilationException {
+                              Element rootElt, ArrayList propertyNames, Map typeMap,
+                              boolean isInherited) throws SchemaCompilationException {
         if (metainf.getParent() != null) {
             populateInfo(metainf.getParent(), model, rootElt, propertyNames,
                     typeMap, true);
@@ -496,8 +518,8 @@
      * @throws SchemaCompilationException
      */
     private void addPropertyEntries(BeanWriterMetaInfoHolder metainf,
-            Document model, Element rootElt, ArrayList propertyNames,
-            Map typeMap, boolean isInherited) throws SchemaCompilationException {
+                                    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()) {
@@ -611,7 +633,7 @@
         return SchemaCompiler.DEFAULT_CLASS_NAME
                 .equals(javaClassNameForElement)
                 || SchemaCompiler.DEFAULT_CLASS_ARRAY_NAME
-                        .equals(javaClassNameForElement);
+                .equals(javaClassNameForElement);
     }
 
     /**
@@ -757,6 +779,108 @@
 
         return typeClassName.substring(typeClassName.lastIndexOf(".") + 1,
                 typeClassName.length());
+
+    }
+
+    /**
+     * Get the mapper class name - there is going to be only one
+     * mapper class for the whole
+     * @return
+     */
+    private String getFullyQualifiedMapperClassName(){
+        if (wrapClasses || !writeClasses){
+            return EXTENSION_MAPPER_CLASSNAME;
+        }else{
+            return mappingClassPackage + "." +  EXTENSION_MAPPER_CLASSNAME;
+        }
+    }
+
+    /**
+     * Sets the mapping class name of this writer. A mapping class
+     * package set by the options may be overridden at the this point
+     * @param mapperPackageName
+     */
+    public void registerExtensionMapperPackageName(String mapperPackageName) {
+        this.mappingClassPackage = mapperPackageName;
+    }
+
+    /**
+     * Write the extension classes - this is needed to process
+     * the hierarchy of classes
+     * @param metainfArray
+     * @return
+     */
+    public void writeExtensionMapper(BeanWriterMetaInfoHolder[] metainfArray) throws SchemaCompilationException{
+        //generate the element
+        try {
+
+
+            String mapperClassName = getFullyQualifiedMapperClassName();
+
+            Document model =XSLTUtils.getDocument();
+            Element rootElt = XSLTUtils.getElement(model, "mapper");
+            String mapperName = mapperClassName.substring(mapperClassName.lastIndexOf(".") + 1);
+            XSLTUtils.addAttribute(model, "name",mapperName, rootElt);
+            String basePackageName = "";
+            if (mapperClassName.indexOf(".")!=-1){
+                basePackageName = mapperClassName.substring(0, mapperClassName.lastIndexOf("."));
+                XSLTUtils.addAttribute(model, "package",basePackageName, rootElt);
+            }else {
+                XSLTUtils.addAttribute(model, "package","", rootElt);
+            }
+
+            if (!wrapClasses) {
+                XSLTUtils.addAttribute(model, "unwrapped", "yes", rootElt);
+            }
+
+            if (!writeClasses) {
+                XSLTUtils.addAttribute(model, "skip-write", "yes", rootElt);
+            }
+
+
+            for (int i = 0; i < metainfArray.length; i++) {
+                QName ownQname = metainfArray[i].getOwnQname();
+                String className = metainfArray[i].getOwnClassName();
+                //do  not add when the qname is not availble
+                if (ownQname!=null){
+                    Element typeChild = XSLTUtils.addChildElement(model,"type",rootElt);
+                    XSLTUtils.addAttribute(model, "nsuri", ownQname.getNamespaceURI(), typeChild);
+                    XSLTUtils.addAttribute(model, "classname", className==null?"":className, typeChild);
+                    XSLTUtils.addAttribute(model, "shortname", ownQname==null?"":
+                            ownQname.getLocalPart(), typeChild);
+                }
+            }
+
+            model.appendChild(rootElt);
+
+            if (!templateLoaded){
+                loadTemplate();
+            }
+
+            if (wrapClasses) {
+                //add to the global wrapped document
+                globalWrappedDocument.getDocumentElement().appendChild(rootElt);
+            } else {
+                if (writeClasses) {
+                    // create the file
+                    File out = createOutFile(basePackageName, mapperName);
+                    // parse with the template and create the files
+                    parse(model, out);
+
+                }
+
+                // add the model to the model map
+                modelMap.put(new QName(mapperName), model);
+            }
+
+        } catch (ParserConfigurationException e) {
+            throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.docuement.error"),e);
+        } catch (Exception e){
+            e.printStackTrace();
+            throw new SchemaCompilationException(e);
+        }
+
+
 
     }
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java Sat Jul 22 07:32:10 2006
@@ -1161,6 +1161,7 @@
             Object o = objectIterator.next();
 
             if (o instanceof Document) {
+                //we cannot have an empty document
                 root.appendChild(doc.importNode(((Document) o).getDocumentElement(), true));
             } else {
 

Modified: webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/ant/AntCodegenTask.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/ant/AntCodegenTask.java?rev=424585&r1=424584&r2=424585&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/ant/AntCodegenTask.java (original)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/ant/AntCodegenTask.java Sat Jul 22 07:32:10 2006
@@ -230,7 +230,7 @@
                         CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION,
                         new String[]{portName}));
         // set the namespaces
-         optionMap.put(
+        optionMap.put(
                 CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
                 new CommandLineOption(
                         CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
@@ -252,18 +252,16 @@
 
     public void execute() throws BuildException {
         try {
-            /**
-             * This needs the ClassLoader we use to load the task have all the dependancies set, hope that
+            /*
+             * This needs the ClassLoader we use to load the task
+             * have all the dependancies set, hope that
              * is ok for now
-             *
-             * todo look into this further!!!!!
              */
 
-
             AntClassLoader cl = new AntClassLoader(
                     getClass().getClassLoader(),
                     getProject(),
-					classpath == null ? createClasspath() : classpath,
+                    classpath == null ? createClasspath() : classpath,
                     false);
 
             Thread.currentThread().setContextClassLoader(cl);
@@ -330,14 +328,6 @@
     public void setGenerateServiceXml(boolean generateServiceXml) {
         this.generateServiceXml = generateServiceXml;
     }
-
-//    public static void main(String[] args) {
-//        AntCodegenTask task = new AntCodegenTask();
-//        task.setWSDLFileName(
-//                "modules/samples/test-resources/wsdl/compound2.wsdl");
-//        task.setOutput("temp");
-//        task.execute();
-//    }
 
     /**
      * @return Returns Path.



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


Mime
View raw message