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/10 16:10:37 UTC

svn commit: r312658 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/schema/ src/org/apache/axis2/databinding/schema/template/ src/org/apache/axis2/util/ src/org/apache/axis2/wsdl/codegen/ src/org/apache/axis2/wsdl/c...

Author: ajith
Date: Mon Oct 10 07:09:58 2005
New Revision: 312658

URL: http://svn.apache.org/viewcvs?rev=312658&view=rev
Log:
1. Completed (Half!) the schema compiler. Now the schema compiler can handle complextypes with sequences and generate beans.
2. Moved some utils up to the org/apache/axis2/wsdl/util/ package.
3. Fixed an old error in the MultiLanguageClientEmitter.java. (I wonder how it survived all this long with the flawed code!)
4. Refactored some methods in the ClassWriter.java

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/Constants.java
    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
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java   (contents, props changed)
      - copied, changed from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/FileWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java   (contents, props changed)
      - copied, changed from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/URLProcessor.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java   (contents, props changed)
      - copied, changed from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/XSLTTemplateProcessor.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTUtils.java
Removed:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/FileWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/URLProcessor.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/XSLTTemplateProcessor.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/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/PackageFinder.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ClassWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ServiceXMLWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/TestServiceXMLWriter.java
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/Constants.java?rev=312658&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/Constants.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/Constants.java Mon Oct 10 07:09:58 2005
@@ -0,0 +1,41 @@
+package org.apache.axis2.databinding.schema;
+
+import javax.xml.namespace.QName;
+/*
+ * 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 Constants{
+    public static final String URI_DEFAULT_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+    public static final QName XSD_STRING = new QName(URI_DEFAULT_SCHEMA_XSD, "string");
+    public static final QName XSD_BOOLEAN = new QName(URI_DEFAULT_SCHEMA_XSD, "boolean");
+    public static final QName XSD_DOUBLE = new QName(URI_DEFAULT_SCHEMA_XSD, "double");
+    public static final QName XSD_FLOAT = new QName(URI_DEFAULT_SCHEMA_XSD, "float");
+    public static final QName XSD_INT = new QName(URI_DEFAULT_SCHEMA_XSD, "int");
+    public static final QName XSD_INTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "integer");
+    public static final QName XSD_LONG = new QName(URI_DEFAULT_SCHEMA_XSD, "long");
+    public static final QName XSD_SHORT = new QName(URI_DEFAULT_SCHEMA_XSD, "short");
+    public static final QName XSD_BYTE = new QName(URI_DEFAULT_SCHEMA_XSD, "byte");
+    public static final QName XSD_DECIMAL = new QName(URI_DEFAULT_SCHEMA_XSD, "decimal");
+    public static final QName XSD_BASE64 = new QName(URI_DEFAULT_SCHEMA_XSD, "base64Binary");
+    public static final QName XSD_HEXBIN = new QName(URI_DEFAULT_SCHEMA_XSD, "hexBinary");
+    public static final QName XSD_ANYSIMPLETYPE = new QName(URI_DEFAULT_SCHEMA_XSD, "anySimpleType");
+    public static final QName XSD_ANYTYPE = new QName(URI_DEFAULT_SCHEMA_XSD, "anyType");
+    public static final QName XSD_ANY = new QName(URI_DEFAULT_SCHEMA_XSD, "any");
+    public static final QName XSD_QNAME = new QName(URI_DEFAULT_SCHEMA_XSD, "QName");
+    public static final QName XSD_DATETIME = new QName(URI_DEFAULT_SCHEMA_XSD, "dateTime");
+    public static final QName XSD_DATE = new QName(URI_DEFAULT_SCHEMA_XSD, "date");
+    public static final QName XSD_TIME = new QName(URI_DEFAULT_SCHEMA_XSD, "time");
+}
+

Added: 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/JavaBeanWriter.java?rev=312658&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/JavaBeanWriter.java Mon Oct 10 07:09:58 2005
@@ -0,0 +1,162 @@
+package org.apache.axis2.databinding.schema;
+
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.axis2.util.FileWriter;
+import org.apache.axis2.util.URLProcessor;
+import org.apache.axis2.util.XSLTUtils;
+import org.apache.axis2.util.XSLTTemplateProcessor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Templates;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.util.Map;
+import java.util.Iterator;
+import java.io.*;
+
+/*
+ * 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 JavaBeanWriter {
+
+    private static final String JAVA_BEAN_TEMPLATE = "/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl";
+    private boolean templateLoaded = false;
+    private Templates templateCache;
+
+
+    private File rootDir;
+
+    public JavaBeanWriter(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!");
+        } else{
+            this.rootDir = rootDir;
+        }
+
+    }
+
+    public void write(XmlSchemaComplexType complexType, Map typeMap,Map currentTypeMap) throws SchemaCompilationException{
+
+        try {
+            //determine the package for this type.
+            QName qName = complexType.getQName();
+            String packageName = URLProcessor.getNameSpaceFromURL(qName.getNamespaceURI());
+            String className = qName.getLocalPart();
+
+            if (!templateLoaded){
+                loadTemplate();
+            }
+
+            //create the model
+            Document model= XSLTUtils.getDocument();
+
+            //make the XML
+            Element rootElt = XSLTUtils.addChildElement(model,"bean",model);
+            XSLTUtils.addAttribute(model,"name",className,rootElt);
+            XSLTUtils.addAttribute(model,"package",packageName,rootElt);
+            // go in the loop and add the part elements
+            if (currentTypeMap != null && !currentTypeMap.isEmpty()){
+
+                Iterator it = currentTypeMap.keySet().iterator();
+                QName name;
+                while (it.hasNext()) {
+                    Element property = XSLTUtils.addChildElement(model,"property",rootElt);
+                    name = (QName)it.next();
+                    XSLTUtils.addAttribute(model,"name",name.getLocalPart(),property);
+                    XSLTUtils.addAttribute(model,"type",currentTypeMap.get(name).toString(),property);
+
+                }
+            }
+            //create the file
+            OutputStream out = createOutFile(packageName,className);
+            //parse with the template and create the files
+            parse(model,out);
+        } catch (Exception e) {
+            throw new SchemaCompilationException(e);
+        }
+
+
+    }
+
+
+
+    /** A bit of code from the code generator. We are better off using the template
+     * engines and such stuff that's already there. But the class writers are hard to be
+     * reused so some code needs to be repeated
+     *
+     */
+    private  void loadTemplate() throws SchemaCompilationException {
+
+        //first get the language specific property map
+        Class clazz = this.getClass();
+        InputStream xslStream;
+        String templateName = JAVA_BEAN_TEMPLATE;
+        if (templateName!=null){
+            try {
+                xslStream = clazz.getResourceAsStream(templateName);
+                templateCache = TransformerFactory.newInstance().newTemplates(new StreamSource(xslStream));
+                templateLoaded = true;
+            } catch (TransformerConfigurationException e) {
+                throw new SchemaCompilationException("Error loading the template",e);
+            }
+        }else{
+            throw new SchemaCompilationException("template for this writer is not found");
+        }
+    }
+
+
+     /**
+     * Creates the output file
+     *
+     * @param packageName
+     * @param fileName
+     * @throws Exception
+     */
+    private OutputStream createOutFile(String packageName, String fileName) throws Exception {
+        File outputFile = FileWriter.createClassFile(this.rootDir,
+                packageName,
+                fileName,
+                ".java");
+           return new FileOutputStream(outputFile);
+
+    }
+
+     /**
+     * Writes the output file
+     *
+     * @param documentStream
+     * @throws Exception
+     */
+    private void parse(Document doc,OutputStream outStream) throws Exception {
+
+            XSLTTemplateProcessor.parse(outStream,
+                    doc,
+                    this.templateCache.newTransformer());
+            outStream.flush();
+            outStream.close();
+
+    }
+}

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=312658&r1=312657&r2=312658&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 10 07:09:58 2005
@@ -1,10 +1,14 @@
 package org.apache.axis2.databinding.schema;
 
 import org.apache.ws.commons.schema.*;
