You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2005/10/31 11:41:04 UTC

svn commit: r329794 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2: databinding/schema/ databinding/schema/typemap/ databinding/schema/util/ databinding/schema/writer/ wsdl/template/java/

Author: ajith
Date: Mon Oct 31 02:40:28 2005
New Revision: 329794

URL: http://svn.apache.org/viewcvs?rev=329794&view=rev
Log:
1. Refactored the templates/writers/typemappers by moving them to different packages
2. Moved the important parameters to a property file

Now the Schema writer is fully configurable and extensible, even to other languages

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/schema-compile.properties
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/JavaTypeMap.java
      - copied, changed from r328780, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/TypeMap.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/SchemaPropertyLoader.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/
    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
      - copied, changed from r328780, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java
Removed:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl

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=329794&r1=329793&r2=329794&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 Mon Oct 31 02:40:28 2005
@@ -2,6 +2,10 @@
 
 import org.apache.ws.commons.schema.*;
 import org.apache.axis2.om.OMElement;
+import org.apache.axis2.databinding.schema.typemap.JavaTypeMap;
+import org.apache.axis2.databinding.schema.writer.JavaBeanWriter;
+import org.apache.axis2.databinding.schema.writer.BeanWriter;
+import org.apache.axis2.databinding.schema.util.SchemaPropertyLoader;
 
 import javax.xml.namespace.QName;
 import java.util.*;
@@ -34,9 +38,10 @@
     private ArrayList processedElementList;
 
 
-    private JavaBeanWriter writer;
+    private BeanWriter writer=null;
+
+    private Map baseSchemaTypeMap =null;
 
-    private Map baseSchemaTypeMap = TypeMap.getTypeMap();
     private static final String ANY_ELEMENT_FIELD_NAME = "extraElements";
     private static final String EXTRA_ATTRIBUTE_FIELD_NAME = "extraAttributes";
 
@@ -63,7 +68,12 @@
             this.processedElementList = new ArrayList();
             this.processedAnonymousComplexTypesMap = new HashMap();
 
-            this.writer = new JavaBeanWriter(this.options.getOutputLocation());
+            //load the writer
+            this.writer = SchemaPropertyLoader.getBeanWriterInstance();
+            this.writer.init(this.options.getOutputLocation());
+
+            //laod the base types
+            baseSchemaTypeMap =SchemaPropertyLoader.getTypeMapperInstance().getTypeMap();
 
         } catch (IOException e) {
             throw new SchemaCompilationException(e);
@@ -190,7 +200,7 @@
             //pass through. We'll be iterating through the elements writing them
             //later
         }
