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 Russell Butek <bu...@us.ibm.com> on 2002/01/14 20:46:39 UTC

Question about the JavaSkelWriter changes

  Index: JavaSkelWriter.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v

  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JavaSkelWriter.java     12 Jan 2002 16:31:37 -0000     1.6
  +++ JavaSkelWriter.java     14 Jan 2002 19:18:52 -0000     1.7
  @@ -131,8 +131,12 @@
           pw.println("    public String getParameterName(String opName,
int i) {");
           pw.println("        return skel.getParameterName(opName, i);");
           pw.println("    }");
  +        pw.println("    public static String
getParameterNameStatic(String opName, int i) {");
  +        pw.println("        init();");
  +        pw.println("        return skel.getParameterName(opName, i);");
  +        pw.println("    }");
           // Initialize operation parameter names
  -        pw.println("    protected void init() {");
  +        pw.println("    protected static void init() {");
           pw.println("        if (skel != null) ");
           pw.println("            return;");
           pw.println("        skel = new org.apache.axis.wsdl.SkeletonImpl
();");


Shouldn't the init code be in a static block?  Then you can get rid of the
init method and the "if (skel != null)" check.  The way it is now, I THINK
that if you instantiated a skeleton, then called the instance
getParameterName method, it'll fail with a NullPointerException because
skel is still null.  At minimum, I think the instance method should call
the static method.

Russell Butek
butek@us.ibm.com


scheu@apache.org on 01/14/2002 01:18:52 PM

Please respond to axis-dev@xml.apache.org

To:   xml-axis-cvs@apache.org
cc:
Subject:  cvs commit: xml-axis/java/test/wsdl Wsdl2javaTestSuite.xml



scheu       02/01/14 11:18:52

  Modified:    java/src/org/apache/axis/utils JavapUtils.java
               java/src/org/apache/axis/wsdl Skeleton.java
               java/src/org/apache/axis/wsdl/fromJava ClassRep.java
                        MethodRep.java
               java/src/org/apache/axis/wsdl/toJava JavaSkelWriter.java
               java/test/wsdl Wsdl2javaTestSuite.xml
  Log:
  The recent improvements to the generated Skeleton provide an alternate
way
  for Java2WSDL to get parameter names.

  Now Java2WSDL examines the implementation class to see if it is a
Skeleton.
  If so the getParameterName(...) method (or getParameterNameStatic method)
is
  invoked to get the parameter names for the operation.  If this fails, the
  code falls back to using the current lookup using javap and the debug
information in
  the class.

  The advantages of the new code are:
    1) Don't need to compile classes with debug.
    2) You get the name of the return as well as the parms.

  I did some limited testing.

  Note that I made a slight change to the skeleton generation so that a
  getParameterNameStatic method is now emitted...so that Java2WSDL can
  get the parameter names without having to instantiate an actual skeleton
object.

  Revision  Changes    Path
  1.3       +7 -6
xml-axis/java/src/org/apache/axis/utils/JavapUtils.java

  Index: JavapUtils.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/utils/JavapUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JavapUtils.java    14 Jan 2002 16:12:54 -0000     1.2
  +++ JavapUtils.java    14 Jan 2002 19:18:52 -0000     1.3
  @@ -82,10 +82,10 @@
       private static Hashtable cache = new Hashtable();

       /**
  -     * Get the parameter names for the indicated method.
  +     * Get the return/parameter names for the indicated method.
        * Returns null if no parameter names are available or accessible.
        * @param method is the Method
  -     * @return String[] of parameter names or null
  +     * @return String[] of return followed by parameter names (or null)
        **/
       public static String[] getParameterNames(Method method) {
           // Get the javap output
  @@ -94,11 +94,12 @@
               return null;

           // Allocate the parameter names array
  -        int numParams = method.getParameterTypes().length;
  +        int numParams = method.getParameterTypes().length + 1;
           if (numParams ==0)
               return null;
  -        String[] paramNames = new String[numParams];
  -
  +        String[] paramNames = new String[numParams + 1];
  +        paramNames[0] = null;  // Don't know the return name
  +
           // Get the Method signature without modifiers, return type and
throws
           // Also javap puts a space after each comma
           String signature = method.toString();
  @@ -134,7 +135,7 @@
           //   java.lang.Object parameter2  pc=0, length=6, slot=3
           //   short parameter3  pc=0, length=6, slot=4
           //   int localvar  pc=3, length=3, slot=5
  -        int paramIndex = 0;
  +        int paramIndex = 1;
           index++;
           while(paramIndex < paramNames.length && index < text.size()) {
               String line = (String) text.elementAt(index++);



  1.2       +5 -0      xml-axis/java/src/org/apache/axis/wsdl/Skeleton.java

  Index: Skeleton.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Skeleton.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Skeleton.java 12 Jan 2002 16:35:07 -0000     1.1
  +++ Skeleton.java 14 Jan 2002 19:18:52 -0000     1.2
  @@ -63,4 +63,9 @@
        * Returns null if problems occur or the parameter is not known.
        */
       public String getParameterName(String operationName, int n);
  +
  +    /**
  +     * Note: The implementor should also provide a static version of the
  +     * above class named getParameterNameStatic
  +     */
   }



  1.8       +57 -4
xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java

  Index: ClassRep.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ClassRep.java 12 Jan 2002 16:31:37 -0000     1.7
  +++ ClassRep.java 14 Jan 2002 19:18:52 -0000     1.8
  @@ -54,6 +54,7 @@
    */
   package org.apache.axis.wsdl.fromJava;

  +import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
   import java.lang.reflect.Field;
  @@ -62,6 +63,7 @@

   import org.apache.axis.utils.JavapUtils;
   import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.wsdl.Skeleton;

   /**
    * ClassRep is the representation of a class used inside the Java2WSDL
  @@ -215,7 +217,10 @@
               m = cls.getDeclaredMethods();
           for (int i=0; i < m.length; i++) {
               int mod = m[i].getModifiers();
  -            if (Modifier.isPublic(mod)) {
  +            if (Modifier.isPublic(mod) &&
  +                // Ignore the getParameterName method from the Skeleton
class
  +                (!m[i].getName().equals("getParameterName") ||
  +
!(Skeleton.class).isAssignableFrom(m[i].getDeclaringClass()))) {
                   short[] modes = getParameterModes(m[i]);
                   Class[] types = getParameterTypes(m[i]);
                   _methods.add(new MethodRep(m[i], types, modes,
  @@ -334,7 +339,7 @@

       /**
        * Get the list of parameter names for the specified method.
  -     * This implementation uses javap to get the parameter names
  +     * This implementation uses Skeleton.getParameterNames or javap to
get the parameter names
        * from the class file.  If parameter names are not available
        * for the method (perhaps the method is in an interface), the
        * corresponding method in the implClass is queried.
  @@ -342,12 +347,18 @@
        * @param implClass  If the first search fails, the corresponding
        *                   Method in this class is searched.
        * @param types  are the parameter types after converting Holders.
  -     * @return array of parameter names or null.
  +     * @return array of Strings which represent the return name followed
by parameter names
        */
       protected String[] getParameterNames(Method method, Class implClass,
Class[] types) {
           String[] paramNames = null;
  +
  +        paramNames = getParameterNamesFromSkeleton(method);
  +        if (paramNames != null) {
  +            return paramNames;
  +        }
  +
           paramNames = JavapUtils.getParameterNames(method);
  -
  +
           // If failed, try getting a method of the impl class
           // It is possible that the impl class is a skeleton, thus the
           // method may have a different signature (no Holders).  This is
  @@ -373,10 +384,52 @@
                   } catch (Exception e) {}
               }
               if (m != null) {
  +                paramNames = getParameterNamesFromSkeleton(m);
  +                if (paramNames != null) {
  +                    return paramNames;
  +                }
                   paramNames = JavapUtils.getParameterNames(m);
               }
           }

  +        return paramNames;
  +    }
  +
  +    /**
  +     * Get the list of parameter names for the specified method.
  +     * This implementation uses Skeleton.getParameterNames to get the
parameter names
  +     * from the class file.  If parameter names are not available,
returns null.
  +     * @param method is the Method to search.
  +     * @return array of Strings which represent the return name followed
by parameter names
  +     */
  +    protected String[] getParameterNamesFromSkeleton(Method method) {
  +        String[] paramNames = null;
  +        Class cls = method.getDeclaringClass();
  +        Class skel = Skeleton.class;
  +        if (!cls.isInterface() && skel.isAssignableFrom(cls)) {
  +            try {
  +                // Use the getParameterNameStatic method so that we
don't have to new up
  +                // an object.
  +                Method getParameterName = cls.getMethod
("getParameterNameStatic",
  +                                                         new Class []
{String.class, int.class});
  +                Skeleton skelObj = null;
  +                if (getParameterName == null) {
  +                    // Fall back to getting new instance
  +                    skelObj = (Skeleton) cls.newInstance();
  +                    getParameterName = cls.getMethod("getParameterName",
  +                                                     new Class []
{String.class, int.class});
  +                }
  +
  +                int numNames = method.getParameterTypes().length + 1; //
Parms + return
  +                paramNames = new String[numNames];
  +                for (int i=0; i < numNames; i++) {
  +                    paramNames[i] = (String)
getParameterName.invoke(skelObj,
  +                                                                     new
Object[] {method.getName(),
  +
new Integer(i-1)});
  +                }
  +            } catch (Exception e) {
  +            }
  +        }
           return paramNames;
       }




  1.3       +6 -3
