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 bu...@apache.org on 2001/10/31 16:18:23 UTC

cvs commit: xml-axis/java/src/org/apache/axis/wsdl JavaTypeWriter.java JavaHolderWriter.java JavaEnumTypeWriter.java JavaComplexTypeWriter.java Type.java JavaWriterFactory.java Emitter.java

butek       01/10/31 07:18:23

  Modified:    java/src/org/apache/axis/wsdl Type.java
                        JavaWriterFactory.java Emitter.java
  Added:       java/src/org/apache/axis/wsdl JavaTypeWriter.java
                        JavaHolderWriter.java JavaEnumTypeWriter.java
                        JavaComplexTypeWriter.java
  Log:
  Another incremental drop of Writer framework code.  Rearranged stuff for
  JavaTypeWriter and company.
  
  Revision  Changes    Path
  1.11      +7 -0      xml-axis/java/src/org/apache/axis/wsdl/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Type.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Type.java	2001/10/30 16:46:42	1.10
  +++ Type.java	2001/10/31 15:18:22	1.11
  @@ -100,6 +100,13 @@
       }
   
       /**
  +     * Set the QName
  +     */
  +    public void setQName(QName qName) {
  +        this.qName = qName;
  +    }
  +
  +    /**
        * Query Java Mapping Name
        */
       public String getJavaName() {
  
  
  
  1.4       +1 -1      xml-axis/java/src/org/apache/axis/wsdl/JavaWriterFactory.java
  
  Index: JavaWriterFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/JavaWriterFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JavaWriterFactory.java	2001/10/30 22:24:56	1.3
  +++ JavaWriterFactory.java	2001/10/31 15:18:22	1.4
  @@ -106,6 +106,6 @@
        * Return Wsdl2java's JavaTypeWriter object.
        */
       public Writer getWriter(Type type) {
  -        return null;//return new JavaTypeWriter(emitter, type);
  +        return new JavaTypeWriter(emitter, type);
       } // getWriter
   } // class JavaWriterFactory
  
  
  
  1.93      +9 -170    xml-axis/java/src/org/apache/axis/wsdl/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Emitter.java,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- Emitter.java	2001/10/30 22:24:56	1.92
  +++ Emitter.java	2001/10/31 15:18:22	1.93
  @@ -835,20 +835,13 @@
   
               HashMap portTypeInfo = (HashMap) portTypesInfo.get(binding.getPortType());
   
  -            writeBinding(binding, portTypeInfo);
  +            HashMap operationParameters = (HashMap) portTypesInfo.get(binding.getPortType());
  +            Writer writer = writerFactory.getWriter(binding, operationParameters);
  +            writer.write();
           }
       } // writeBindings
   
       /**
  -     * Generate a stub and a skeleton for the given binding tag.
  -     */
  -    private void writeBinding(Binding binding, HashMap portTypeInfo) throws IOException {
  -        HashMap operationParameters = (HashMap) portTypesInfo.get(binding.getPortType());
  -        Writer writer = writerFactory.getWriter(binding, operationParameters);
  -        writer.write();
  -    } // writeBinding
  -
  -    /**
        * Create the service class or classes
        */
       private void writeServices() throws IOException {
  @@ -856,17 +849,10 @@
           Iterator i = services.values().iterator();
   
           while (i.hasNext()) {
  -            Service s = (Service) i.next();
  -            writeService(s);
  -        }
  -    }
  -
  -    /**
  -     * Write out a single service class
  -     */
  -    private void writeService(Service service) throws IOException {
  -        Writer writer = writerFactory.getWriter(service, portTypesInfo);
  -        writer.write();
  +            Service service = (Service) i.next();
  +            Writer writer = writerFactory.getWriter(service, portTypesInfo);
  +            writer.write();
  +       }
       }
   
       /**
  @@ -1052,158 +1038,11 @@
           while (i.hasNext()) {
               Type type = (Type) i.next();
               if (type.isDefined() && type.getBaseType() == null) {
  -                writeType(type);
  -                writeHolder(type);
  +                Writer writer = writerFactory.getWriter(type);
  +                writer.write();
               }
           }
       } // writeTypes
  -
  -    /**
  -     * Generate the binding for the given type.
  -     */
  -    private void writeType(Type type) throws IOException {
  -
  -        Node node = type.getNode();
  -
  -        // Generate the proper class for either "complex" or "enumeration" types
  -        Vector v = emitFactory.getComplexElementTypesAndNames(node);
  -        if (v != null)
  -            writeComplexType(type, v);
  -        else {
  -            v = emitFactory.getEnumerationBaseAndValues(node);
  -            if (v != null) {
  -                writeEnumType(type, v);
  -            }
  -        }
  -    } // writeType
  -
  -   /**
  -     * Generate the binding for the given complex type.
  -     * The elements vector contains the Types (even indices) and
  -     * element names (odd indices) of the contained elements
  -     */
  -    private void writeComplexType(Type type, Vector elements) throws IOException {
  -        Node node = type.getNode();
  -
  -        // We are only interested in the java names of the types, so replace the
  -        // Types in the list with their java names.
  -        for (int i=0; i < elements.size(); i+=2) {
  -            elements.setElementAt(((Type) elements.get(i)).getJavaName(), i);
  -        }
  -
  -        String javaName = type.getJavaLocalName();
  -
  -        PrintWriter typePW = printWriter(type.getQName(), null, "java", "Generating type implementation:  ");
  -
  -        writeFileHeader(javaName + ".java", type.getJavaPackageName(), typePW);
  -        typePW.println("public class " + javaName + " implements java.io.Serializable {");
  -
  -        for (int i = 0; i < elements.size(); i += 2) {
  -            String variable = (String) elements.get(i + 1);
  -            if (Utils.isJavaKeyword(variable)) {
  -                variable = Utils.makeNonJavaKeyword(variable);
  -            }
  -            typePW.println("    private " + elements.get(i) + " " + variable + ";");
  -        }
  -
  -        typePW.println();
  -        typePW.println("    public " + javaName + "() {");
  -        typePW.println("    }");
  -        typePW.println();
  -        if (elements.size() > 0) {
  -            typePW.print("    public " + javaName + "(");
  -            for (int i = 0; i < elements.size(); i += 2) {
  -                if (i != 0) typePW.print(", ");
  -                String variable = (String) elements.get(i + 1);
  -                if (Utils.isJavaKeyword(variable)) {
  -                    variable = Utils.makeNonJavaKeyword(variable);
  -                }
  -                typePW.print((String) elements.get(i) + " " + variable);
  -            }
  -            typePW.println(") {");
  -            for (int i = 1; i < elements.size(); i += 2) {
  -                String variable = (String) elements.get(i);
  -                if (Utils.isJavaKeyword(variable)) {
  -                    variable = Utils.makeNonJavaKeyword(variable);
  -                }
  -                typePW.println("        this." + variable + " = " + variable + ";");
  -            }
  -            typePW.println("    }");
  -        }
  -        typePW.println();
  -        for (int i = 0; i < elements.size(); i += 2) {
  -            String typeName = (String) elements.get(i);
  -            String name = (String) elements.get(i + 1);
  -            String capName = Utils.capitalize(name);
  -
  -            if (Utils.isJavaKeyword(name)) {
  -                name = Utils.makeNonJavaKeyword(name);
  -            }
  -            typePW.println("    public " + typeName + " get" + capName + "() {");
  -            typePW.println("        return " + name + ";");
  -            typePW.println("    }");
  -            typePW.println();
  -            typePW.println("    public void set" + capName + "(" + typeName + " " + name + ") {");
  -            typePW.println("        this." + name + " = " + name + ";");
  -            typePW.println("    }");
  -            typePW.println();
  -        }
  -        typePW.println("}");
  -        typePW.close();
  -    } // writeComplexType
  -
  -   /**
  -     * Generate the binding for the given enumeration type.
  -     * The values vector contains the base type (first index) and
  -     * the values (subsequent Strings)
  -     */
  -    private void writeEnumType(Type eType, Vector values) throws IOException {
  -
  -        Node node = eType.getNode();
  -
  -        // The first index is the base type.  Get its java name.
  -        String baseType = ((Type) values.get(0)).getJavaName();
  -
  -        String javaName = eType.getJavaLocalName();
  -
  -        PrintWriter typePW = printWriter(eType.getQName(), null, "java", "Generating enum type implementation:  ");
  -
  -        writeFileHeader(javaName + ".java", eType.getJavaPackageName(), typePW);
  -        typePW.println("public class " + javaName + " implements java.io.Serializable {");
  -        for (int i=1; i < values.size(); i++) {
  -            typePW.println("    public static final " + baseType + " _" + values.get(i)
  -                           + " = \"" + values.get(i) + "\";");
  -        }
  -
  -        typePW.println("}");
  -        typePW.close();
  -    } // writeEnumType
  -
  -    /**
  -     * Generate the holder for the given complex type.
  -     */
  -    private void writeHolder(Type type) throws IOException {
  -        Node node = type.getNode();
  -        String javaName = type.getJavaLocalName();
  -
  -        PrintWriter pw = printWriter(type.getQName(), "Holder", "java", "Generating type implementation holder:  ");
  -
  -        writeFileHeader(javaName + "Holder.java", type.getJavaPackageName(), pw);
  -        pw.println("public final class " + javaName + "Holder implements java.io.Serializable {");
  -        pw.println("    public " + javaName + " _value;");
  -        pw.println();
  -        pw.println("    public " + javaName + "Holder() {");
  -        pw.println("    }");
  -        pw.println();
  -        pw.println("    public " + javaName + "Holder(" + javaName + " value) {");
  -        pw.println("        this._value = value;");
  -        pw.println("    }");
  -        pw.println();
  -        pw.println("    // ??? what else?");
  -        pw.println("}");
  -        pw.close();
  -    } // writeHolder
  -
   
       //
       // Methods using types (non WSDL)
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaTypeWriter.java
  
  Index: JavaTypeWriter.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.wsdl;
  
  import java.io.IOException;
  
  import java.util.Vector;
  
  import javax.wsdl.QName;
  
  import org.w3c.dom.Node;
  
  /**
  * This is Wsdl2java's Type Writer.  It writes the following files, as appropriate:
  * <typeName>.java, <typeName>Holder.java.
  */
  public class JavaTypeWriter implements Writer {
      Writer typeWriter = null;
      Writer holderWriter = null;
  
      /**
       * Constructor.
       */
      protected JavaTypeWriter(
              Emitter emitter,
              Type type) {
          QName typeQName = new QName(type.getQName().getNamespaceURI(), type.getJavaLocalName());
          type.setQName (typeQName);
  
          // Determine what sort of type this is and instantiate the appropriate Writer.
          Node node = type.getNode();
  
          // Generate the proper class for either "complex" or "enumeration" types
          Vector v = emitter.getTypeFactory().getComplexElementTypesAndNames(node);
          if (v != null) {
              typeWriter = new JavaComplexTypeWriter(emitter, type, v);
          }
          else {
              v = emitter.getTypeFactory().getEnumerationBaseAndValues(node);
              if (v != null) {
                  typeWriter = new JavaEnumTypeWriter(emitter, type, v);
              }
          }
  
          holderWriter = new JavaHolderWriter(emitter, type);
      } // ctor
  
      /**
       * Write all the service bindnigs:  service and testcase.
       */
      public void write() throws IOException {
          typeWriter.write();
          if (holderWriter != null) {
              holderWriter.write();
          }
      } // write
  
  } // class JavaTypeWriter
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaHolderWriter.java
  
  Index: JavaHolderWriter.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.wsdl;
  
  import java.io.IOException;
  
  /**
  * This is Wsdl2java's Holder Writer.  It writes the <typeName>Holder.java file.
  */
  public class JavaHolderWriter extends JavaWriter {
      private Type type;
  
      /**
       * Constructor.
       */
      protected JavaHolderWriter(Emitter emitter, Type type) {
          super(emitter, type.getQName(), "Holder", "java", "Generating type implementation holder:  ");
          this.type = type;
      } // ctor
  
      /**
       * Generate the holder for the given complex type.
       */
      protected void writeFileBody() throws IOException {
          String holderType = qname.getLocalPart();
          pw.println("public final class " + className + " implements java.io.Serializable {");
          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();
          pw.println("    // ??? what else?");
          pw.println("}");
          pw.close();
      } // writeOperation
  
  } // class JavaHolderWriter
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaEnumTypeWriter.java
  
  Index: JavaEnumTypeWriter.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.wsdl;
  
  import java.io.IOException;
  
  import java.util.Vector;
  
  import org.w3c.dom.Node;
  
  /**
  * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file.
  */
  public class JavaEnumTypeWriter extends JavaWriter {
      private Type type;
      private Vector elements;
  
      /**
       * Constructor.
       */
      protected JavaEnumTypeWriter(
              Emitter emitter,
              Type type, Vector elements) {
          super(emitter, type.getQName(), "", "java", "Generating type implementation:  ");
          this.type = type;
          this.elements = elements;
      } // ctor
  
     /**
       * Generate the binding for the given enumeration type.
       * The values vector contains the base type (first index) and
       * the values (subsequent Strings)
       */
      protected void writeFileBody() throws IOException {
          Node node = type.getNode();
  
          // The first index is the base type.  Get its java name.
          String baseType = ((Type) elements.get(0)).getJavaName();
  
          pw.println("public class " + className + " implements java.io.Serializable {");
          for (int i=1; i < elements.size(); i++) {
              pw.println("    public static final " + baseType + " _" + elements.get(i)
                             + " = \"" + elements.get(i) + "\";");
          }
  
          pw.println("}");
          pw.close();
      } // writeOperation
  
  } // class JavaEnumTypeWriter
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaComplexTypeWriter.java
  
  Index: JavaComplexTypeWriter.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.wsdl;
  
  import java.io.IOException;
  
  import java.util.Vector;
  
  import javax.wsdl.QName;
  
  import org.w3c.dom.Node;
  
  /**
  * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file.
  */
  public class JavaComplexTypeWriter extends JavaWriter {
      private Type type;
      private Vector elements;
  
      /**
       * Constructor.
       */
      protected JavaComplexTypeWriter(
              Emitter emitter,
              Type type, Vector elements) {
          super(emitter, type.getQName(), "", "java", "Generating type implementation:  ");
          this.type = type;
          this.elements = elements;
      } // ctor
  
     /**
       * Generate the binding for the given complex type.
       * The elements vector contains the Types (even indices) and
       * element names (odd indices) of the contained elements
       */
      protected void writeFileBody() throws IOException {
          Node node = type.getNode();
  
          // We are only interested in the java names of the types, so replace the
          // Types in the list with their java names.
          for (int i=0; i < elements.size(); i+=2) {
              elements.setElementAt(((Type) elements.get(i)).getJavaName(), i);
          }
  
          pw.println("public class " + className + " implements java.io.Serializable {");
  
          for (int i = 0; i < elements.size(); i += 2) {
              String variable = (String) elements.get(i + 1);
              if (Utils.isJavaKeyword(variable)) {
                  variable = Utils.makeNonJavaKeyword(variable);
              }
              pw.println("    private " + elements.get(i) + " " + variable + ";");
          }
  
          pw.println();
          pw.println("    public " + className + "() {");
          pw.println("    }");
          pw.println();
          if (elements.size() > 0) {
              pw.print("    public " + className + "(");
              for (int i = 0; i < elements.size(); i += 2) {
                  if (i != 0) pw.print(", ");
                  String variable = (String) elements.get(i + 1);
                  if (Utils.isJavaKeyword(variable)) {
                      variable = Utils.makeNonJavaKeyword(variable);
                  }
                  pw.print((String) elements.get(i) + " " + variable);
              }
              pw.println(") {");
              for (int i = 1; i < elements.size(); i += 2) {
                  String variable = (String) elements.get(i);
                  if (Utils.isJavaKeyword(variable)) {
                      variable = Utils.makeNonJavaKeyword(variable);
                  }
                  pw.println("        this." + variable + " = " + variable + ";");
              }
              pw.println("    }");
          }
          pw.println();
          for (int i = 0; i < elements.size(); i += 2) {
              String typeName = (String) elements.get(i);
              String name = (String) elements.get(i + 1);
              String capName = Utils.capitalize(name);
  
              if (Utils.isJavaKeyword(name)) {
                  name = Utils.makeNonJavaKeyword(name);
              }
              pw.println("    public " + typeName + " get" + capName + "() {");
              pw.println("        return " + name + ";");
              pw.println("    }");
              pw.println();
              pw.println("    public void set" + capName + "(" + typeName + " " + name + ") {");
              pw.println("        this." + name + " = " + name + ";");
              pw.println("    }");
              pw.println();
          }
          pw.println("}");
          pw.close();
      } // writeOperation
  
  } // class JavaComplexTypeWriter