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 sc...@apache.org on 2002/03/22 15:38:46 UTC

cvs commit: xml-axis/java/test/wsdl/filegen FileGenTestCase.java

scheu       02/03/22 06:38:46

  Modified:    java/src/org/apache/axis/description TypeDesc.java
               java/src/org/apache/axis/wsdl/toJava JavaWriter.java
               java/test/wsdl/clash VerifyFilesTestCase.java
               java/test/wsdl/filegen FileGenTestCase.java
  Added:       java/src/org/apache/axis/wsdl/toJava
                        JavaBeanHelperWriter.java
  Log:
  Added the JavaBeanHelperWriter.java class...duh
  
  Added some more scaffolding code.
  
  Revision  Changes    Path
  1.7       +13 -4     xml-axis/java/src/org/apache/axis/description/TypeDesc.java
  
  Index: TypeDesc.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TypeDesc.java	20 Mar 2002 15:53:44 -0000	1.6
  +++ TypeDesc.java	22 Mar 2002 14:38:45 -0000	1.7
  @@ -74,10 +74,11 @@
   
       /**
        * Static function for centralizing access to type metadata for a
  -     * given class.
  +     * given class.  
        *
  -     * Right now this just checks for a static getTypeDesc() method on the
  -     * class, but we will eventually extend this to provide for external
  +     * This checks for a static getTypeDesc() method on the
  +     * class or _Helper class.
  +     * Eventually we may extend this to provide for external
        * metadata config (via files sitting in the classpath, etc).
        *
        * (Could introduce a cache here for speed as an optimization)
  @@ -87,9 +88,17 @@
           try {
               Method getTypeDesc =
                       cls.getMethod("getTypeDesc", noClasses);
  -            if (getTypeDesc != null)
  +            if (getTypeDesc == null) {
  +                // Look for a Helper Class
  +                ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +                Class helper = Class.forName(cls.getName() + "_Helper", true, cl);
  +                getTypeDesc =
  +                    helper.getMethod("getTypeDesc", noClasses);
  +            }
  +            if (getTypeDesc != null) {
                   return (TypeDesc)getTypeDesc.invoke(null,
                                                       BeanSerializer.noArgs);
  +            }
           } catch (Exception e) {
           }
           return null;
  
  
  
  1.9       +3 -1      xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java
  
  Index: JavaWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JavaWriter.java	21 Mar 2002 22:27:02 -0000	1.8
  +++ JavaWriter.java	22 Mar 2002 14:38:45 -0000	1.9
  @@ -101,6 +101,7 @@
       protected PrintWriter pw;
       protected String      message;
       protected String      type;
  +    protected boolean     embeddedCode = false;
   
       /**
        * Constructor.  Use this one to pass in a Type.  Type contains QName and java name.
  @@ -145,9 +146,10 @@
       } // ctor
   
       /**
  -     * Generate as an inner class
  +     * Generate into an existing class with PrinterWriter pw
        */
       public void write(PrintWriter pw) throws IOException {
  +        embeddedCode = true;  // Indicated embedded
           String packageDirName = namespaces.toDir(packageName);
           String path = packageDirName + fileName;
           String fqClass = packageName + "." + className;
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java
  
  Index: JavaBeanHelperWriter.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.toJava;
  
  import org.apache.axis.utils.JavaUtils;
  import org.w3c.dom.Node;
  
  import javax.xml.rpc.namespace.QName;
  import java.io.IOException;
  import java.util.Vector;
  import java.util.HashMap;
  import java.util.Iterator;
  
  /**
   * This is Wsdl2java's Helper Type Writer.  It writes the <typeName>.java file.
   */
  public class JavaBeanHelperWriter extends JavaWriter {
      private TypeEntry type;
      private Vector elements;
      private Vector attributes;
      private TypeEntry extendType;
      private HashMap elementMappings = null;
  
      /**
       * Constructor.
       * @param emitter   
       * @param type        The type representing this class
       * @param elements    Vector containing the Type and name of each property
       * @param extendType  The type representing the extended class (or null)
       * @param attributes  Vector containing the attribute types and names    
       * @param extendType  The type representing the extended clas (or null)
       */
      protected JavaBeanHelperWriter(
                                     Emitter emitter,
                                     TypeEntry type,
                                     Vector elements,
                                     TypeEntry extendType,
                                     Vector attributes) {
          super(emitter, type, "_Helper", "java",
                JavaUtils.getMessage("genType00"), "helper");
          this.type = type;
          this.elements = elements;
          this.attributes = attributes;
          this.extendType = extendType;
      } // 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 {
  
          if (!embeddedCode) {
              pw.println("public class " + className + " {");
          }
  
          // Build elementMappings
          if (elements != null) {
              for (int i = 0; i < elements.size(); i++) {
                  ElementDecl elem = (ElementDecl)elements.get(i);
                  TypeEntry type = elem.getType();
                  String elemName = elem.getName().getLocalPart();
                  String javaName = Utils.xmlNameToJava(elemName);
                  if (!javaName.equals(elemName)) {
                      // If we did some mangling, make sure we'll write out the XML
                      // the correct way.
                      if (elementMappings == null)
                          elementMappings = new HashMap();
  
                      elementMappings.put(javaName, elem.getName());
                  }
              }
          }
  
          // if we have attributes, create metadata function which returns the
          // list of properties that are attributes instead of elements
  
          if (attributes != null || elementMappings != null) {
              boolean wroteFieldType = false;
              pw.println("    // " + JavaUtils.getMessage("typeMeta"));
              pw.println("    private static org.apache.axis.description.TypeDesc typeDesc =");
              pw.println("        new org.apache.axis.description.TypeDesc();");
              pw.println();
              pw.println("    static {");
  
              if (attributes != null) {
                  for (int i = 0; i < attributes.size(); i += 2) {
                      String attrName = (String) attributes.get(i + 1);
                      String fieldName = Utils.xmlNameToJava(attrName);
                      pw.print("        ");
                      if (!wroteFieldType) {
                          pw.print("org.apache.axis.description.FieldDesc ");
                          wroteFieldType = true;
                      }
                      pw.println("field = new org.apache.axis.description.AttributeDesc();");
                      pw.println("        field.setFieldName(\"" + fieldName + "\");");
                      if (!fieldName.equals(attrName)) {
                          pw.print("        field.setXmlName(");
                          pw.print("new javax.xml.rpc.namespace.QName(null, \"");
                          pw.println(attrName + "\"));");
                      }
                      pw.println("        typeDesc.addFieldDesc(field);");
                  }
              }
  
              if (elementMappings != null) {
                  Iterator i = elementMappings.keySet().iterator();
                  while (i.hasNext()) {
                      String fieldName = (String)i.next();
                      QName xmlName = (QName)elementMappings.get(fieldName);
                      pw.print("        ");
                      if (!wroteFieldType) {
                          pw.print("org.apache.axis.description.FieldDesc ");
                          wroteFieldType = true;
                      }
                      pw.println("field = new org.apache.axis.description.ElementDesc();");
                      pw.println("        field.setFieldName(\"" + fieldName + "\");");
                      pw.print(  "        field.setXmlName(new javax.xml.rpc.namespace.QName(\"");
                      pw.println(xmlName.getNamespaceURI() + "\", \"" +
                                 xmlName.getLocalPart() + "\"));");
                      pw.println("        typeDesc.addFieldDesc(field);");
                  }
              }
  
              pw.println("    };");
              pw.println();
  
              pw.println("    /**");
              pw.println("     * " + JavaUtils.getMessage("returnTypeMeta"));
              pw.println("     */");
              pw.println("    public static org.apache.axis.description.TypeDesc getTypeDesc() {");
              pw.println("        return typeDesc;");
              pw.println("    }");
              pw.println();
          }
          if (!embeddedCode) {
              pw.println("}");
              pw.close();
          }
          
      } // writeFileBody
  
  } // class JavaBeanHelperWriter
  
  
  
  1.4       +9 -0      xml-axis/java/test/wsdl/clash/VerifyFilesTestCase.java
  
  Index: VerifyFilesTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/clash/VerifyFilesTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VerifyFilesTestCase.java	27 Feb 2002 22:08:34 -0000	1.3
  +++ VerifyFilesTestCase.java	22 Mar 2002 14:38:45 -0000	1.4
  @@ -94,6 +94,15 @@
       } // shouldExist
   
       /**
  +     * List of files which may be generated.
  +     */
  +    protected Set mayExist() {
  +        HashSet set = new HashSet();
  +        set.add("SharedName_Type_Helper.java");
  +        return set;
  +    } // shouldExist
  +
  +    /**
        * The directory containing the files that should exist.
        */
       protected String rootDir() {
  
  
  
  1.5       +12 -0     xml-axis/java/test/wsdl/filegen/FileGenTestCase.java
  
  Index: FileGenTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/filegen/FileGenTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileGenTestCase.java	6 Feb 2002 21:08:54 -0000	1.4
  +++ FileGenTestCase.java	22 Mar 2002 14:38:46 -0000	1.5
  @@ -89,6 +89,14 @@
           set.add("ReferenceSoapBindingStub.java");
           return set;
       }
  +    
  +    /**
  +     * List of files which may or may not be generated.
  +     */
  +    protected Set mayExist() {
  +        HashSet set = new HashSet();
  +        return set;
  +    }
   
       /**
        * The directory containing the files that should exist.
  @@ -102,6 +110,7 @@
       public void testFileGen() throws IOException {
           String rootDir = rootDir();
           Set shouldExist = shouldExist();
  +        Set mayExist = mayExist();
   
           // open up the output directory and check what files exist.
           File outputDir = new File(rootDir);
  @@ -113,6 +122,9 @@
           for (int i = 0; i < files.length; ++i) {
               if (shouldExist.contains(files[i])) {
                   shouldExist.remove(files[i]);
  +            } 
  +            else if (mayExist.contains(files[i])) {
  +                mayExist.remove(files[i]);
               }
               else {
                   shouldNotExist.add(files[i]);