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/06 12:55:27 UTC

svn commit: r306583 [6/9] - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2: databinding/ databinding/gen/ databinding/gen/impl/ databinding/symbolTable/ databinding/toJava/ databinding/utils/ databinding/utils/support/ wsdl/codeg...

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaEnumTypeWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaEnumTypeWriter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaEnumTypeWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaEnumTypeWriter.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,375 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+
+import org.apache.axis2.databinding.symbolTable.TypeEntry;
+import org.apache.axis2.databinding.utils.JavaUtils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Vector;
+
+/**
+ * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file.
+ */
+public class JavaEnumTypeWriter extends JavaClassWriter {
+
+    /** Field elements */
+    private Vector elements;
+
+    /** Field type */
+    private TypeEntry type;
+
+    /**
+     * Constructor.
+     * 
+     * @param emitter  
+     * @param type     
+     * @param elements 
+     */
+    protected JavaEnumTypeWriter(Emitter emitter, TypeEntry type,
+                                 Vector elements) {
+
+        super(emitter, type.getName(), "enumType");
+
+        this.elements = elements;
+        this.type = type;
+    }    // ctor
+
+    /**
+     * Return "implements java.io.Serializable ".
+     * 
+     * @return 
+     */
+    protected String getImplementsText() {
+        return "implements java.io.Serializable ";
+    }    // getImplementsText
+
+    /**
+     * Generate the binding for the given enumeration type.
+     * The values vector contains the base type (first index) and
+     * the values (subsequent Strings)
+     * 
+     * @param pw 
+     * @throws IOException 
+     */
+    protected void writeFileBody(PrintWriter pw) throws IOException {
+
+        // Get the java name of the type
+        String javaName = getClassName();
+
+        // The first index is the base type.
+        // The base type could be a non-object, if so get the corresponding Class.
+        String baseType = ((TypeEntry) elements.get(0)).getName();
+        String baseClass = baseType;
+
+        if (baseType.indexOf("int") == 0) {
+            baseClass = "java.lang.Integer";
+        } else if (baseType.indexOf("char") == 0) {
+            baseClass = "java.lang.Character";
+        } else if (baseType.indexOf("short") == 0) {
+            baseClass = "java.lang.Short";
+        } else if (baseType.indexOf("long") == 0) {
+            baseClass = "java.lang.Long";
+        } else if (baseType.indexOf("double") == 0) {
+            baseClass = "java.lang.Double";
+        } else if (baseType.indexOf("float") == 0) {
+            baseClass = "java.lang.Float";
+        } else if (baseType.indexOf("byte") == 0) {
+            baseClass = "java.lang.Byte";
+        }
+
+        // Create a list of the literal values.
+        Vector values = new Vector();
+
+        for (int i = 1; i < elements.size(); i++) {
+            String value = (String) elements.get(i);
+
+            if (baseClass.equals("java.lang.String")) {
+                value = "\"" + value
+                        + "\"";    // Surround literal with double quotes
+            } else if (baseClass.equals("java.lang.Character")) {
+                value = "'" + value + "'";
+            } else if (baseClass.equals("java.lang.Float")) {
+                if (!value.endsWith("F") && // Indicate float literal so javac
+                        !value.endsWith(
+                                "f")) {    // doesn't complain about precision.
+                    value += "F";
+                }
+            } else if (baseClass.equals("java.lang.Long")) {
+                if (!value.endsWith("L") && // Indicate float literal so javac
+                        !value.endsWith(
+                                "l")) {    // doesn't complain about precision.
+                    value += "L";
+                }
+            } else if (baseClass.equals("javax.xml.namespace.QName")) {
+                value = org.apache.axis2.databinding.symbolTable.Utils.getQNameFromPrefixedName(type.getNode(), value).toString();
+                value = "javax.xml.namespace.QName.valueOf(\"" + value + "\")";
+            } else if (baseClass.equals(baseType)) {
+
+                // Construct baseClass object with literal string
+                value = "new " + baseClass + "(\"" + value + "\")";
+            }
+
+            values.add(value);
+        }
+
+        // Create a list of ids
+        Vector ids = getEnumValueIds(elements);
+
+        // Each object has a private _value_ variable to store the base value
+        pw.println("    private " + baseType + " _value_;");
+
+        // The enumeration values are kept in a hashtable
+        pw.println(
+                "    private static java.util.HashMap _table_ = new java.util.HashMap();");
+        pw.println("");
+
+        // A protected constructor is used to create the static enumeration values
+       // pw.println("    // " + Messages.getMessage("ctor00"));
+        pw.println("    protected " + javaName + "(" + baseType + " value) {");
+        pw.println("        _value_ = value;");
+
+        if (baseClass.equals("java.lang.String")
+                || baseClass.equals(baseType)) {
+            pw.println("        _table_.put(_value_,this);");
+        } else {
+            pw.println("        _table_.put(new " + baseClass
+                    + "(_value_),this);");
+        }
+
+        pw.println("    }");
+        pw.println("");
+
+        // A public static variable of the base type is generated for each enumeration value.
+        // Each variable is preceded by an _.
+        for (int i = 0; i < ids.size(); i++) {
+            
+            // Need to catch the checked MalformedURIException for URI base types
+            if(baseType.equals("org.apache.axis.types.URI")) {
+                pw.println("    public static final " + baseType + " _" + ids.get(i) + ";");
+                pw.println("    static {");
+                pw.println("    	try {");
+                pw.println("            _" + ids.get(i) + " = " + values.get(i) + ";");
+                pw.println("        }");
+                pw.println("        catch (org.apache.axis.types.URI.MalformedURIException mue) {");
+                pw.println("            throw new java.lang.RuntimeException(mue.toString());");
+                pw.println("        }");
+                pw.println("    }");
+                pw.println("");
+            }
+            else {
+                pw.println("    public static final " + baseType + " _"
+                    + ids.get(i) + " = " + values.get(i) + ";");
+            }
+        }
+
+        // A public static variable is generated for each enumeration value.
+        for (int i = 0; i < ids.size(); i++) {
+            pw.println("    public static final " + javaName + " " + ids.get(i)
+                    + " = new " + javaName + "(_" + ids.get(i) + ");");
+        }
+
+        // Getter that returns the base value of the enumeration value
+        pw.println("    public " + baseType + " getValue() { return _value_;}");
+
+        // FromValue returns the unique enumeration value object from the table
+        pw.println("    public static " + javaName + " fromValue(" + baseType
+                + " value)");
+        pw.println("          throws java.lang.IllegalArgumentException {");
+        pw.println("        " + javaName + " enumeration = (" + javaName + ")");
+
+        if (baseClass.equals("java.lang.String")
+                || baseClass.equals(baseType)) {
+            pw.println("            _table_.get(value);");
+        } else {
+            pw.println("            _table_.get(new " + baseClass
+                    + "(value));");
+        }
+
+        pw.println(
+                "        if (enumeration==null) throw new java.lang.IllegalArgumentException();");
+        pw.println("        return enumeration;");
+        pw.println("    }");
+
+        // FromString returns the unique enumeration value object from a string representation
+        pw.println("    public static " + javaName
+                + " fromString(java.lang.String value)");
+        pw.println("          throws java.lang.IllegalArgumentException {");
+
+        if (baseClass.equals("java.lang.String")) {
+            pw.println("        return fromValue(value);");
+        } else if (baseClass.equals("javax.xml.namespace.QName")) {
+            pw.println("        try {");
+            pw.println("            return fromValue(javax.xml.namespace.QName.valueOf"
+                    + "(value));");
+            pw.println("        } catch (Exception e) {");
+            pw.println(
+                    "            throw new java.lang.IllegalArgumentException();");
+            pw.println("        }");
+        } else if (baseClass.equals(baseType)) {
+            pw.println("        try {");
+            pw.println("            return fromValue(new " + baseClass
+                    + "(value));");
+            pw.println("        } catch (Exception e) {");
+            pw.println(
+                    "            throw new java.lang.IllegalArgumentException();");
+            pw.println("        }");
+        } else if (baseClass.equals("java.lang.Character")) {
+            pw.println("        if (value != null && value.length() == 1);");
+            pw.println("            return fromValue(value.charAt(0));");
+            pw.println(
+                    "        throw new java.lang.IllegalArgumentException();");
+        } else if (baseClass.equals("java.lang.Integer")) {
+            pw.println("        try {");
+            pw.println(
+                    "            return fromValue(java.lang.Integer.parseInt(value));");
+            pw.println("        } catch (Exception e) {");
+            pw.println(
+                    "            throw new java.lang.IllegalArgumentException();");
+            pw.println("        }");
+        } else {
+            String parse = "parse"
+                    + baseClass.substring(baseClass.lastIndexOf(".")
+                    + 1);
+
+            pw.println("        try {");
+            pw.println("            return fromValue(" + baseClass + "."
+                    + parse + "(value));");
+            pw.println("        } catch (Exception e) {");
+            pw.println(
+                    "            throw new java.lang.IllegalArgumentException();");
+            pw.println("        }");
+        }
+
+        pw.println("    }");
+
+        // Equals == to determine equality value.
+        // Since enumeration values are singletons, == is appropriate for equals()
+        pw.println(
+                "    public boolean equals(java.lang.Object obj) {return (obj == this);}");
+
+        // Provide a reasonable hashCode method (hashCode of the string value of the enumeration)
+        pw.println(
+                "    public int hashCode() { return toString().hashCode();}");
+
+        // toString returns a string representation of the enumerated value
+        if (baseClass.equals("java.lang.String")) {
+            pw.println(
+                    "    public java.lang.String toString() { return _value_;}");
+        } else if (baseClass.equals(baseType)) {
+            pw.println(
+                    "    public java.lang.String toString() { return _value_.toString();}");
+        } else {
+            pw.println(
+                    "    public java.lang.String toString() { return java.lang.String.valueOf(_value_);}");
+        }
+
+        pw.println(
+                "    public java.lang.Object readResolve() throws java.io.ObjectStreamException { return fromValue(_value_);}");
+        pw.println(
+                "    public static org.apache.axis.encoding.Serializer getSerializer(");
+        pw.println("           java.lang.String mechType, ");
+        pw.println("           java.lang.Class _javaType,  ");
+        pw.println("           javax.xml.namespace.QName _xmlType) {");
+        pw.println("        return ");
+        pw.println(
+                "          new org.apache.axis.encoding.ser.EnumSerializer(");
+        pw.println("            _javaType, _xmlType);");
+        pw.println("    }");
+        pw.println(
+                "    public static org.apache.axis.encoding.Deserializer getDeserializer(");
+        pw.println("           java.lang.String mechType, ");
+        pw.println("           java.lang.Class _javaType,  ");
+        pw.println("           javax.xml.namespace.QName _xmlType) {");
+        pw.println("        return ");
+        pw.println(
+                "          new org.apache.axis.encoding.ser.EnumDeserializer(");
+        pw.println("            _javaType, _xmlType);");
+        pw.println("    }");
+        //pw.println("    // " + Messages.getMessage("typeMeta"));
+        pw.println(
+                "    private static org.apache.axis.description.TypeDesc typeDesc =");
+        pw.println("        new org.apache.axis.description.TypeDesc("
+                + Utils.getJavaLocalName(type.getName()) + ".class);");
+        pw.println();
+        pw.println("    static {");
+        pw.println("        typeDesc.setXmlType("
+                + Utils.getNewQName(type.getQName()) + ");");
+        pw.println("    }");
+        pw.println("    /**");
+        //pw.println("     * " + Messages.getMessage("returnTypeMeta"));
+        pw.println("     */");
+        pw.println(
+                "    public static org.apache.axis.description.TypeDesc getTypeDesc() {");
+        pw.println("        return typeDesc;");
+        pw.println("    }");
+        pw.println();
+    }    // writeFileBody
+
+    /**
+     * Get the enumeration names for the values.
+     * The name is affected by whether all of the values of the enumeration
+     * can be expressed as valid java identifiers.
+     * 
+     * @param bv Vector base and values vector from getEnumerationBaseAndValues
+     * @return Vector names of enum value identifiers.
+     */
+    public static Vector getEnumValueIds(Vector bv) {
+
+        boolean validJava = true;    // Assume all enum values are valid ids
+
+        // Walk the values looking for invalid ids
+        for (int i = 1; (i < bv.size()) && validJava; i++) {
+            String value = (String) bv.get(i);
+
+            if (!JavaUtils.isJavaId(value)) {
+                validJava = false;
+            }
+        }
+
+        // Build the vector of ids
+        Vector ids = new Vector();
+
+        for (int i = 1; i < bv.size(); i++) {
+
+            // If any enum values are not valid java, then
+            // all of the ids are of the form value<1..N>.
+            if (!validJava) {
+                ids.add("value" + i);
+            } else {
+                ids.add((String) bv.get(i));
+            }
+        }
+
+        return ids;
+    }
+
+    /** Generate a java source file for enum class.
+     * If the emitter works in deploy mode and the class already exists, the source wull not be generated.
+     */
+    public void generate() throws IOException {
+        String fqcn = getPackage() + "." + getClassName();	
+        if (emitter.isDeploy()) {
+            if (!emitter.doesExist(fqcn)) {
+                super.generate();
+            }
+        } else {
+            super.generate();
+        }
+    }
+}    // class JavaEnumTypeWriter

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaHolderWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaHolderWriter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaHolderWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaHolderWriter.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+//import org.apache.axis.wsdl.symbolTable.TypeEntry;
+import org.apache.axis2.databinding.symbolTable.TypeEntry;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * This is Wsdl2java's Holder Writer.  It writes the <typeName>Holder.java file.
+ */
+public class JavaHolderWriter extends JavaClassWriter {
+
+    /** Field type */
+    private TypeEntry type;
+
+    /**
+     * Constructor.
+     * 
+     * @param emitter 
+     * @param type    
+     */
+    protected JavaHolderWriter(Emitter emitter, TypeEntry type) {
+
+        super(emitter, Utils.holder(type, emitter), "holder");
+
+        this.type = type;
+    }    // ctor
+
+    /**
+     * Return "public final ".
+     * 
+     * @return 
+     */
+    protected String getClassModifiers() {
+        return super.getClassModifiers() + "final ";
+    }    // getClassModifiers
+
+    /**
+     * Return "implements javax.xml.rpc.holders.Holder ".
+     * 
+     * @return 
+     */
+    protected String getImplementsText() {
+        return "implements javax.xml.rpc.holders.Holder ";
+    }    // getImplementsText
+
+    /**
+     * Generate the holder for the given complex type.
+     * 
+     * @param pw 
+     * @throws IOException 
+     */
+    protected void writeFileBody(PrintWriter pw) throws IOException {
+
+        String holderType = type.getName();
+
+        pw.println("    public " + holderType + " value;");
+        pw.println();
+        pw.println("    public " + className + "() {");
+        pw.println("    }");
+        pw.println();
+        pw.println("    public " + className + "(" + holderType + " value) {");
+        pw.println("        this.value = value;");
+        pw.println("    }");
+        pw.println();
+    }    // writeOperation
+
+    /** Generate a java source file for the holder class.
+     * If the emitter works in deploy mode and the class already exists, the source wull not be generated.
+     */
+    public void generate() throws IOException {
+        String fqcn = getPackage() + "." + getClassName();
+        if (emitter.isDeploy()) {
+            if (!emitter.doesExist(fqcn)) {
+                super.generate();
+            }
+        } else {
+            super.generate();
+        }
+    }
+}    // class JavaHolderWriter

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaTypeWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaTypeWriter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaTypeWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaTypeWriter.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+//import org.apache.axis.wsdl.gen.Generator;
+//import org.apache.axis.wsdl.symbolTable.SchemaUtils;
+//import org.apache.axis.wsdl.symbolTable.SymTabEntry;
+//import org.apache.axis.wsdl.symbolTable.SymbolTable;
+//import org.apache.axis.wsdl.symbolTable.Type;
+//import org.apache.axis.wsdl.symbolTable.TypeEntry;
+import org.apache.axis2.databinding.gen.Generator;
+import org.apache.axis2.databinding.symbolTable.*;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.util.Vector;
+import java.util.Collections;
+
+/**
+ * This is Wsdl2java's Type Writer.  It writes the following files, as appropriate:
+ * <typeName>.java, <typeName>Holder.java.
+ */
+public class JavaTypeWriter implements Generator {
+
+    /** Field HOLDER_IS_NEEDED */
+    public static final String HOLDER_IS_NEEDED = "Holder is needed";
+
+    /** Field typeWriter */
+    private Generator typeWriter = null;
+
+    /** Field holderWriter */
+    private Generator holderWriter = null;
+
+    /**
+     * Constructor.
+     * 
+     * @param emitter     
+     * @param type        
+     * @param symbolTable 
+     */
+    public JavaTypeWriter(Emitter emitter, TypeEntry type,
+                          SymbolTable symbolTable) {
+
+        //if (type.isReferenced() && !type.isOnlyLiteralReferenced()) {
+
+            // Determine what sort of type this is and instantiate
+            // the appropriate Writer.
+            Node node = type.getNode();
+
+            boolean isSimpleList = SchemaUtils.isListWithItemType(node);
+            // If it's an array, don't emit a class
+            if (!type.getName().endsWith("[]") && !isSimpleList) {
+                
+                // Generate the proper class for either "complex" or "enumeration" types
+                Vector v = Utils.getEnumerationBaseAndValues(node, symbolTable);
+
+                if (v != null) {
+                    typeWriter = getEnumTypeWriter(emitter, type, v);
+                } else {
+                    TypeEntry base =
+                            SchemaUtils.getComplexElementExtensionBase(node,
+                                    symbolTable);
+
+                    if (base == null) {
+                        base = SchemaUtils.getComplexElementRestrictionBase(
+                                node, symbolTable);
+                    }
+
+                    if (base == null) {
+                        QName baseQName = SchemaUtils.getSimpleTypeBase(node);
+
+                        if (baseQName != null) {
+                            base = symbolTable.getType(baseQName);
+                        }
+                    }
+
+                    typeWriter = getBeanWriter(emitter, type, base);
+                }
+            }
+
+            // If the holder is needed (ie., something uses this type as an out or inout
+            // parameter), instantiate the holder writer.
+            if (holderIsNeeded(type)) {
+                holderWriter = getHolderWriter(emitter, type);
+            }
+            
+            if (typeWriter != null && type instanceof Type) {
+                ((Type)type).setGenerated(true);
+            }
+        //}
+    }    // ctor
+
+    /**
+     * Write all the service bindnigs:  service and testcase.
+     * 
+     * @throws IOException 
+     */
+    public void generate() throws IOException {
+
+        if (typeWriter != null) {
+            typeWriter.generate();
+        }
+
+        if (holderWriter != null) {
+            holderWriter.generate();
+        }
+    }    // generate
+
+    /**
+     * Does anything use this type as an inout/out parameter?  Query the Type dynamicVar
+     * 
+     * @param entry 
+     * @return 
+     */
+    private boolean holderIsNeeded(SymTabEntry entry) {
+
+        Boolean holderIsNeeded =
+                (Boolean) entry.getDynamicVar(HOLDER_IS_NEEDED);
+
+        return ((holderIsNeeded != null) && holderIsNeeded.booleanValue());
+    }    // holderIsNeeded
+
+    /**
+     * getEnumWriter
+     * 
+     * @param emitter 
+     * @param type    
+     * @param v       
+     * @return 
+     */
+    protected JavaWriter getEnumTypeWriter(Emitter emitter, TypeEntry type,
+                                           Vector v) {
+        return new JavaEnumTypeWriter(emitter, type, v);
+    }
+
+    /**
+     * getBeanWriter
+     * 
+     * @param emitter    
+     * @param type       
+     * @param base       
+     * @return 
+     */
+    protected JavaWriter getBeanWriter(Emitter emitter, TypeEntry type, TypeEntry base) {   // CONTAINED_ELEM_AND_ATTR
+        Vector elements = type.getContainedElements();
+        Vector attributes = type.getContainedAttributes();
+        
+        // If this complexType is referenced in a
+        // fault context, emit a bean-like exception
+        // class
+        Boolean isComplexFault = (Boolean) type.getDynamicVar(COMPLEX_TYPE_FAULT);
+
+        if ((isComplexFault != null) && isComplexFault.booleanValue()) {
+
+            return new JavaBeanFaultWriter(emitter, type, elements, base,
+                attributes,
+                getBeanHelperWriter(emitter, type, elements, base,
+                                    attributes, true));
+        }
+
+        return new JavaBeanWriter(emitter, type, elements, base, attributes,
+                getBeanHelperWriter(emitter, type, elements, base,
+                                    attributes, false));
+    }
+
+    /**
+     * getHelperWriter
+     * 
+     * @param emitter    
+     * @param type       
+     * @param elements   
+     * @param base       
+     * @param attributes 
+     * @return 
+     */
+    protected JavaWriter getBeanHelperWriter(
+            Emitter emitter, TypeEntry type, Vector elements, TypeEntry base,
+            Vector attributes, boolean forException) {
+        return new JavaBeanHelperWriter(
+                emitter, type, elements, base, attributes,
+                forException  ?  JavaBeanFaultWriter.RESERVED_PROPERTY_NAMES
+                              :  Collections.EMPTY_SET);
+    }
+
+    /**
+     * getHolderWriter
+     * 
+     * @param emitter 
+     * @param type    
+     * @return 
+     */
+    protected Generator getHolderWriter(Emitter emitter, TypeEntry type) {
+        return new JavaHolderWriter(emitter, type);
+    }
+}    // class JavaTypeWriter

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaWriter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaWriter.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,375 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+import org.apache.axis2.databinding.gen.Generator;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+
+/**
+ * Emitter knows about WSDL writers, one each for PortType, Binding, Service,
+ * Definition, Type.  But for some of these WSDL types, Wsdl2java generates
+ * multiple files.  Each of these files has a corresponding writer that extends
+ * JavaWriter.  So the Java WSDL writers (JavaPortTypeWriter, JavaBindingWriter,
+ * etc.) each calls a file writer (JavaStubWriter, JavaSkelWriter, etc.) for
+ * each file that that WSDL generates.
+ * <p/>
+ * <p>For example, when Emitter calls JavaWriterFactory for a Binding Writer, it
+ * returns a JavaBindingWriter.  JavaBindingWriter, in turn, contains a
+ * JavaStubWriter, JavaSkelWriter, and JavaImplWriter since a Binding may cause
+ * a stub, skeleton, and impl template to be generated.
+ * <p/>
+ * <p>Note that the writers that are given to Emitter by JavaWriterFactory DO NOT
+ * extend JavaWriter.  They simply implement Writer and delegate the actual
+ * task of writing to extensions of JavaWriter.
+ * <p/>
+ * <p>All of Wsdl2java's Writer implementations follow a common behaviour.
+ * JavaWriter is the abstract base class that dictates this common behaviour.
+ * This behaviour is primarily placed within the generate method.  The generate
+ * method calls, in succession (note:  the starred methods are the ones you are
+ * probably most interested in):
+ * <dl>
+ * <dt> * getFileName
+ * <dd> This is an abstract method that must be implemented by the subclass.
+ * It returns the fully-qualified file name.
+ * <dt> isFileGenerated(file)
+ * <dd> You should not need to override this method.  It checks to see whether
+ * this file is in the List returned by emitter.getGeneratedFileNames.
+ * <dt> registerFile(file)
+ * <dd> You should not need to override this method.  It registers this file by
+ * calling emitter.getGeneratedFileInfo().add(...).
+ * <dt> * verboseMessage(file)
+ * <dd> You may override this method if you want to provide more information.
+ * The generate method only calls verboseMessage if verbose is turned on.
+ * <dt> getPrintWriter(file)
+ * <dd> You should not need to override this method.  Given the file name, it
+ * creates a PrintWriter for it.
+ * <dt> * writeFileHeader(pw)
+ * <dd> You may want to override this method.  The default implementation
+ * generates nothing.
+ * <dt> * writeFileBody(pw)
+ * <dd> This is an abstract method that must be implemented by the subclass.
+ * This is where the body of a file is generated.
+ * <dt> * writeFileFooter(pw)
+ * <dd> You may want to override this method.  The default implementation
+ * generates nothing.
+ * <dt> closePrintWriter(pw)
+ * <dd> You should not need to override this method.  It simply closes the
+ * PrintWriter.
+ * </dl>
+ */
+public abstract class JavaWriter implements Generator {
+
+    /** This controls how many characters per line for javadoc comments */
+    protected final static int LINE_LENGTH = 65;
+
+    /** Field emitter */
+    protected Emitter emitter;
+
+    /** Field type */
+    protected String type;
+
+    /**
+     * Constructor.
+     *
+     * @param emitter
+     * @param type
+     */
+    protected JavaWriter(Emitter emitter, String type) {
+        this.emitter = emitter;
+        this.type = type;
+    }    // ctor
+
+    /**
+     * Generate a file.
+     *
+     * @throws IOException
+     */
+    public void generate() throws IOException {
+
+        String file = getFileName();
+
+        if (isFileGenerated(file)) {
+           // throw new DuplicateFileException("");
+                //    Messages.getMessage("duplicateFile00", file), file);
+        }
+
+        registerFile(file);
+
+        if (emitter.isVerbose()) {
+            String msg = verboseMessage(file);
+
+            if (msg != null) {
+                System.out.println(msg);
+            }
+        }
+
+        PrintWriter pw = getPrintWriter(file);
+
+        writeFileHeader(pw);
+        writeFileBody(pw);
+        writeFileFooter(pw);
+        closePrintWriter(pw);
+    }    // generate
+
+    /**
+     * This method must be implemented by a subclass.  It
+     * returns the fully-qualified name of the file to be
+     * generated.
+     *
+     * @return
+     */
+    protected abstract String getFileName();
+
+    /**
+     * You should not need to override this method. It checks
+     * to see whether the given file is in the List returned
+     * by emitter.getGeneratedFileNames.
+     *
+     * @param file
+     * @return
+     */
+    protected boolean isFileGenerated(String file) {
+        return emitter.getGeneratedFileNames().contains(file);
+    }    // isFileGenerated
+
+    /**
+     * You should not need to override this method.
+     * It registers the given file by calling
+     * emitter.getGeneratedFileInfo().add(...).
+     *
+     * @param file
+     */
+    protected void registerFile(String file) {
+        emitter.getGeneratedFileInfo().add(file, null, type);
+    }    // registerFile
+
+    /**
+     * Return the string:  "Generating <file>".  Override this
+     * method if you want to provide more information.
+     *
+     * @param file
+     * @return
+     */
+    protected String verboseMessage(String file) {
+        return "";// todo Messages.getMessage("generating", file);
+    }    // verboseMessage
+
+    /**
+     * You should not need to override this method.
+     * Given the file name, it creates a PrintWriter for it.
+     *
+     * @param filename
+     * @return
+     * @throws IOException
+     */
+    protected PrintWriter getPrintWriter(String filename) throws IOException {
+
+        File file = new File(filename);
+        File parent = new File(file.getParent());
+
+        parent.mkdirs();
+
+        return new PrintWriter(new FileWriter(file));
+    }                                // getPrintWriter
+
+    /**
+     * This method is intended to be overridden as necessary
+     * to generate file header information.  This default
+     * implementation does nothing.
+     *
+     * @param pw
+     * @throws IOException
+     */
+    protected void writeFileHeader(PrintWriter pw)
+            throws IOException {
+    }    // writeFileHeader
+
+    /**
+     * This method must be implemented by a subclass.  This
+     * is where the body of a file is generated.
+     *
+     * @param pw
+     * @throws IOException
+     */
+    protected abstract void writeFileBody(PrintWriter pw) throws IOException;
+
+    /**
+     * You may want to override this method.  This default
+     * implementation generates nothing.
+     *
+     * @param pw
+     * @throws IOException
+     */
+    protected void writeFileFooter(PrintWriter pw)
+            throws IOException {
+    }    // writeFileFooter
+
+    /**
+     * Close the print writer.
+     *
+     * @param pw
+     */
+    protected void closePrintWriter(PrintWriter pw) {
+        pw.close();
+    }    // closePrintWriter
+
+    /**
+     * Takes out new lines and wraps at Javadoc tags
+     * @param documentation the raw comments from schema
+     * @param addTab if true adds a tab character when wrapping (methods)
+     */
+    protected String getJavadocDescriptionPart(String documentation, boolean addTab) {
+        if (documentation == null) {
+            return "";
+        }
+
+        String doc = documentation.trim();
+
+        if (documentation.trim().length() == 0) {
+            //nothing to do
+            return doc;
+        }
+
+        // make @ tags start a new line (for javadoc tags mostly)
+        StringTokenizer st = new StringTokenizer(doc, "@");
+        StringBuffer newComments;
+        if (st.hasMoreTokens()) {
+            String token = st.nextToken();
+            boolean startLine = Character.isWhitespace(token.charAt(token.length() - 1))
+                && (token.charAt(token.length() - 1) != '\n');
+            newComments = new StringBuffer(token);
+            
+            while (st.hasMoreTokens()) {
+                token = st.nextToken();
+                // don't span links across lines
+                if (startLine) {
+                    newComments.append('\n');
+                }
+                newComments.append('@');
+                startLine = Character.isWhitespace(token.charAt(token.length() - 1))
+            & (token.charAt(token.length() - 1) != '\n');
+
+                newComments.append(token);
+            }
+        } else {
+            newComments = new StringBuffer(doc);
+        }
+        newComments.insert(0, addTab ? "     * " : " * ");
+
+        // tweak comment ending tags by insterting a
+        // space between the star and the slash, BUG13407
+        int pos = newComments.toString().indexOf("*/");
+        while (pos >= 0) {
+            newComments.insert(pos + 1, ' ');
+            pos = newComments.toString().indexOf("*/");
+        }
+        
+        // now pretty it up based on column length
+        int lineStart = 0;
+        int newlinePos = 0;
+        while (lineStart < newComments.length()) {
+            newlinePos = newComments.toString().indexOf("\n", lineStart);
+            if (newlinePos == -1) {
+                newlinePos = newComments.length();
+            }
+            if ((newlinePos - lineStart) > LINE_LENGTH) {
+                // find first whitespace after length
+                lineStart += LINE_LENGTH;
+                while ((lineStart < newComments.length()) 
+                    && !Character.isWhitespace(newComments.charAt(lineStart))) {
+                    lineStart++;
+                }
+
+                if (lineStart < newComments.length()) {
+                    // don't insert if line wold break at EOF
+                    char next = newComments.charAt(lineStart);
+                    // insert new line header
+                    if ((next == '\r') || (next == '\n')) {
+                        //newline exists at the break point, don't put in another one
+                        newComments.insert(lineStart + 1, addTab ? "     * " : " * ");
+                        lineStart += addTab ? 8 : 4;
+                    } else {
+                        newComments.insert(lineStart, addTab ? "\n     * " : "\n * ");
+                        lineStart += addTab ? 8 : 4;
+                    }
+                }
+
+                // chew up witespace after newline
+                while ((lineStart < newComments.length()) 
+                    && (newComments.charAt(lineStart) == ' ')) { // only chew up simple spaces
+                    newComments.delete(lineStart, lineStart + 1);
+                }
+            } else {
+                if (++newlinePos < newComments.length()) {
+                    newComments.insert(newlinePos, addTab ? "     * " : " * ");
+                }
+                lineStart = newlinePos;
+                lineStart += addTab ? 7 : 3;
+            }
+        }
+
+        return newComments.toString();
+    }
+
+    /**
+     * Output a documentation element as a Java comment.
+     *
+     * @param pw
+     * @param element
+     */
+    protected void writeComment(PrintWriter pw, Element element) {
+       writeComment(pw, element, true);
+    }
+
+    /**
+     * Output a documentation element as a Java comment.
+     *
+     * @param pw
+     * @param element
+     * @param addTab
+     */
+    protected void writeComment(PrintWriter pw, Element element, boolean addTab) {
+
+        if (element == null) {
+            return;
+        }
+
+        Node child = element.getFirstChild();
+
+        if (child == null) {
+            return;
+        }
+
+        String comment = child.getNodeValue();
+
+        if (comment != null) {
+            int start = 0;
+
+            pw.println();    // blank line
+
+            pw.println(addTab ? "    /**" : "/**");
+            pw.println(getJavadocDescriptionPart(comment, addTab));
+            pw.println(addTab ? "     */" : " */");
+        }
+    }                        // writeComment
+}    // abstract class JavaWriter

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/NamespaceSelector.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/NamespaceSelector.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/NamespaceSelector.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/NamespaceSelector.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2002,2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+/**
+   This class is used within the context of a FactorySpec to express
+   namespaces that should be either included and/or excluded from source
+   code generation. The ability to include/exclude specific namespaces from
+   wsdl2java generation allows certain namespaces to be mapped to custom
+   bean classes, have wsdl-generated stubs/skeletons declared to pass those
+   types, and not have the wsdl2java process generate classes which would 
+   conflict with the externally developed custom beans.
+
+   @author Jim Stafford (jim.stafford@raba.com)
+*/
+public class NamespaceSelector {
+    private String namespace_ = "";
+    
+    public NamespaceSelector() {}
+    public NamespaceSelector(String namespace) {
+        namespace_ = namespace;
+    }
+    
+    public void setNamespace(String value) {
+        namespace_ = value;
+    }
+    
+    public String getNamespace() {
+        return namespace_;
+    }
+    
+    public String toString() {
+        if (namespace_ != null) {
+            return "namespace=" + namespace_; 
+        }
+        else {
+            return "";
+        }
+    }
+
+    public boolean equals(Object value) {
+        boolean isEqual = false;
+        if (value == null) {
+            isEqual = false;
+        }
+        else if (value instanceof String) {
+            isEqual = ((String)value).equals(namespace_);
+        }
+        else if (value instanceof NamespaceSelector) {
+            isEqual = ((NamespaceSelector)value).namespace_.equals(namespace_);
+        }
+        return isEqual;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Namespaces.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Namespaces.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Namespaces.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Namespaces.java Thu Oct  6 03:54:18 2005
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+package org.apache.axis2.databinding.toJava;
+
+//import org.apache.axis.utils.JavaUtils;
+import org.apache.axis2.databinding.utils.JavaUtils;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * This class is essentially a HashMap of <namespace, package name> pairs with
+ * a few extra wizzbangs.
+ */
+public class Namespaces extends HashMap {
+
+    /** Field root */
+    private String root;
+
+    /** Field defaultPackage */
+    private String defaultPackage = null;
+
+    /** Toknens in a namespace that are treated as package name part separators. */
+    private static final char[] pkgSeparators = {'.', ':'};
+
+    /** Field javaPkgSeparator */
+    private static final char javaPkgSeparator = pkgSeparators[0];
+    
+    /** Field pkg2Namespaces : reverse mapping of Namespaces */
+    private Map pkg2NamespacesMap = new HashMap();
+
+    /**
+     * Method normalizePackageName
+     * 
+     * @param pkg       
+     * @param separator 
+     * @return 
+     */
+    private static String normalizePackageName(String pkg, char separator) {
+
+        for (int i = 0; i < pkgSeparators.length; i++) {
+            pkg = pkg.replace(pkgSeparators[i], separator);
+        }
+
+        return pkg;
+    }
+
+    /**
+     * Instantiate a Namespaces object whose packages will all reside under root.
+     * 
+     * @param root 
+     */
+    public Namespaces(String root) {
+
+        super();
+
+        this.root = root;
+    }    // ctor
+
+    /**
+     * Instantiate a clone of an existing Namespaces object.
+     * 
+     * @param clone 
+     */
+    private Namespaces(Namespaces clone) {
+
+        super(clone);
+
+        this.root = clone.root;
+        this.defaultPackage = clone.defaultPackage;
+    }    // ctor
+
+    /**
+     * Instantiate a clone of this Namespaces object.
+     * 
+     * @return 
+     */
+    public Object clone() {
+        return new Namespaces(this);
+    }    // clone
+
+    /**
+     * Get the package name for the given namespace.  If there is no entry in the HashMap for
+     * this namespace, create one.
+     * 
+     * @param key 
+     * @return 
+     */
+    public String getCreate(String key) {
+        return getCreate(key, true);
+    }    // getCreate
+
+    /**
+     * Get the package name for the given namespace.  If there is no entry in the HashMap for
+     * this namespace, create one if create flag is on, return <tt>null</tt> otherwise.
+     * 
+     * @param key    
+     * @param create 
+     * @return 
+     */
+    String getCreate(String key, boolean create) {
+
+        if (defaultPackage != null) {
+            put(key, defaultPackage);
+            return defaultPackage;
+        }
+
+        String value = (String) super.get(key);
+
+        if ((value == null) && create) {
+            value = normalizePackageName((String) Utils.makePackageName(key),
+                    javaPkgSeparator);
+
+            put(key, value);
+        }
+
+        return (String) value;
+    }    // getCreate
+
+    /**
+     * Get the package name in directory format (dots replaced by slashes).  If the package name
+     * doesn't exist in the HashMap, return "".
+     * 
+     * @param key 
+     * @return 
+     */
+    public String getAsDir(String key) {
+
+        if (defaultPackage != null) {
+            return toDir(defaultPackage);
+        }
+
+        String pkg = (String) get(key);
+
+        return toDir(pkg);
+    }    // getAsDir
+
+    /**
+     * Return the given package name in directory format (dots replaced by slashes).  If pkg is null,
+     * "" is returned.
+     * 
+     * @param pkg 
+     * @return 
+     */
+    public String toDir(String pkg) {
+
+        String dir = null;
+
+        if (pkg != null) {
+            pkg = normalizePackageName(pkg, File.separatorChar);
+        }
+
+        if (root == null) {
+            dir = pkg;
+        } else {
+            dir = root + File.separatorChar + pkg;
+        }
+
+        return (dir == null)
+                ? ""
+                : dir + File.separatorChar;
+    }    // toDir
+
+    /**
+     * Like HashMap's putAll, this adds the given map's contents to this map.  But it
+     * also makes sure the value strings are javified.
+     * 
+     * @param map 
+     */
+    public void putAll(Map map) {
+
+        Iterator i = map.entrySet().iterator();
+
+        while (i.hasNext()) {
+            Map.Entry entry = (Map.Entry) i.next();
+            Object key = entry.getKey();
+            String pkg = (String) entry.getValue();
+
+            pkg = javify(pkg);
+
+            put(key, pkg);
+        }
+    }    // putAll
+
+    /**
+     * Make sure each package name doesn't conflict with a Java keyword.
+     * Ie., org.apache.import.test becomes org.apache.import_.test.
+     * 
+     * @param pkg 
+     * @return 
+     */
+    private String javify(String pkg) {
+
+        StringTokenizer st = new StringTokenizer(pkg, ".");
+
+        pkg = "";
+
+        while (st.hasMoreTokens()) {
+            String token = st.nextToken();
+
+            if (JavaUtils.isJavaKeyword(token)) {
+                token = JavaUtils.makeNonJavaKeyword(token);
+            }
+
+            pkg = pkg + token;
+
+            if (st.hasMoreTokens()) {
+                pkg = pkg + '.';
+            }
+        }
+
+        return pkg;
+    }    // javify
+
+    /**
+     * Make a directory for the given package under root.
+     * 
+     * @param pkg 
+     */
+    public void mkdir(String pkg) {
+
+        String pkgDirString = toDir(pkg);
+        File packageDir = new File(pkgDirString);
+
+        packageDir.mkdirs();
+    }    // mkdir
+
+    /**
+     * Set a package name that overrides the namespace map
+     * 
+     * @param defaultPackage a java package name (e.g. com.foo)
+     */
+    public void setDefaultPackage(String defaultPackage) {
+        this.defaultPackage = defaultPackage;
+    }
+    
+    public Object put(Object key, Object value) {
+        // Store pakcage->namespaces vector mapping
+        Vector v = null;
+        if (!pkg2NamespacesMap.containsKey(value)) {
+            v = new Vector();                       
+        } else {
+            v = (Vector)pkg2NamespacesMap.get(value);
+        }
+        // NOT need to add an input key (namespace value) to v (package vector) 
+        if (!v.contains(key)) { 
+            v.add(key); 
+        }
+        pkg2NamespacesMap.put(value, v);
+         
+        return super.put(key, value);
+    }
+    
+    public Map getPkg2NamespacesMap() {
+        return pkg2NamespacesMap;
+    }
+}    // class Namespaces