-        
+
         //There can be instances where the SchemaType is null but the schemaTypeName is not
         //this specifically happens with xsd:anyType.
         if (!isOuter){

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/schema-compile.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/schema-compile.properties?rev=329794&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/schema-compile.properties (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/schema-compile.properties Mon Oct 31 02:40:28 2005
@@ -0,0 +1,17 @@
+###############################################################################
+##########################Schema Compiler properties   ########################
+###############################################################################
+# The bean writer class
+# The bean writer is the class used by the schema compiler to write the beans
+# and should implement the org.apache.axis2.databinding.schema.writer.BeanWriter
+# inteface
+schema.bean.writer.class=org.apache.axis2.databinding.schema.writer.JavaBeanWriter
+#
+# bean writer template
+# The bean writers template is it's own responsibilty. (A bean writer provider
+# may choose not to use a template at all!) However the property loader will
+# load the followiing template (reference) and provide it in case the bean writer is
+# not hard bound to a template
+schema.bean.writer.template=/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
+# The type map to be used by the schema compiler
+schema.bean.typemap=org.apache.axis2.databinding.schema.typemap.JavaTypeMap
\ No newline at end of file

Copied: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/JavaTypeMap.java (from r328780, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/JavaTypeMap.java?p2=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/JavaTypeMap.java&p1=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java&r1=328780&r2=329794&rev=329794&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/JavaTypeMap.java Mon Oct 31 02:40:28 2005
@@ -1,6 +1,7 @@
-package org.apache.axis2.databinding.schema;
+package org.apache.axis2.databinding.schema.typemap;
 
 import org.apache.axis2.om.OMElement;
+import org.apache.axis2.databinding.schema.SchemaConstants;
 
 import javax.xml.namespace.QName;
 import java.util.Map;
@@ -21,9 +22,9 @@
  * limitations under the License.
  */
 
-public class TypeMap {
+public class JavaTypeMap implements TypeMap {
     
-    public static Map getTypeMap() {
+    public Map getTypeMap() {
         return typeMap;
     }
 

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/TypeMap.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/TypeMap.java?rev=329794&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/TypeMap.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/typemap/TypeMap.java Mon Oct 31 02:40:28 2005
@@ -0,0 +1,26 @@
+package org.apache.axis2.databinding.schema.typemap;
+
+import java.util.Map;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This is a  typemapper for the bean writer
+ */
+public interface TypeMap {
+
+    public Map getTypeMap();
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/SchemaPropertyLoader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/SchemaPropertyLoader.java?rev=329794&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/SchemaPropertyLoader.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/util/SchemaPropertyLoader.java Mon Oct 31 02:40:28 2005
@@ -0,0 +1,69 @@
+package org.apache.axis2.databinding.schema.util;
+
+import org.apache.axis2.databinding.schema.writer.BeanWriter;
+import org.apache.axis2.databinding.schema.typemap.TypeMap;
+
+import java.util.Properties;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class SchemaPropertyLoader {
+    private  static  String beanTemplate = null;
+    private  static  BeanWriter beanWriterInstance = null;
+    private  static  TypeMap typeMapperInstance = null;
+
+    private static final String SCHEMA_COMPILER_PROPERTIES = "/org/apache/axis2/databinding/schema/schema-compile.properties";
+    private static final String BEAN_WRITER_KEY = "schema.bean.writer.class";
+    private static final String BEAN_WRITER_TEMPLATE_KEY = "schema.bean.writer.template";
+    private static final String BEAN_WRITER_TYPEMAP_KEY = "schema.bean.typemap";
+
+    static{
+        try {
+            //load the properties
+            Properties props = new Properties();
+            props.load(Object.class.getResourceAsStream(SCHEMA_COMPILER_PROPERTIES));
+
+            String beanWriterClassName =  props.getProperty(BEAN_WRITER_KEY);
+            if (beanWriterClassName!=null){
+                 beanWriterInstance = (BeanWriter)Class.forName(beanWriterClassName).newInstance();
+            }
+
+            String typeMapperClassName =  props.getProperty(BEAN_WRITER_TYPEMAP_KEY);
+            if (typeMapperClassName !=null){
+                 typeMapperInstance = (TypeMap)Class.forName(typeMapperClassName).newInstance();
+            }
+
+            beanTemplate = props.getProperty(BEAN_WRITER_TEMPLATE_KEY);
+            
+        } catch (Exception e) {
+           throw new RuntimeException(e);
+        }
+
+
+    }
+
+    public static String getBeanTemplate() {
+        return beanTemplate;
+    }
+
+    public static BeanWriter getBeanWriterInstance() {
+        return beanWriterInstance;
+    }
+
+    public static TypeMap getTypeMapperInstance() {
+        return typeMapperInstance;
+    }
+}

Added: 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=329794&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/BeanWriter.java Mon Oct 31 02:40:28 2005
@@ -0,0 +1,67 @@
+package org.apache.axis2.databinding.schema.writer;
+
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.axis2.databinding.schema.BeanWriterMetaInfoHolder;
+import org.apache.axis2.databinding.schema.SchemaCompilationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface BeanWriter {
+
+    /**
+     * Initialize this writer
+     * @param rootDir
+     * @throws IOException
+     */
+    public void init(File rootDir) throws IOException ;
+
+    /**
+     * Write a complex type
+     * @param complexType
+     * @param typeMap
+     * @param metainf
+     * @return
+     * @throws SchemaCompilationException
+     */
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException ;
+
+    /**
+     * Write a element
+     * @param element
+     * @param typeMap
+     * @param metainf
+     * @return
+     * @throws SchemaCompilationException
+     */
+    public String write(XmlSchemaElement element, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException;
+
+    /**
+     * Write a simple type
+     * @param simpleType
+     * @param typeMap
+     * @param metainf
+     * @return
+     * @throws SchemaCompilationException
+     */
+    public String write(XmlSchemaSimpleType simpleType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException;
+
+}

Copied: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java (from r328780, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java?p2=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java&p1=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java&r1=328780&r2=329794&rev=329794&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/writer/JavaBeanWriter.java Mon Oct 31 02:40:28 2005
@@ -1,8 +1,12 @@
-package org.apache.axis2.databinding.schema;
+package org.apache.axis2.databinding.schema.writer;
 
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 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.util.SchemaPropertyLoader;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -12,7 +16,6 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.stream.StreamSource;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
@@ -34,9 +37,9 @@
  * limitations under the License.
  */
 
-public class JavaBeanWriter {
+public class JavaBeanWriter implements BeanWriter{
 
-    private static final String JAVA_BEAN_TEMPLATE = "/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl";
+    private String javaBeanTemplateName = null;
     private boolean templateLoaded = false;
     private Templates templateCache;
 
@@ -47,8 +50,14 @@
 
     private File rootDir;
 
-    public JavaBeanWriter(File rootDir) throws IOException {
-        if (rootDir ==null){
+    /**
+     * Default constructor
+     */
+    public JavaBeanWriter(){
+    }
+
+    public void init(File rootDir) throws IOException{
+         if (rootDir ==null){
             this.rootDir = new File(".");
         }else if (!rootDir.isDirectory()){
             throw new IOException("Root location needs to be a directory!");
@@ -57,16 +66,16 @@
         }
 
         namesList = new ArrayList();
+        javaBeanTemplateName = SchemaPropertyLoader.getBeanTemplate();
     }
-
     /**
      *
      * @param complexType
      * @param typeMap
      * @param metainf
-     * @throws SchemaCompilationException
+     * @throws org.apache.axis2.databinding.schema.SchemaCompilationException
      */
-    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException{
+    public String write(XmlSchemaComplexType complexType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
 
         try {
             //determine the package for this type.
@@ -198,6 +207,10 @@
         return packageName+"."+className;
     }
 
+    public String write(XmlSchemaSimpleType simpleType, Map typeMap, BeanWriterMetaInfoHolder metainf) throws SchemaCompilationException {
+        throw new SchemaCompilationException("Not implemented yet");
+    }
+
     /**
      *
      * @param listOfNames
@@ -249,7 +262,7 @@
         //first get the language specific property map
         Class clazz = this.getClass();
         InputStream xslStream;
-        String templateName = JAVA_BEAN_TEMPLATE;
+        String templateName = javaBeanTemplateName;
         if (templateName!=null){
             try {
                 xslStream = clazz.getResourceAsStream(templateName);

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?rev=329794&r1=329793&r2=329794&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl Mon Oct 31 02:40:28 2005
@@ -10,6 +10,9 @@
     <xsl:variable name="soapVersion"><xsl:value-of select="@soap-version"/></xsl:variable>
     package <xsl:value-of select="$package"/>;
 
+        <!-- Put the MTOM enable flag -->
+
+
     /*
      *  Auto generated java implementation by the Axis code generator
     */