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 Tom Jordahl <to...@macromedia.com> on 2003/10/27 17:31:41 UTC

RE: cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava Java StubWriter.java

Eric,

+1

Did you add a test for this code?  That would be a very good thing if we tested this.... :-)


--
Tom Jordahl
Macromedia Server Development

-----Original Message-----
From: ericf@apache.org [mailto:ericf@apache.org] 
Sent: Friday, October 24, 2003 5:07 PM
To: ws-axis-cvs@apache.org
Subject: cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java

ericf       2003/10/24 14:06:30

  Modified:    java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java
  Log:
  fix for 24018 -- when a stub has more than 100 types for which it defines
  metadata, emit code for the metadata in methods that handle no more than
  100 types at a time to avoid writing classes that the VM cannot load
  because the constructor is larger than 64k.  For stubs with less than
  100 types the output is the same as before (binding metadata is
  inlined in the stub constructor).
  
  Revision  Changes    Path
  1.118     +76 -1     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
  
  Index: JavaStubWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
  retrieving revision 1.117
  retrieving revision 1.118
  diff -u -r1.117 -r1.118
  --- JavaStubWriter.java	10 Jul 2003 23:10:53 -0000	1.117
  +++ JavaStubWriter.java	24 Oct 2003 21:06:30 -0000	1.118
  @@ -100,6 +100,11 @@
       private BindingEntry bEntry;
       private Binding binding;
       private SymbolTable symbolTable;
  +    // the maximum number of java type <-> qname binding instructions we'll
  +    // emit in a single method.  This is important for stubs that handle
  +    // a large number of schema types, as the generated source can exceed
  +    // the size in a single method by the VM.
  +    private static final int MAXIMUM_BINDINGS_PER_METHOD = 100;
   
       static String [] modeStrings = new String [] { "",
                                               "org.apache.axis.description.ParameterDesc.IN",
  @@ -185,6 +190,7 @@
           pw.println("            super.service = service;");
           pw.println("        }");
   
  +        List deferredBindings = new ArrayList();
           // keep track of how many type mappings we write out
           int typeMappingCount = 0;
           if (types.size() > 0) {
  @@ -214,7 +220,8 @@
                   }
   
                   // write the type mapping for this type
  -                writeSerializationInit(pw, type);
  +                //writeSerializationInit(pw, type);
  +                deferredBindings.add(type);
   
                   // increase the number of type mappings count
                   typeMappingCount++;
  @@ -227,8 +234,32 @@
               typeMappingCount++;
           }
   
  +        // track whether the number of bindings exceeds the threshold
  +        // that we allow per method.
  +        boolean needsMultipleBindingMethods = false;
  +        if (deferredBindings.size() < MAXIMUM_BINDINGS_PER_METHOD) {
  +            // small number of bindings, just inline them:
  +            for (Iterator it = deferredBindings.iterator(); it.hasNext();) {
  +                writeSerializationInit(pw, (TypeEntry)it.next());
  +            }
  +        } else {
  +            needsMultipleBindingMethods = true;
  +            int methodCount = calculateBindingMethodCount(deferredBindings);
  +
  +            // invoke each of the soon-to-be generated addBindings methods
  +            // from the constructor.
  +            for (int i = 0; i < methodCount; i++) {
  +                pw.println("        addBindings" + i + "();");
  +            }
  +        }
  +
           pw.println("    }");
           pw.println();
  +        // emit any necessary methods for assembling binding metadata.
  +        if (needsMultipleBindingMethods) {
  +            writeBindingMethods(pw, deferredBindings);
  +            pw.println();
  +        }
           pw.println("    private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
           pw.println("        try {");
           pw.println("            org.apache.axis.client.Call _call =");
  @@ -360,6 +391,50 @@
           }
       } // writeFileBody
   
  +    /**
  +     * Compute the number of addBindings methods we need to generate for the
  +     * set of TypeEntries used by the generated stub.
  +     *
  +     * @param deferredBindings a <code>List</code> value
  +     * @return an <code>int</code> value
  +     */
  +    private int calculateBindingMethodCount(List deferredBindings) {
  +        int methodCount = deferredBindings.size() / MAXIMUM_BINDINGS_PER_METHOD;
  +        if ((deferredBindings.size() % MAXIMUM_BINDINGS_PER_METHOD) != 0) {
  +            methodCount++;
  +        }
  +        return methodCount;
  +    }
  +
  +    /**
  +     * for each of the TypeEntry objects in the deferredBindings list, we need
  +     * to write code that will associate a class with a schema namespace/name.
  +     * This method writes a number of private methods out that do this in
  +     * batches of size MAXIMUM_BINDINGS_PER_METHOD so that generated classes
  +     * do not end up with a single method that exceeds the 64K limit that the
  +     * VM imposes on all methods.
  +     *
  +     * @param pw a <code>PrintWriter</code> value
  +     * @param deferredBindings a <code>List</code> of TypeEntry objects
  +     */
  +    private void writeBindingMethods(PrintWriter pw, List deferredBindings) {
  +        int methodCount = calculateBindingMethodCount(deferredBindings);
  +        for (int i = 0; i < methodCount; i++) {
  +            pw.println("    private void addBindings" + i + "() {");
  +            // each method gets its own local variables for use in generating
  +            // the binding code
  +            writeSerializationDecls(pw, false, null);
  +            for (int j = 0; j < MAXIMUM_BINDINGS_PER_METHOD; j++) {
  +                int absolute = i * MAXIMUM_BINDINGS_PER_METHOD + j;
  +                if (absolute == deferredBindings.size()) {
  +                    break;      // last one
  +                }
  +                writeSerializationInit(pw, (TypeEntry) deferredBindings.get(absolute));
  +            }
  +            pw.println("    }");
  +        }
  +    }
  +    
       private void writeOperationMap(PrintWriter pw) {
           List operations = binding.getBindingOperations();
           pw.println("    static {");
  
  
  

Re: cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
> ericf       2003/10/24 14:06:30
>
>   Modified:    java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java
>   Log:
>   fix for 24018 -- when a stub has more than 100 types for which it
defines
>   metadata, emit code for the metadata in methods that handle no more than
>   100 types at a time to avoid writing classes that the VM cannot load
>   because the constructor is larger than 64k.  For stubs with less than
>   100 types the output is the same as before (binding metadata is
>   inlined in the stub constructor).

I missed this - is this some kind of Java restriction - that
constructors can't be larger than 64k?? I don't think I
understand what that means.

Sanjiva.