You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/12/01 19:19:24 UTC

svn commit: r350293 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2: databinding/schema/ databinding/schema/writer/ wsdl/codegen/ wsdl/codegen/emitter/ wsdl/codegen/extension/ wsdl/codegen/writer/ wsdl/template/general/

Author: ajith
Date: Thu Dec  1 10:19:09 2005
New Revision: 350293

URL: http://svn.apache.org/viewcvs?rev=350293&view=rev
Log:
1. Added a mechanism to set the package name in the generated ADB code.
2. Updated SimpleDBExtension.java to add the 'adb' prefix into the generated code.
3. Updated the ant build write class to write a custom antbuild for ADB stuff as well
   * Added the template for this new ant build

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/CompilerOptions.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/AntBuildWriter.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/CompilerOptions.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/CompilerOptions.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/CompilerOptions.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/CompilerOptions.java Thu Dec  1 10:19:09 2005
@@ -1,6 +1,8 @@
 package org.apache.axis2.databinding.schema;
 
 import java.io.File;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -29,6 +31,23 @@
      * Generated output file
      */
     File outputLocation;
+    String packageName=null;
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public CompilerOptions setPackageName(String packageName) {
+        //validate the package name
+        //should be ***.***.***. type value
+        if (packageName!=null && testValue(packageName)){
+           this.packageName = packageName;
+        }else{
+            throw new RuntimeException("Unsupported value!");
+        }
+
+        return this;
+    }
 
     public File getOutputLocation() {
         return outputLocation;
@@ -39,4 +58,9 @@
         return this;
     }
 
+    private boolean testValue(String wordToMatch){
+         Pattern pat = Pattern.compile("^(\\w+\\.)+$");
+         Matcher m= pat.matcher(wordToMatch);
+         return m.matches();
+    }
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java Thu Dec  1 10:19:09 2005
@@ -75,7 +75,7 @@
 
             //load the writer
             this.writer = SchemaPropertyLoader.getBeanWriterInstance();
-            this.writer.init(this.options.getOutputLocation());
+            this.writer.init(this.options);
 
             //laod the base types
             baseSchemaTypeMap =SchemaPropertyLoader.getTypeMapperInstance().getTypeMap();
@@ -284,7 +284,7 @@
             }
         }else if (schemaType instanceof XmlSchemaSimpleType){
             //process simple type
-            processSimpleSchemaType((XmlSchemaSimpleType)schemaType);
+            processSimpleSchemaType(xsElt,(XmlSchemaSimpleType)schemaType);
         }
     }
 
@@ -520,7 +520,7 @@
      * Handle the simple content
      * @param simpleType
      */
-    private void processSimpleSchemaType(XmlSchemaSimpleType simpleType){
+    private void processSimpleSchemaType(XmlSchemaElement xsElt,XmlSchemaSimpleType simpleType){
         // handle the restriction
         XmlSchemaSimpleTypeContent content = simpleType.getContent();
         if (content!=null){
@@ -537,9 +537,13 @@
                     this.changedTypeMap.put(simpleType.getQName(),baseTypeName);
                 }else{
                     //recurse
+                    if (restriction.getBaseType()!= null){
+                        processSimpleSchemaType(xsElt, restriction.getBaseType());
+                    }
                     //processSimpleSchemaType(xsElt, new XmlSchemaSimpleType());
                 }
             }
+            //We still don't handle UNIONS of  simple types
         }
 
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java Thu Dec  1 10:19:09 2005
@@ -5,6 +5,7 @@
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.axis2.databinding.schema.BeanWriterMetaInfoHolder;
 import org.apache.axis2.databinding.schema.SchemaCompilationException;
+import org.apache.axis2.databinding.schema.CompilerOptions;
 
 import java.io.File;
 import java.io.IOException;
@@ -37,6 +38,15 @@
      * @throws IOException
      */
     public void init(File rootDir) throws IOException ;
