axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bu...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/wsdl WriterFactory.java Writer.java JavaWriterFactory.java JavaWriter.java JavaPortTypeWriter.java Wsdl2java.java Utils.java Emitter.java
Date Tue, 30 Oct 2001 13:20:15 GMT
butek       01/10/30 05:20:15

  Modified:    java/src/org/apache/axis/wsdl Wsdl2java.java Utils.java
                        Emitter.java
  Added:       java/src/org/apache/axis/wsdl WriterFactory.java Writer.java
                        JavaWriterFactory.java JavaWriter.java
                        JavaPortTypeWriter.java
  Log:
  First cut at refactoring Emitter.  I've created a Writer framework and implemented the
  JavaPortTypeWriter.  Yet to do:  JavaBindingWriter, JavaServiceWriter, JavaTypeWriter.
  Like JavaPortTypeWriter, the implementation of these will come from the various
  write methods in Emitter.
  
  Revision  Changes    Path
  1.19      +3 -1      xml-axis/java/src/org/apache/axis/wsdl/Wsdl2java.java
  
  Index: Wsdl2java.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Wsdl2java.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Wsdl2java.java	2001/10/26 10:59:29	1.18
  +++ Wsdl2java.java	2001/10/30 13:20:14	1.19
  @@ -153,7 +153,9 @@
           try {
   
               // Instantiate the emitter
  -            Emitter emitter = new Emitter();
  +            JavaWriterFactory writerFactory = new JavaWriterFactory();
  +            Emitter emitter = new Emitter(writerFactory);
  +            writerFactory.setEmitter(emitter);
   
               // Parse the options and configure the emitter as appropriate.
               for (int i = 0; i < size; i++) {
  
  
  
  1.8       +14 -0     xml-axis/java/src/org/apache/axis/wsdl/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Utils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Utils.java	2001/10/23 21:04:54	1.7
  +++ Utils.java	2001/10/30 13:20:14	1.8
  @@ -270,6 +270,20 @@
           return  keyword + keywordSuffix;
        }
   
  +    /**
  +     * Map an XML name to a valid Java identifier
  +     */
  +    public static String xmlNameToJava(String name)
  +    {
  +        char[] nameArray = name.toCharArray();
  +        for(int j = 0, len = name.length(); j < len; ++j) {
  +            char c = nameArray[j];
  +            if( !Character.isLetterOrDigit(c) && c != '_' )
  +                nameArray[j] = '_';
  +        }
  +        return new String(nameArray);
  +    }
  +
       public static String makePackageName(String namespace)
       {
           String hostname = null;
  
  
  
  1.90      +16 -51    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.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- Emitter.java	2001/10/29 16:42:58	1.89
  +++ Emitter.java	2001/10/30 13:20:14	1.90
  @@ -117,15 +117,16 @@
       private boolean bEmitSkeleton = false;
       private boolean bMessageContext = false;
       private boolean bEmitTestCase = false;
  -    private boolean bVerbose = false;
  +    protected boolean bVerbose = false;
       private boolean bGenerateImports = true;
       private String outputDir = null;
       private byte scope = NO_EXPLICIT_SCOPE;
  -    private ArrayList classList = new ArrayList();
  -    private ArrayList fileList = new ArrayList();
  +    protected ArrayList classList = new ArrayList();
  +    protected ArrayList fileList = new ArrayList();
       private Namespaces namespaces = null;
       private HashMap delaySetMap = null;
       private TypeFactory emitFactory = null;
  +    private WriterFactory writerFactory = null;
   
       // portTypesInfo is a Hashmap of <PortType, HashMap2> pairs where HashMap2 is
a
       // Hashmap of <Operation, Parameters> pairs.
  @@ -134,7 +135,8 @@
       /**
        * Default constructor.
        */
  -    public Emitter() {
  +    public Emitter(WriterFactory writerFactory) {
  +        this.writerFactory = writerFactory;
           portTypesInfo = new HashMap();
       } // ctor
   
  @@ -152,6 +154,7 @@
           this.namespaces           = that.namespaces;
           this.emitFactory          = that.emitFactory;
           this.portTypesInfo        = that.portTypesInfo;
  +        this.writerFactory        = that.writerFactory;
       } // ctor
   
       /**
  @@ -509,25 +512,9 @@
        * Generate the interface for the given port type.
        */
       private void writePortType(PortType portType) throws IOException {
  -        QName portTypeQName = portType.getQName();
  -        PrintWriter interfacePW = printWriter(portTypeQName, null, "java", "Generating
portType interface:  ");
  -        String nameValue = xmlNameToJava(portTypeQName.getLocalPart());
  -
  -        writeFileHeader(nameValue + ".java", namespaces.getCreate(portTypeQName.getNamespaceURI()),
interfacePW);
  -        interfacePW.println("public interface " + nameValue + " extends java.rmi.Remote
{");
  -
  -        // Remove Duplicates - happens with only a few WSDL's. No idea why!!! 
  -        // (like http://www.xmethods.net/tmodels/InteropTest.wsdl) 
  -        // TODO: Remove this patch...
  -        // NOTE from RJB:  this is a WSDL4J bug and the WSDL4J guys have been notified.
  -        Iterator operations = (new HashSet(portType.getOperations())).iterator();
  -        while(operations.hasNext()) {
  -            Operation operation = (Operation) operations.next();
  -            writeOperation(portType, operation, portType.getQName().getNamespaceURI(),
interfacePW);
  -        }
  -
  -        interfacePW.println("}");
  -        interfacePW.close();
  +        HashMap operationParameters = (HashMap) portTypesInfo.get(portType);
  +        Writer writer = writerFactory.getWriter(portType, operationParameters);
  +        writer.write();
       } // writePortType
   
       /**
  @@ -536,7 +523,7 @@
       private void writeAxisPortType(PortType portType) throws IOException {
           QName portTypeQName = portType.getQName();
           PrintWriter interfacePW = printWriter(portTypeQName, "Axis", "java", "Generating
server-side PortType interface:  ");
  -        String nameValue = xmlNameToJava(portTypeQName.getLocalPart()) + "Axis";
  +        String nameValue = Utils.xmlNameToJava(portTypeQName.getLocalPart()) + "Axis";
   
           writeFileHeader(nameValue + ".java", namespaces.getCreate(portTypeQName.getNamespaceURI()),
interfacePW);
           interfacePW.println("public interface " + nameValue + " extends java.rmi.Remote
{");
  @@ -904,15 +891,6 @@
       } // partTypes
   
       /**
  -     * This method generates the interface signatures for the given operation.
  -     */
  -    private void writeOperation(PortType portType, Operation operation, String namespace,
PrintWriter interfacePW) throws IOException {
  -        writeComment(interfacePW, operation.getDocumentationElement());
  -        Parameters parms = (Parameters) ((HashMap) portTypesInfo.get(portType)).get(operation);
  -        interfacePW.println(parms.signature + ";");
  -    } // writeOperation
  -
  -    /**
        * This method generates the axis server side impl interface signatures operation.
        */
       private void writeOperationAxisSkelSignatures(PortType portType, Operation operation,
String namespace, PrintWriter interfacePW) throws IOException {
  @@ -925,7 +903,7 @@
        * the fault.
        */
       private String fault(Fault operation, String namespace) throws IOException {
  -        String exceptionName = Utils.capitalize(xmlNameToJava(operation.getName()));
  +        String exceptionName = Utils.capitalize(Utils.xmlNameToJava(operation.getName()));
           QName qname = new QName(namespace, exceptionName);
           PrintWriter pw = printWriter(qname, null, "java", "Generating Fault class:  ");
   
  @@ -992,7 +970,7 @@
               throw new IOException("Emitter failure.  Can't find interal classes for portType
for binding " + bindingQName);
   
           PortType portType = binding.getPortType();
  -        String name = xmlNameToJava(bindingQName.getLocalPart());
  +        String name = Utils.xmlNameToJava(bindingQName.getLocalPart());
           String portTypeName = emitFactory.getJavaName(portType.getQName());
           boolean isRPC = true;
           if (wsdlAttr.getBindingStyle(binding) == WsdlAttributes.STYLE_DOCUMENT) {
  @@ -1453,7 +1431,7 @@
        */
       private void writeService(Service service) throws IOException {
           QName serviceQName = service.getQName();
  -        String serviceName = Utils.capitalize(xmlNameToJava(serviceQName.getLocalPart()));
  +        String serviceName = Utils.capitalize(Utils.xmlNameToJava(serviceQName.getLocalPart()));
           String servicePackage = namespaces.getCreate(serviceQName.getNamespaceURI());
           PrintWriter servicePW = printWriter(serviceQName, null, "java", "Generating service
class:  ");
   
  @@ -1946,7 +1924,7 @@
           String name = qname.getLocalPart();
           // Don't capitalize for deploy.xml and undeploy.xml
           if(name.indexOf("deploy")==-1)
  -            name = Utils.capitalize(xmlNameToJava(name));
  +            name = Utils.capitalize(Utils.xmlNameToJava(name));
           String fileName = name + (suffix == null ? "" : suffix) + '.' + extension;
           String packageName = namespaces.getCreate(qname.getNamespaceURI());
           String packageDirName = namespaces.toDir(packageName);
  @@ -1959,6 +1937,7 @@
           return new PrintWriter(new FileWriter(file));
       } // printWriter
   
  +
       /**
        * output documentation element as a Java comment
        */
  @@ -2023,20 +2002,6 @@
           else
               return typeValue + "Holder";
       } // holder
  -
  -    /**
  -     * Map an XML name to a valid Java identifier
  -     */
  -    private String xmlNameToJava(String name)
  -    {
  -        char[] nameArray = name.toCharArray();
  -        for(int j = 0, len = name.length(); j < len; ++j) {
  -            char c = nameArray[j];
  -            if( !Character.isLetterOrDigit(c) && c != '_' )
  -                nameArray[j] = '_';
  -        }
  -        return new String(nameArray);
  -    }
   
       /**
        * A simple map of the primitive types and their holder objects
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/WriterFactory.java
  
  Index: WriterFactory.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.util.HashMap;
  
  import javax.wsdl.Binding;
  import javax.wsdl.PortType;
  import javax.wsdl.Service;
  
  /**
  * Writer and WriterFactory are part of the Writer framework.  Folks who want
  * to use the emitter to generate stuff from WSDL should do 3 things:
  * 1.  Write implementations of the Writer interface, one each for PortType,
  *     Binding, Service, and Type.  These implementations generate the stuff
  *     for each of these WSDL types.
  * 2.  Write an implementation of the WriterFactory interface that returns
  *     instantiations of these Writer implementations as appropriate.
  * 3.  Implement a class with a main method (like Wsdl2java) that instantiates
  *     an Emitter and passes it the WriterFactory implementation
  */
  
  public interface WriterFactory {
      /**
       * Get a Writer implementation that will generate bindings for the given
       * PortType and HashMap of Parameters keyed off of operations.
       */
      public Writer getWriter(PortType portType, HashMap operationParameters);
  
      /**
       * Get a Writer implementation that will generate bindings for the given
       * Binding and HashMap of Parameters keyed off of operations.
       */
      public Writer getWriter(Binding binding, HashMap operationParameters);
  
      /**
       * Get a Writer implementation that will generate bindings for the given
       * Service.
       */
      public Writer getWriter(Service service);
  
      /**
       * Get a Writer implementation that will generate bindings for the given
       * Type.
       */
      public Writer getWriter(Type type);
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/Writer.java
  
  Index: Writer.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 the interface for all writers.  All writers, very simply, must
  * support a write method.
  *
  * Writer and WriterFactory are part of the Writer framework.  Folks who want
  * to use the emitter to generate stuff from WSDL should do 3 things:
  * 1.  Write implementations of the Writer interface, one each for PortType,
  *     Binding, Service, and Type.  These implementations generate the stuff
  *     for each of these WSDL types.
  * 2.  Write an implementation of the WriterFactory interface that returns
  *     instantiations of these Writer implementations as appropriate.
  * 3.  Implement a class with a main method (like Wsdl2java) that instantiates
  *     an Emitter and passes it the WriterFactory implementation
  */
  public interface Writer {
      /**
       * Write something.
       */
      public void write() throws IOException;
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaWriterFactory.java
  
  Index: JavaWriterFactory.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.util.HashMap;
  
  import javax.wsdl.Binding;
  import javax.wsdl.PortType;
  import javax.wsdl.Service;
  
  /**
  * This is Wsdl2java's implementation of the WriterFactory.
  */
  
  public class JavaWriterFactory implements WriterFactory {
      private Emitter emitter;
  
      /**
       * Default constructor.  Note that this class is unusable until setEmitter
       * is called.
       */
      public JavaWriterFactory() {
      } // ctor
  
      /**
       * Provide the emitter object to this class.
       */
      public void setEmitter(Emitter emitter) {
          this.emitter = emitter;
      } // setEmitter
  
      /**
       * Return Wsdl2java's JavaPortTypeWriter object.
       */
      public Writer getWriter(PortType portType, HashMap operationParameters) {
          return new JavaPortTypeWriter(emitter, portType, operationParameters);
      } // getWriter
  
      /**
       * Return Wsdl2java's JavaBindingWriter object.
       */
      public Writer getWriter(Binding binding, HashMap operationParameters) {
          return null;//new JavaBindingWriter(emitter, binding, operationParameters);
      } // getWriter
  
      /**
       * Return Wsdl2java's JavaServiceWriter object.
       */
      public Writer getWriter(Service service) {
          return null;//return new JavaServiceWriter(emitter, service);
      } // getWriter
  
      /**
       * Return Wsdl2java's JavaTypeWriter object.
       */
      public Writer getWriter(Type type) {
          return null;//return new JavaTypeWriter(emitter, type);
      } // getWriter
  } // class JavaWriterFactory
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaWriter.java
  
  Index: JavaWriter.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.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.wsdl.QName;
  
  import org.w3c.dom.Element;
  
  /**
  * All of Wsdl2java's Writer implementations do some common stuff.  All this
  * common stuff resides in this abstract base class.  All that extensions to
  * this class have to do is implement writeFileBody.
  */
  
  public abstract class JavaWriter implements Writer {
      protected Emitter     emitter;
      protected QName       qname;
      protected Namespaces  namespaces;
      protected String      className;
      protected String      fileName;
      protected String      packageName;
      protected PrintWriter pw;
      protected String      message;
  
      /**
       * Constructor.  Set up all the variables needed to write a file.
       */
      protected JavaWriter(
              Emitter emitter,
              QName qname,
              String suffix,
              String extension,
              String message) {
          this.emitter     = emitter;
          this.qname       = qname;
          this.namespaces  = emitter.getNamespaces();
          this.className   = qname.getLocalPart() + (suffix == null ? "" : suffix);
          this.fileName    = className + '.' + extension;
          this.packageName = namespaces.getCreate(qname.getNamespaceURI());
          this.message     = message;
      } // ctor
  
      /**
       * Create the file, write the header, write the body.
       */
      public void write() throws IOException {
          String packageDirName = namespaces.toDir(packageName);
          emitter.fileList.add(packageDirName + fileName);
          emitter.classList.add(packageName + "." + className);
          File file = new File(packageDirName, fileName);
          if (emitter.bVerbose) {
              System.out.println(message + file.getPath());
          }
          pw = new PrintWriter(new FileWriter(file));
          writeFileHeader();
          writeFileBody();
      } // write
  
      /**
       * Write a common header, including the package name.
       */
      protected void writeFileHeader() throws IOException {
          pw.println("/**");
          pw.println(" * " + fileName);
          pw.println(" *");
          pw.println(" * This file was auto-generated from WSDL");
          pw.println(" * by the Apache Axis Wsdl2java emitter.");
          pw.println(" */");
          pw.println();
  
          // print package declaration
          pw.println("package " + packageName + ";");
          pw.println();
      } // writeFileHeader
  
      /**
       * output documentation element as a Java comment.
       */
      protected void writeComment(PrintWriter pw, Element element) {
          // This controls how many characters per line
          final int LINE_LENGTH = 65;
  
          if (element == null)
              return;
  
          String comment = element.getFirstChild().getNodeValue();
  
          // Strip out stuff that will really mess up our comments
          comment = comment.replace('\r', ' ');
          comment = comment.replace('\n', ' ');
  
          if (comment != null) {
              int start = 0;
  
              pw.println();  // blank line
  
              // make the comment look pretty
              while (start < comment.length()) {
                  int end = start + LINE_LENGTH;
                  if (end > comment.length())
                      end = comment.length();
                  // look for next whitespace
                  while (end < comment.length() &&
                          !Character.isWhitespace(comment.charAt(end))) {
                      end++;
                  }
                  pw.println("    // " + comment.substring(start, end).trim());
                  start = end + 1;
              }
          }
      } // writeComment
  
      /**
       * Write the body of the file.  This is what extenders of this class must
       * implement
       */
      protected abstract void writeFileBody() throws IOException;
  
  } // abstract class JavaWriter
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/JavaPortTypeWriter.java
  
  Index: JavaPortTypeWriter.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.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  
  import javax.wsdl.Operation;
  import javax.wsdl.PortType;
  import javax.wsdl.QName;
  
  /**
  * This is Wsdl2java's PortType Writer.  It writes the <portTypeName>.java file
  * which contains the <portTypeName> interface.
  */
  public class JavaPortTypeWriter extends JavaWriter {
      private PortType portType;
      private HashMap  operationParameters;
  
      /**
       * Constructor.
       */
      protected JavaPortTypeWriter(
              Emitter emitter,
              PortType portType, HashMap operationParameters) {
          super(emitter, new QName(portType.getQName().getNamespaceURI(), Utils.capitalize(Utils.xmlNameToJava(portType.getQName().getLocalPart()))),
"", "java", "Generating portType interface:  ");
          this.portType = portType;
          this.operationParameters = operationParameters;
      } // ctor
  
      /**
       * Write the body of the portType interface file.
       */
      protected void writeFileBody() throws IOException {
          pw.println("public interface " + className + " extends java.rmi.Remote {");
  
          // Remove Duplicates - happens with only a few WSDL's. No idea why!!! 
          // (like http://www.xmethods.net/tmodels/InteropTest.wsdl) 
          // TODO: Remove this patch...
          // NOTE from RJB:  this is a WSDL4J bug and the WSDL4J guys have been notified.
          Iterator operations = (new HashSet(portType.getOperations())).iterator();
          while(operations.hasNext()) {
              Operation operation = (Operation) operations.next();
              writeOperation(portType, operation, qname.getNamespaceURI());
          }
  
          pw.println("}");
          pw.close();
      } // writeFileBody
  
      /**
       * This method generates the interface signatures for the given operation.
       */
      private void writeOperation(PortType portType, Operation operation, String namespace)
throws IOException {
          writeComment(pw, operation.getDocumentationElement());
          Emitter.Parameters parms = (Emitter.Parameters) operationParameters.get(operation);
          pw.println(parms.signature + ";");
      } // writeOperation
  
  } // class JavaPortTypeWriter
  
  
  

Mime
View raw message