+import org.apache.axis2.wsdl.codegen.CodeGenerationException;
 
+import javax.xml.namespace.QName;
 import java.util.List;
 import java.util.Iterator;
 import java.util.HashMap;
+import java.util.Map;
+import java.io.IOException;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -25,21 +29,31 @@
 
     private CompilerOptions options;
     private HashMap processedTypemap;
+    private JavaBeanWriter writer;
+
+    private Map baseSchemaTypeMap = TypeMap.getTypeMap();
+
 
     /**
      *
      * @param options
      */
-    public SchemaCompiler(CompilerOptions options) {
-        if (options==null){
-            //create an empty options object
-            this.options = new CompilerOptions();
-        }else{
-            this.options = options;
-        }
+    public SchemaCompiler(CompilerOptions options) throws SchemaCompilationException {
+        try {
+            if (options==null){
+                //create an empty options object
+                this.options = new CompilerOptions();
+            }else{
+                this.options = options;
+            }
+
+            this.processedTypemap = new HashMap();
 
-        this.processedTypemap = new HashMap();
+            this.writer = new JavaBeanWriter(this.options.getOutputLocation());
 
+        } catch (IOException e) {
+            throw new SchemaCompilationException(e);
+        }
     }
 
     /**
@@ -54,6 +68,8 @@
                 schema =  (XmlSchema)schemalist.get(i);
                 compile(schema);
             }
+        }catch(SchemaCompilationException e) {
+            throw e;
         } catch (Exception e) {
             throw new SchemaCompilationException(e);
         }
@@ -66,6 +82,7 @@
      * @throws SchemaCompilationException
      */
     public void compile(XmlSchema schema) throws SchemaCompilationException{
+
         //write the code here to do the schema compilation
         //select the types
         XmlSchemaObjectTable types =  schema.getSchemaTypes();
@@ -76,20 +93,19 @@
 
         //select all the elements next
         XmlSchemaObjectTable elements = schema.getElements();
-        XmlSchemaElement xsElt;
         Iterator  xmlSchemaElementIterator = elements.getValues();
         while (xmlSchemaElementIterator.hasNext()) {
             processElement((XmlSchemaElement)xmlSchemaElementIterator.next());
         }
 
-        System.out.println("processedTypemap = " + processedTypemap);
+        //System.out.println("processedTypemap = " + processedTypemap);
     }
 
     /**
      *
      * @param xsElt
      */
-    private void processElement(XmlSchemaElement xsElt){
+    private void processElement(XmlSchemaElement xsElt) throws SchemaCompilationException{
         //The processing element logic seems to be quite simple. Look at the relevant schema type
         //for each and every element and process that accordingly.
         //this means that any unused type definitions would not be generated!
@@ -102,7 +118,7 @@
 
     }
 
-    private void processSchema(XmlSchemaType schemaType) {
+    private void processSchema(XmlSchemaType schemaType) throws SchemaCompilationException {
         if (schemaType instanceof XmlSchemaComplexType){
             //write classes for complex types
             processComplexSchemaType((XmlSchemaComplexType)schemaType);
@@ -115,7 +131,7 @@
      * handle the complex type
      * @param complexType
      */
-    private void processComplexSchemaType(XmlSchemaComplexType complexType){
+    private void processComplexSchemaType(XmlSchemaComplexType complexType) throws SchemaCompilationException{
 
         if (processedTypemap.containsKey(complexType.getQName())){
             return;
@@ -125,6 +141,8 @@
         //
 
         XmlSchemaParticle particle =  complexType.getParticle();
+        Map elementMap = new HashMap();
+
         if (particle!=null){
             //check the particle
             if (particle instanceof XmlSchemaSequence ){
@@ -134,7 +152,18 @@
                     XmlSchemaObject item = items.getItem(i);
                     if (item instanceof XmlSchemaElement){
                         //recursively process the element
-                        processElement((XmlSchemaElement)item);
+                        XmlSchemaElement xsElt = (XmlSchemaElement) item;
+                        processElement(xsElt);
+                        //add this to the processed element list
+                        QName schemaTypeQName = xsElt.getSchemaType().getQName();
+                        Class clazz = (Class)baseSchemaTypeMap.get(schemaTypeQName);
+                        if (clazz!=null){
+                            elementMap.put(xsElt.getQName(),clazz.getName());
+                        }else{
+                            elementMap.put(xsElt.getQName(),schemaTypeQName.getLocalPart());
+                        }
+
+
                     }else{
                         //handle the other types here
                     }
@@ -150,7 +179,7 @@
         }
 
         //write the class. This type mapping would have been populated right now
-        
+        writer.write(complexType,processedTypemap,elementMap);
         processedTypemap.put(complexType.getQName(),"");
 
 

Added: 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.java?rev=312658&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/TypeMap.java Mon Oct 10 07:09:58 2005
@@ -0,0 +1,60 @@
+package org.apache.axis2.databinding.schema;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.HashMap;
+/*
+ * 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 TypeMap {
+    
+    public static Map getTypeMap() {
+        return typeMap;
+    }
+
+    private static Map typeMap =  new HashMap();
+
+    static{
+// If SOAP 1.1 over the wire, map wrapper classes to XSD primitives.
+        addTypemapping(Constants.XSD_STRING, java.lang.String.class);
+        addTypemapping(Constants.XSD_BOOLEAN, java.lang.Boolean.class);
+        addTypemapping(Constants.XSD_DOUBLE, java.lang.Double.class);
+        addTypemapping(Constants.XSD_FLOAT, java.lang.Float.class);
+        addTypemapping(Constants.XSD_INT, java.lang.Integer.class);
+        addTypemapping(Constants.XSD_INTEGER, java.math.BigInteger.class
+        );
+        addTypemapping(Constants.XSD_DECIMAL, java.math.BigDecimal.class
+        );
+        addTypemapping(Constants.XSD_LONG, java.lang.Long.class);
+        addTypemapping(Constants.XSD_SHORT, java.lang.Short.class);
+        addTypemapping(Constants.XSD_BYTE, java.lang.Byte.class);
+
+        // The XSD Primitives are mapped to java primitives.
+        addTypemapping(Constants.XSD_BOOLEAN, boolean.class);
+        addTypemapping(Constants.XSD_DOUBLE, double.class);
+        addTypemapping(Constants.XSD_FLOAT, float.class);
+        addTypemapping(Constants.XSD_INT, int.class);
+        addTypemapping(Constants.XSD_LONG, long.class);
+        addTypemapping(Constants.XSD_SHORT, short.class);
+        addTypemapping(Constants.XSD_BYTE, byte.class);
+
+    }
+    private static void addTypemapping(QName name,Class clazz) {
+        typeMap.put( name,clazz);
+    }
+
+
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl?rev=312658&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl Mon Oct 10 07:09:58 2005
@@ -0,0 +1,39 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:output method="text"/>
+    <xsl:template match="/bean">
+    package <xsl:value-of select="@package"/>;
+
+    /**
+     *  Auto generated bean class by the Axis code generator
+     */
+
+    public class <xsl:value-of select="@name"/> {
+
+
+     <xsl:for-each select="property">
+         <xsl:variable name="propertyType"><xsl:value-of select="@type"></xsl:value-of></xsl:variable>
+         <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable>
+        /**
+         * field for <xsl:value-of select="$propertyName"/>
+         */
+         private <xsl:value-of select="$propertyType"/> local<xsl:value-of select="$propertyName"/>;
+
+        /**
+         * Auto generated getter method
+         * @return <xsl:value-of select="$propertyType"/>
+         */
+        public  <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text>get<xsl:value-of select="$propertyName"/>(){
+             return local<xsl:value-of select="$propertyName"/>;
+        }
+
+        /**
+         * Auto generated setter method
+         * @param param<xsl:value-of select="$propertyName"/>
+         */
+        public void set<xsl:value-of select="$propertyName"/>(<xsl:value-of select="$propertyType"/> param<xsl:value-of select="$propertyName"/>){
+             this.local<xsl:value-of select="$propertyName"/>=param<xsl:value-of select="$propertyName"/>;
+        }
+     </xsl:for-each>
+    }
+    </xsl:template>
+ </xsl:stylesheet>
\ No newline at end of file

Copied: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java (from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/FileWriter.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java?p2=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java&p1=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/FileWriter.java&r1=312479&r2=312658&rev=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/FileWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java Mon Oct 10 07:09:58 2005
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.apache.axis2.wsdl.util;
+package org.apache.axis2.util;
 
 
 import java.io.File;

Propchange: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/FileWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java (from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/URLProcessor.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java?p2=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java&p1=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/URLProcessor.java&r1=312479&r2=312658&rev=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/URLProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java Mon Oct 10 07:09:58 2005
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.apache.axis2.wsdl.util;
+package org.apache.axis2.util;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

Propchange: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/URLProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java (from r312479, webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/XSLTTemplateProcessor.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java?p2=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java&p1=webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/XSLTTemplateProcessor.java&r1=312479&r2=312658&rev=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/XSLTTemplateProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java Mon Oct 10 07:09:58 2005
@@ -14,15 +14,18 @@
  * limitations under the License.
  */
 
-package org.apache.axis2.wsdl.util;
+package org.apache.axis2.util;
 
 
+import org.w3c.dom.Document;
+
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import java.io.InputStream;
@@ -54,5 +57,41 @@
 
     }
 
+    /**
+         * Parses an XML stream with an XSL stream
+         *
+         * @param out        Stream to write the output
+         * @param xmlStream  Source XML stream
+         * @throws TransformerFactoryConfigurationError
+         *
+         * @throws TransformerException
+         */
+        public static void parse(OutputStream out,
+                                 Document doc,
+                                 Transformer transformer)
+                throws TransformerFactoryConfigurationError, TransformerException {
+            Source xmlSource = new DOMSource(doc);
+            Result result = new StreamResult(out);
+            transformer.transform(xmlSource, result);
+
+        }
 
+    /**
+     *
+     * @param out
+     * @param document
+     * @param xsltStream
+     * @throws TransformerFactoryConfigurationError
+     * @throws TransformerException
+     */
+       public static void parse(OutputStream out,
+                             Document document,
+                             InputStream xsltStream)
+            throws TransformerFactoryConfigurationError, TransformerException {
+        Source xsltSource = new StreamSource(xsltStream);
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer(xsltSource);
+        parse(out,document,transformer);
+
+    }
 }

Propchange: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTTemplateProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTUtils.java?rev=312658&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTUtils.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/XSLTUtils.java Mon Oct 10 07:09:58 2005
@@ -0,0 +1,65 @@
+package org.apache.axis2.util;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.DocumentBuilderFactory;
+/*
+ * 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 XSLTUtils {
+
+    public static Document getDocument() throws ParserConfigurationException {
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        return documentBuilderFactory.newDocumentBuilder().newDocument();
+    }
+
+    /**
+     * Utility method to add an attribute to a given element
+     * @param document
+     * @param AttribName
+     * @param attribValue
+     * @param element
+     */
+    public static void addAttribute(Document document,
+                                    String AttribName,
+                                    String attribValue,
+                                    Element element) {
+        Attr attribute = document.createAttribute(AttribName);
+        attribute.setValue(attribValue);
+        element.setAttributeNode(attribute);
+    }
+
+    /**
+     * Utility method to add an attribute to a given element
+     * @param document
+     * @param attribName
+     * @param attribValue
+     * @param element
+     */
+    public static Element addChildElement(Document document,
+                                          String elementName,
+                                          Node parentNode) {
+        Element elt = document.createElement(elementName);
+        parentNode.appendChild(elt);
+        return elt;
+    }
+
+}

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=312658&r1=312657&r2=312658&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 Mon Oct 10 07:09:58 2005
@@ -4,6 +4,7 @@
 # Extensions - The extensions are comma seperated
 # these are loaded in their lexical order
 codegen.extension=org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder,org.apache.axis2.wsdl.codegen.extension.WSDLValidatorExtension,org.apache.axis2.wsdl.codegen.extension.PackageFinder,org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension,org.apache.axis2.wsdl.codegen.extension.DefaultDatabindingExtension
+#codegen.extension=org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder,org.apache.axis2.wsdl.codegen.extension.WSDLValidatorExtension,org.apache.axis2.wsdl.codegen.extension.PackageFinder,org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension,org.apache.axis2.wsdl.codegen.extension.DefaultDatabindingExtension
 # The third party schemas to be loaded. e.g. The Xmime extension
 # Note - these will be loaded from the org.apache.axis2.wsdl.codegen.schema package.
 # so whatever the third party schema's that are listed here should be present there

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=312658&r1=312657&r2=312658&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 Mon Oct 10 07:09:58 2005
@@ -17,6 +17,7 @@
 package org.apache.axis2.wsdl.codegen.emitter;
 
 import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.util.XSLTUtils;
 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
 import org.apache.axis2.wsdl.codegen.CodeGenerationException;
 import org.apache.axis2.wsdl.codegen.XSLTConstants;
@@ -28,7 +29,6 @@
 import org.apache.wsdl.extensions.ExtensionConstants;
 import org.apache.wsdl.extensions.SOAPHeader;
 import org.apache.wsdl.extensions.SOAPOperation;
-import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Text;
@@ -37,12 +37,6 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -472,22 +466,12 @@
      */
     protected void writeClass(Document model, ClassWriter writer) throws IOException,
             Exception {
-        ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
-        // Use a Transformer for output
-        TransformerFactory tFactory =
-                TransformerFactory.newInstance();
-        Transformer transformer = tFactory.newTransformer();
-
-        DOMSource source = new DOMSource(model);
-        StreamResult result = new StreamResult(memoryStream);
-        transformer.transform(source, result);
-
         writer.loadTemplate();
         writer.createOutFile(
                 model.getDocumentElement().getAttribute("package"),
                 model.getDocumentElement().getAttribute("name"));
-        writer.writeOutFile(
-                new ByteArrayInputStream(memoryStream.toByteArray()));
+        writer.parse(
+                model);
     }
 
 
@@ -1187,9 +1171,7 @@
                                 String AttribName,
                                 String attribValue,
                                 Element element) {
-        Attr attribute = document.createAttribute(AttribName);
-        attribute.setValue(attribValue);
-        element.setAttributeNode(attribute);
+       XSLTUtils.addAttribute(document,AttribName,attribValue,element);
     }
 
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/PackageFinder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/PackageFinder.java?rev=312658&r1=312657&r2=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/PackageFinder.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/PackageFinder.java Mon Oct 10 07:09:58 2005
@@ -17,7 +17,7 @@
 package org.apache.axis2.wsdl.codegen.extension;
 
 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
-import org.apache.axis2.wsdl.util.URLProcessor;
+import org.apache.axis2.util.URLProcessor;
 import org.apache.wsdl.WSDLBinding;
 
 public class PackageFinder extends AbstractCodeGenerationExtension {

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ClassWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ClassWriter.java?rev=312658&r1=312657&r2=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ClassWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ClassWriter.java Mon Oct 10 07:09:58 2005
@@ -18,8 +18,9 @@
 
 import org.apache.axis2.wsdl.codegen.CodeGenerationException;
 import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
-import org.apache.axis2.wsdl.util.FileWriter;
-import org.apache.axis2.wsdl.util.XSLTTemplateProcessor;
+import org.apache.axis2.util.FileWriter;
+import org.apache.axis2.util.XSLTTemplateProcessor;
+import org.w3c.dom.Document;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -148,10 +149,10 @@
      * @param documentStream
      * @throws Exception
      */
-    public void writeOutFile(InputStream documentStream) throws Exception {
+    public void parse(Document doc) throws Exception {
         if (!fileExists){
             XSLTTemplateProcessor.parse(this.stream,
-                    documentStream,
+                    doc,
                     this.xsltStream);
             this.stream.flush();
             this.stream.close();

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ServiceXMLWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ServiceXMLWriter.java?rev=312658&r1=312657&r2=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ServiceXMLWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ServiceXMLWriter.java Mon Oct 10 07:09:58 2005
@@ -16,7 +16,7 @@
 
 package org.apache.axis2.wsdl.codegen.writer;
 
-import org.apache.axis2.wsdl.util.FileWriter;
+import org.apache.axis2.util.FileWriter;
 
 import java.io.File;
 import java.io.FileOutputStream;

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/TestServiceXMLWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/TestServiceXMLWriter.java?rev=312658&r1=312657&r2=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/TestServiceXMLWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/TestServiceXMLWriter.java Mon Oct 10 07:09:58 2005
@@ -16,7 +16,7 @@
 
 package org.apache.axis2.wsdl.codegen.writer;
 
-import org.apache.axis2.wsdl.util.FileWriter;
+import org.apache.axis2.util.FileWriter;
 
 import java.io.File;
 import java.io.FileOutputStream;

Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java?rev=312658&r1=312657&r2=312658&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java Mon Oct 10 07:09:58 2005
@@ -33,6 +33,9 @@
     //this should be an xsd name in the test-resource directory
     protected String fileName = "";
     protected  XmlSchema currentSchema;
+    protected File outputFolder = null;
+
+    private static String TEMP_OUT_FOLDER="temp_compile";
 
     protected void setUp() throws Exception {
         //load the current Schema through a file
@@ -46,13 +49,48 @@
         //now read it to a schema
         XmlSchemaCollection schemaCol =  new XmlSchemaCollection();
         currentSchema = schemaCol.read(doc,null);
+
+        outputFolder = new File(TEMP_OUT_FOLDER);
+        if (outputFolder.exists()){
+            if (outputFolder.isFile()){
+                outputFolder.delete();
+                outputFolder.mkdirs();
+            }
+        }else{
+            outputFolder.mkdirs();
+        }
     }
 
 
+
     public void testSchema() throws Exception{
-        SchemaCompiler compiler = new SchemaCompiler(null);
+        CompilerOptions compilerOptions = new CompilerOptions();
+        compilerOptions.setOutputLocation(outputFolder);
+        SchemaCompiler compiler = new SchemaCompiler(compilerOptions);
         compiler.compile(currentSchema);
     }
 
+    protected void tearDown() throws Exception {
+         deleteDir(outputFolder);
+    }
+
+    /**
+     * Deletes all files and subdirectories under dir.
+     * Returns true if all deletions were successful.
+     * If a deletion fails, the method stops attempting to delete and returns false.
+     */
+    private boolean deleteDir(File dir) {
+        if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i=0; i<children.length; i++) {
+                boolean success = deleteDir(new File(dir, children[i]));
+                if (!success) {
+                    return false;
+                }
+            }
+        }
 
+        // The directory is now empty so delete it
+        return dir.delete();
+    }
 }