+
+    /**
+     *  Init the write with compiler options
+     * @param options
+     * @throws IOException
+     */
+    public void init(CompilerOptions options) throws IOException ;
+
+
 
     /**
      * Write a complex type

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java Thu Dec  1 10:19:09 2005
@@ -6,6 +6,7 @@
 import org.apache.axis2.util.*;
 import org.apache.axis2.databinding.schema.BeanWriterMetaInfoHolder;
 import org.apache.axis2.databinding.schema.SchemaCompilationException;
+import org.apache.axis2.databinding.schema.CompilerOptions;
 import org.apache.axis2.databinding.schema.util.SchemaPropertyLoader;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -49,6 +50,8 @@
     private List namesList;
     private static int count = 0;
 
+    private String packageName=null;
+
 
 
     private File rootDir;
@@ -59,6 +62,11 @@
     public JavaBeanWriter(){
     }
 
+    public void init(CompilerOptions options) throws IOException {
+        init(options.getOutputLocation());
+        this.packageName = options.getPackageName();
+    }
+
     /**
      * @see BeanWriter#init(java.io.File)
      * @param rootDir
@@ -111,7 +119,14 @@
      * @throws Exception
      */
     private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map typeMap, boolean isElement) throws Exception {
-        String packageName = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
+
+        String nameSpaceFromURL = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
+        String packageName = this.packageName==null?
+                     nameSpaceFromURL :
+                     this.packageName +nameSpaceFromURL;
+
+        
+
         String originalName = qName.getLocalPart();
         String className = getNonConflictingName(this.namesList,originalName);
 
@@ -168,7 +183,7 @@
             XSLTUtils.addAttribute(model,"name",xmlName,property);
             XSLTUtils.addAttribute(model,"javaname",javaName,property);
             String javaClassNameForElement = metainf.getClassNameForQName(name);
-            
+
             String shortTypeName = "";
             if (metainf.getSchemaQNameForQName(name)!=null){
                 shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
@@ -270,7 +285,6 @@
     public String write(XmlSchemaElement element, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException{
 
         try {
-            //determine the package for this type.
             QName qName = element.getQName();
             return process(qName, metainf, typeMap, true);
         } catch (Exception e) {

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties Thu Dec  1 10:19:09 2005
@@ -48,7 +48,9 @@
 java.dbsupporter.adb.template=org.apache.axis2.wsdl.codegen.writer.DatabindingSupportClassWriter,/org/apache/axis2/wsdl/template/java/ADBSupporterTemplate.xsl
 ###########
 java.dbsupporter.default.template=org.apache.axis2.wsdl.codegen.writer.DatabindingSupportClassWriter,/org/apache/axis2/wsdl/template/java/DefaultDataBindingSupporterTemplate.xsl
-java.antbuild.template=org.apache.axis2.wsdl.codegen.writer.AntBuildWriter,/org/apache/axis2/wsdl/template/general/xmlbeansAntBuildTemplate.xsl
+#
+java.antbuild.xmlbeans.template=org.apache.axis2.wsdl.codegen.writer.AntBuildWriter,/org/apache/axis2/wsdl/template/general/xmlbeansAntBuildTemplate.xsl
+java.antbuild.adb.template=org.apache.axis2.wsdl.codegen.writer.AntBuildWriter,/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl
 # file extension for generated files from this language
 java.filename.extension=java
 #

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java Thu Dec  1 10:19:09 2005
@@ -420,9 +420,10 @@
                 axisInterface, axisBinding);
         
 
-        ClassWriter antBuildWriter = new AntBuildWriter(
+        AntBuildWriter antBuildWriter = new AntBuildWriter(
                 this.configuration.getOutputLocation(),
                 this.configuration.getOutputLanguage());
+        antBuildWriter.setDatabindingFramework(this.configuration.getDatabindingType());
         writeClass(skeletonModel, antBuildWriter);
     }
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java Thu Dec  1 10:19:09 2005
@@ -42,6 +42,8 @@
  *
  */
 public class SimpleDBExtension extends AbstractCodeGenerationExtension {
+    public static final String ADB_PACKAGE_NAME_PREFIX = "adb.";
+
     public void init(CodeGenConfiguration configuration) {
         this.configuration = configuration;
     }
@@ -95,6 +97,8 @@
             }
             //call the schema compiler
             CompilerOptions options = new CompilerOptions().setOutputLocation(configuration.getOutputLocation());
+            options.setPackageName(ADB_PACKAGE_NAME_PREFIX);
+
             SchemaCompiler schemaCompiler = new SchemaCompiler(options);
             schemaCompiler
                     .compile(xmlSchemaTypeVector);

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/AntBuildWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/AntBuildWriter.java?rev=350293&r1=350292&r2=350293&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/AntBuildWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/AntBuildWriter.java Thu Dec  1 10:19:09 2005
@@ -1,9 +1,12 @@
 package org.apache.axis2.wsdl.codegen.writer;
 
 import org.apache.axis2.util.FileWriter;
+import org.apache.axis2.wsdl.codegen.XSLTConstants;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Map;
+import java.util.Iterator;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -21,6 +24,9 @@
  */
 
 public class AntBuildWriter extends ClassWriter{
+
+    int databindingFramework = 0;
+
      public AntBuildWriter(String outputFileLocation) {
         this.outputFileLocation = new File(outputFileLocation);
     }
@@ -30,7 +36,9 @@
         this.language = language;
     }
 
-
+    public void setDatabindingFramework(int databindingFramework) {
+        this.databindingFramework = databindingFramework;
+    }
 
     public void createOutFile(String packageName, String fileName) throws Exception {
         File outputFile = FileWriter.createClassFile(outputFileLocation,
@@ -42,5 +50,49 @@
         if (!fileExists){
             this.stream = new FileOutputStream(outputFile);
         }
+    }
+
+     //overridden to get the correct behavior
+    protected String findTemplate(Map languageSpecificPropertyMap) {
+        String ownClazzName =  this.getClass().getName();
+        String key;
+        String propertyValue;
+        String templateName = null;
+        Iterator keys = languageSpecificPropertyMap.keySet().iterator();
+        String databindString;
+
+        //set the correct databinding type string
+        switch(this.databindingFramework)  {
+            case XSLTConstants.DataBindingTypes.XML_BEANS:
+                databindString = "xmlbeans";
+                break;
+            case XSLTConstants.DataBindingTypes.JAXB:
+                databindString = "jaxb";
+                break;
+            case XSLTConstants.DataBindingTypes.ADB:
+                databindString = "adb";
+                break;
+            default:
+                databindString = "default";
+        }
+
+        while (keys.hasNext()) {
+            //check for template entries
+            key = keys.next().toString();
+            if (key.endsWith(TEMPLATE_SUFFIX)){
+                // check if the class name is there
+                propertyValue = languageSpecificPropertyMap.get(key).toString();
+                if (propertyValue.startsWith(ownClazzName)){
+                    if (key.indexOf(databindString)!=-1){
+                        templateName = propertyValue.substring(propertyValue.indexOf(SEPERATOR_STRING)+1) ;
+                        break;
+                    }
+                }
+            }
+
+        }
+
+        return templateName;
+
     }
 }

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl?rev=350293&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/adbAntBuildTemplate.xsl Thu Dec  1 10:19:09 2005
@@ -0,0 +1,133 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
+    <xsl:template match="/ant">
+        <xsl:variable name="package"><xsl:value-of select="@package"/></xsl:variable>
+
+        <project basedir="." default="move.files">
+            <xsl:comment>Auto generated ant build file</xsl:comment>
+            <property name="src">
+                <xsl:attribute name="value">${basedir}\src</xsl:attribute>
+            </property>
+            <property name="classes">
+                <xsl:attribute name="value">${basedir}\classes</xsl:attribute>
+            </property>
+            <property name="bin">
+                <xsl:attribute name="value">${basedir}\bin</xsl:attribute>
+            </property>
+            <property name="other">
+                <xsl:attribute name="value">${basedir}\other</xsl:attribute>
+            </property>
+
+            <!--<property name="xbeans.available" value=""></property>
+            <property name="stax.available" value=""></property>
+            <property name="axis2.available" value=""></property>-->
+            <property name="jars.ok" value=""></property>
+            <property name="mappings.folder.name" value="Mapping"></property>
+            <property name="schemas.folder.name" value="schemas"></property>
+
+
+            <target name="move.files" depends="init">
+                <xsl:comment>first move the generated packages</xsl:comment>
+                <move>
+                    <xsl:attribute name="todir">${src}</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${basedir}</xsl:attribute>
+                        <xsl:attribute name="includes"><xsl:value-of select="$package"></xsl:value-of>\**\</xsl:attribute>
+                    </fileset>
+
+                </move>
+                <xsl:comment>move the adb stuff to the src too</xsl:comment>
+                <move>
+                    <xsl:attribute name="todir">${src}</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${basedir}</xsl:attribute>
+                        <xsl:attribute name="includes">adb\**\</xsl:attribute>
+                    </fileset>
+                </move>
+                <xsl:comment>move the rest of the stuff to the other folder</xsl:comment>
+                <move>
+                    <xsl:attribute name="todir">${other}</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${basedir}</xsl:attribute>
+                        <xsl:attribute name="includes">${mappings.folder.name}\**\</xsl:attribute>
+                    </fileset>
+                </move>
+                <move>
+                    <xsl:attribute name="todir">${other}</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${basedir}</xsl:attribute>
+                        <xsl:attribute name="includes">${schemas.folder.name}\**\</xsl:attribute>
+                    </fileset>
+                </move>
+
+            </target>
+
+            <target name="init">
+                <mkdir>
+                    <xsl:attribute name="dir">${src}</xsl:attribute>
+                </mkdir>
+                <mkdir>
+                    <xsl:attribute name="dir">${classes}</xsl:attribute>
+                </mkdir>
+                <mkdir>
+                    <xsl:attribute name="dir">${bin}</xsl:attribute>
+                </mkdir>
+
+            </target>
+
+            <target name="pre.compile.test" depends="move.files">
+                <xsl:comment>Test the classpath for the availability of necesary classes</xsl:comment>
+
+                <available classname="javax.xml.stream.XMLStreamReader" property="stax.available"/>
+                <available classname="org.apache.axis2.engine.AxisEngine" property="axis2.available"/>
+                <condition property="jars.ok" >
+                    <and>
+                        <isset property="xbeans.available"/>
+                        <isset property="stax.available"/>
+                        <isset property="axis2.available"/>
+                    </and>
+                </condition>
+
+                <xsl:comment>Print out the availabilities</xsl:comment>
+                <echo>
+                     <xsl:attribute name="message">Stax Availability= ${stax.available}</xsl:attribute>
+                </echo>
+                <echo>
+                     <xsl:attribute name="message">Axis2 Availability= ${axis2.available}</xsl:attribute>
+                </echo>
+
+            </target>
+
+            <target name="compile.all" depends="pre.compile.test">
+                <xsl:attribute name="if">${jars.ok}</xsl:attribute>
+                <javac>
+                    <xsl:attribute name="destdir">${classes}</xsl:attribute>
+                    <xsl:attribute name="srcdir">${src}</xsl:attribute>
+                    <classpath>
+                        <xsl:attribute name="location">${bin}\${xbeans.packaged.jar.name}</xsl:attribute>
+                    </classpath>
+                    <classpath>
+                        <xsl:attribute name="location">${java.class.path}</xsl:attribute>
+                    </classpath>
+                </javac>
+            </target>
+
+            <target name="echo.classpath.problem" depends="pre.compile.test">
+                <xsl:attribute name="unless">${jars.ok}</xsl:attribute>
+                <echo message="The class path is not set right!
+                               Please make sure the following classes are in the classpath
+                               1. XmlBeans
+                               2. Stax
+                               3. Axis2
+                "></echo>
+            </target>
+            <target name="jar.all" depends="compile.all,echo.classpath.problem">
+                <xsl:attribute name="if">${jars.ok}</xsl:attribute>
+                <jar>
+                    <xsl:attribute name="basedir">${classes}</xsl:attribute>
+                    <xsl:attribute name="destfile">${bin}</xsl:attribute>
+                </jar>
+            </target>
+        </project>
+    </xsl:template>
+</xsl:stylesheet>