xml-axis/java/src/org/apache/axis/wsdl/fromJava/MethodRep.java

  Index: MethodRep.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/MethodRep.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MethodRep.java     3 Jan 2002 20:33:43 -0000      1.2
  +++ MethodRep.java     14 Jan 2002 19:18:52 -0000     1.3
  @@ -84,19 +84,22 @@
        * @param types  This is an array of parameter types
        * @param modes  This is an array of parameter modes (IN, OUT,
INOUT)
        * @param paramNames This is an array of names to be used for the
  -     *                   parameter names.  If null, default names
  +     *                   return/parameter names.  If null, default names
        *                   are constructed.
        */
       public MethodRep(Method method, Class[] types, short[] modes, String
[] paramNames) {
           _name = method.getName();
  -        _returns = new ParamRep("return", method.getReturnType(),
ParamRep.OUT);
  +        String retName = "return";
  +        if (paramNames != null)
  +            retName = paramNames[0];
  +        _returns = new ParamRep(retName, method.getReturnType(),
ParamRep.OUT);

           // Create a ParamRep for each parameter.  The holderClass()
method
           // returns the name of the held type if this is a holder class.
           for (int i=0; i < method.getParameterTypes().length; i++) {
               String name;
               if (paramNames !=null) {
  -                name = (String) paramNames[i];
  +                name = (String) paramNames[i+1];
               } else if (modes[i] == ParamRep.IN) {
                   name = "in" + i;
               } else if (modes[i] == ParamRep.OUT) {



  1.7       +5 -1
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java

  Index: JavaSkelWriter.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v

  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JavaSkelWriter.java     12 Jan 2002 16:31:37 -0000     1.6
  +++ JavaSkelWriter.java     14 Jan 2002 19:18:52 -0000     1.7
  @@ -131,8 +131,12 @@
           pw.println("    public String getParameterName(String opName,
int i) {");
           pw.println("        return skel.getParameterName(opName, i);");
           pw.println("    }");
  +        pw.println("    public static String
getParameterNameStatic(String opName, int i) {");
  +        pw.println("        init();");
  +        pw.println("        return skel.getParameterName(opName, i);");
  +        pw.println("    }");
           // Initialize operation parameter names
  -        pw.println("    protected void init() {");
  +        pw.println("    protected static void init() {");
           pw.println("        if (skel != null) ");
           pw.println("            return;");
           pw.println("        skel = new org.apache.axis.wsdl.SkeletonImpl
();");



  1.55      +3 -4      xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml

  Index: Wsdl2javaTestSuite.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Wsdl2javaTestSuite.xml  11 Jan 2002 21:28:23 -0000     1.54
  +++ Wsdl2javaTestSuite.xml  14 Jan 2002 19:18:52 -0000     1.55
  @@ -103,9 +103,8 @@
           <include name="SequenceInfo.java"/>
         </fileset>
       </copy>
  -    <!-- Compile Java (debug is turned on so that Java2WSDL can access
parm names) -->
  -    <javac srcdir="${build.dir}/work" destdir="${build.dest}"
  -           debug="on">
  +    <!-- Compile Java -->
  +    <javac srcdir="${build.dir}/work" destdir="${build.dest}" debug="
${debug}">
         <classpath refid="test-classpath" />
         <include name="test/wsdl/sequence/**.java" />
         <exclude name="test/wsdl/sequence/*TestCase.java" />
  @@ -114,7 +113,7 @@
       <!-- Now create a WSDL file from the Java classes -->
       <java2wsdl output="build/work/test/wsdl/sequence/SequenceTest.wsdl"
                  className= "test.wsdl.sequence.SequenceTestPortType"
  -               implClass
= "test.wsdl.sequence.SequenceTestSoapBindingImpl"
  +               implClass
= "test.wsdl.sequence.SequenceTestSoapBindingSkeleton"
                  namespace="urn:SequenceTest2"
                  location="
http://localhost:8080/axis/services/SequenceTest">
           <mapping namespace="urn:SequenceTest2" package
="test.wsdl.sequence"/>