geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r159005 [8/9] - in geronimo/trunk/modules: assembly/src/plan/ interop/ interop/src/idl/ interop/src/java/org/apache/geronimo/interop/ interop/src/java/org/apache/geronimo/interop/CosNaming/iiop_stubs/ interop/src/java/org/apache/geronimo/interop/adapter/ interop/src/java/org/apache/geronimo/interop/client/ interop/src/java/org/apache/geronimo/interop/generator/ interop/src/java/org/apache/geronimo/interop/naming/ interop/src/java/org/apache/geronimo/interop/properties/ interop/src/java/org/apache/geronimo/interop/repository/ interop/src/java/org/apache/geronimo/interop/rmi/iiop/ interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/ interop/src/java/org/apache/geronimo/interop/rmi/iiop/server/ interop/src/java/org/apache/geronimo/interop/server/ interop/src/java/org/apache/geronimo/interop/util/
Date Fri, 25 Mar 2005 11:54:53 GMT
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java Fri Mar 25 03:54:30 2005
@@ -18,97 +18,74 @@
 package org.apache.geronimo.interop.rmi.iiop.compiler;
 
 import java.lang.reflect.Method;
-import java.util.HashMap;
+import java.util.*;
+import java.io.File;
 
 import org.apache.geronimo.interop.generator.GenOptions;
 import org.apache.geronimo.interop.generator.JParameter;
 import org.apache.geronimo.interop.generator.JVariable;
 
-
 public class Compiler {
-    protected Class _riClass;
-    protected GenOptions _genOptions;
-    protected ClassLoader _cl;
-    protected boolean _simpleIDL = false;
-
-    protected static HashMap _readMethods;
-    protected static HashMap _writeMethods;
-    protected static HashMap _overloadTypes;
+    protected GenOptions      genOptions;
 
-    static {
-        _readMethods = new HashMap();
-        _readMethods.put("boolean", "readBoolean");
-        _readMethods.put("char", "readChar");
-        _readMethods.put("byte", "readByte");
-        _readMethods.put("short", "readShort");
-        _readMethods.put("int", "readInt");
-        _readMethods.put("long", "readLong");
-        _readMethods.put("float", "readFloat");
-        _readMethods.put("double", "readDouble");
-
-        _writeMethods = new HashMap();
-        _writeMethods.put("boolean", "writeBoolean");
-        _writeMethods.put("char", "writeChar");
-        _writeMethods.put("byte", "writeByte");
-        _writeMethods.put("short", "writeShort");
-        _writeMethods.put("int", "writeInt");
-        _writeMethods.put("long", "writeLong");
-        _writeMethods.put("float", "writeFloat");
-        _writeMethods.put("double", "writeDouble");
-
-        _overloadTypes = new HashMap();
-        _overloadTypes.put("boolean", "boolean");
-        _overloadTypes.put("byte", "octet");
-        _overloadTypes.put("char", "wchar");
-        _overloadTypes.put("double", "double");
-        _overloadTypes.put("float", "float");
-        _overloadTypes.put("int", "long");
-        _overloadTypes.put("long", "long_long");
-        _overloadTypes.put("short", "short");
-        _overloadTypes.put("java.lang.Class", "javax_rmi_CORBA.ClassDesc");
-        _overloadTypes.put("java.lang.String", "CORBA.WStringValue");
-        _overloadTypes.put("org.omg.CORBA.Object", "Object");
-        _overloadTypes.put("org.omg.CORBA.Any", "org_omg_boxedIDL_CORBA.Any");
-        _overloadTypes.put("org.omg.CORBA.TypeCode", "org_omg_boxedIDL_CORBA.TypeCode");
-    }
-
-    public Compiler(Class remoteInterface) {
-        this(remoteInterface, null);
-    }
-
-    public Compiler(Class riClass, GenOptions go) {
-        _riClass = riClass;
-
-        _cl = _riClass.getClassLoader();
-        if (_cl == null) {
-            _cl = ClassLoader.getSystemClassLoader();
-        }
-
-        if (go == null) {
-            go = new GenOptions();
-        }
-
-        _genOptions = go;
-    }
-
-    //
-    // Properties
-    //
+    private ClassLoader       classLoader;
+
+    private static HashMap    readMethods;
+    private static HashMap    writeMethods;
+    private static HashMap    overloadTypes;
 
-    public boolean isSimpleIDL() {
-        return _simpleIDL;
+    static {
+        readMethods = new HashMap();
+        readMethods.put("boolean", "readBoolean");
+        readMethods.put("char", "readChar");
+        readMethods.put("byte", "readByte");
+        readMethods.put("short", "readShort");
+        readMethods.put("int", "readInt");
+        readMethods.put("long", "readLong");
+        readMethods.put("float", "readFloat");
+        readMethods.put("double", "readDouble");
+
+        writeMethods = new HashMap();
+        writeMethods.put("boolean", "writeBoolean");
+        writeMethods.put("char", "writeChar");
+        writeMethods.put("byte", "writeByte");
+        writeMethods.put("short", "writeShort");
+        writeMethods.put("int", "writeInt");
+        writeMethods.put("long", "writeLong");
+        writeMethods.put("float", "writeFloat");
+        writeMethods.put("double", "writeDouble");
+
+        overloadTypes = new HashMap();
+        overloadTypes.put("boolean", "boolean");
+        overloadTypes.put("byte", "octet");
+        overloadTypes.put("char", "wchar");
+        overloadTypes.put("double", "double");
+        overloadTypes.put("float", "float");
+        overloadTypes.put("int", "long");
+        overloadTypes.put("long", "long_long");
+        overloadTypes.put("short", "short");
+        overloadTypes.put("java.lang.Class", "javax_rmi_CORBA.ClassDesc");
+        overloadTypes.put("java.lang.String", "CORBA.WStringValue");
+        overloadTypes.put("org.omg.CORBA.Object", "Object");
+        overloadTypes.put("org.omg.CORBA.Any", "org_omg_boxedIDL_CORBA.Any");
+        overloadTypes.put("org.omg.CORBA.TypeCode", "org_omg_boxedIDL_CORBA.TypeCode");
     }
 
-    public void setSimpleIDL(boolean simpleIDL) {
-        _simpleIDL = simpleIDL;
+    public Compiler(GenOptions go, ClassLoader cl) {
+        classLoader = cl;
+        if (classLoader == null) {
+            classLoader = ClassLoader.getSystemClassLoader();
+        }
+
+        genOptions = go;
     }
 
     public GenOptions getGenOptions() {
-        return _genOptions;
+        return genOptions;
     }
 
-    public void setGenOptions(GenOptions genOptions) {
-        _genOptions = genOptions;
+    public ClassLoader getClassLoader() {
+        return classLoader;
     }
 
     public JParameter[] getMethodParms(Method m) {
@@ -131,7 +108,7 @@
         String rc = null;
 
         if (v != null) {
-            rc = (String) _readMethods.get(v.getTypeDecl());
+            rc = (String) readMethods.get(v.getTypeDecl());
         }
 
         return rc;
@@ -141,11 +118,191 @@
         String rc = null;
 
         if (v != null) {
-            rc = (String) _writeMethods.get(v.getTypeDecl());
+            rc = (String) writeMethods.get(v.getTypeDecl());
         }
 
         return rc;
     }
 
+    protected static void error( String errMsg ) {
+        System.err.println( "Error: " + errMsg );
+        System.exit(1);
+    }
+
+    protected void error(String msg, Throwable t) {
+        error(msg);
+        t.printStackTrace();
+    }
+
+    protected static void warn( String warnMsg ) {
+        System.out.println( "Warning: " + warnMsg );
+    }
+
+    protected String adjustPath( String path )
+    {
+        // Maybe it would be easier if GenOptions just made sure that platform path
+        // separators and file separators were as required on the platform?
+        
+        if (File.separatorChar == '/') {
+            // We're under Unix, change '\\' to '/'
+            return path.replace( '\\', '/' );
+        } else {
+            // We're under Windows, change '/' to '\\'
+            return path.replace( '/', '\\' );
+        }
+    }
+
+    protected void addMethodsToList( ArrayList list, Method[] methods )
+    {
+        for(int i=0; list != null && methods != null && i < methods.length; i++ )
+        {
+            list.add( methods[i] );
+        }
+    }
+
+    protected void collectInterfaceMethods( ArrayList list, Class intfClass, boolean simpleIdl )
+    {
+        Method myMethods[] = intfClass.getDeclaredMethods();
+
+        if (!simpleIdl)
+        {
+            addMethodsToList( list, myMethods );
+        }
+
+        Class myInterfaces[] = intfClass.getInterfaces();
+        if (myInterfaces != null && myInterfaces.length > 0)
+        {
+            String opsName = intfClass.getName() + "Operations";
+
+            for (int i = 0; i < myInterfaces.length; i++)
+            {
+                if (simpleIdl)
+                {
+                    // add interface and its Operations, only if there is a coresponding Operations
+                    if (myInterfaces[i].getName().equals(opsName))
+                    {
+                        addMethodsToList( list, myMethods );
+                        addMethodsToList( list, myInterfaces[i].getDeclaredMethods() );
+                        continue;
+                    }
+                    else
+                    {
+                        collectInterfaceMethods( list, myInterfaces[i], simpleIdl );
+                    }
+                }
+                else
+                {
+                    // Collect the interface methods for all interfaces ..
+                    collectInterfaceMethods( list, myInterfaces[i], simpleIdl );
+                }
+            }
+        }
+    }
+
+    protected Method[] getMethods( Class intfClass, GenOptions go )
+    {
+        Method myMethods[] = intfClass.getDeclaredMethods();
+        ArrayList list = new ArrayList( myMethods.length * 2 );
+
+        collectInterfaceMethods( list, intfClass, go.isSimpleIdl() );
+
+        Object[] objs = list.toArray();
+        Method[] methods = new Method[objs.length];
+        System.arraycopy( objs, 0, methods, 0, objs.length );
 
+        return methods;
+    }
+
+    public MethodOverload[] getMethodOverloads( Method methods[] )
+    {
+        HashMap hm = new HashMap( methods.length );
+
+        // Put all the methods into the hashmap
+        for( int i=0; methods != null && i < methods.length; i++ )
+        {
+            ArrayList al = (ArrayList)hm.get( methods[i].getName() );
+            if (al == null)
+            {
+                al = new ArrayList( methods.length );
+                al.add( methods[i] );
+                hm.put( methods[i].getName(), al );
+            }
+            else
+            {
+                al.add( methods[i] );
+            }
+        }
+
+        Set keySet = hm.keySet();
+        ArrayList overloadList = new ArrayList( methods.length );
+        for (Iterator keyIt = keySet.iterator(); keyIt != null && keyIt.hasNext(); )
+        {
+            ArrayList al = (ArrayList)hm.get( keyIt.next() );
+            if (al.size() == 1)
+            {
+                Method m = (Method)al.remove(0);
+                overloadList.add( new MethodOverload( m.getName(), m ) );
+            }
+            else
+            {
+                for( int i=0; i<=al.size(); i++ )
+                {
+                    Method m = (Method)al.remove(0);
+                    overloadList.add( new MethodOverload( overloadMethodName(m), m ) );
+                }
+            }
+        }
+
+        Object obj[] = overloadList.toArray();
+        MethodOverload m[] = new MethodOverload[ obj.length ];
+        System.arraycopy( obj, 0, m, 0, obj.length );
+
+        return m;
+    }
+
+    protected String overloadMethodName( Method m )
+    {
+        Class parms[] = m.getParameterTypes();
+        String name = m.getName() + "_";
+        for( int i=0; i<parms.length; i++ )
+        {
+            name += "_" + parms[i].getName();
+        }
+        return name.replace( '.', '_' );
+    }
+
+    class MethodOverload
+    {
+        public Method method;
+        public String iiop_name;
+
+        public MethodOverload( String iiop_name, Method method )
+        {
+            this.method = method;
+            this.iiop_name = iiop_name;
+        }
+
+        public int hashCode()
+        {
+            return iiop_name.hashCode();
+        }
+
+        public boolean equals( Object other )
+        {
+            if (other instanceof MethodOverload)
+            {
+                MethodOverload mother = (MethodOverload)other;
+                if (iiop_name != null)
+                {
+                    return iiop_name.equals( mother.iiop_name );
+                }
+                else
+                {
+                    return iiop_name == mother.iiop_name;
+                }
+            }
+
+            return false;
+        }
+    }
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java Fri Mar 25 03:54:30 2005
@@ -19,55 +19,45 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.io.File;
+import java.util.*;
 
-import org.apache.geronimo.interop.generator.GenOptions;
-import org.apache.geronimo.interop.generator.JCaseStatement;
-import org.apache.geronimo.interop.generator.JCatchStatement;
-import org.apache.geronimo.interop.generator.JClass;
-import org.apache.geronimo.interop.generator.JCodeStatement;
-import org.apache.geronimo.interop.generator.JConstructor;
-import org.apache.geronimo.interop.generator.JDeclareStatement;
-import org.apache.geronimo.interop.generator.JExpression;
-import org.apache.geronimo.interop.generator.JField;
-import org.apache.geronimo.interop.generator.JLocalVariable;
-import org.apache.geronimo.interop.generator.JMethod;
-import org.apache.geronimo.interop.generator.JPackage;
-import org.apache.geronimo.interop.generator.JParameter;
-import org.apache.geronimo.interop.generator.JReturnType;
-import org.apache.geronimo.interop.generator.JSwitchStatement;
-import org.apache.geronimo.interop.generator.JTryCatchFinallyStatement;
-import org.apache.geronimo.interop.generator.JTryStatement;
-import org.apache.geronimo.interop.generator.JVariable;
-import org.apache.geronimo.interop.generator.JavaGenerator;
-
-
-public class SkelCompiler
-        extends Compiler {
-    protected ValueTypeContext _vtc = new ValueTypeContext();
-    protected static JParameter _objInputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.class, "input");
-    protected static JParameter _objOutputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.class, "output");
-
-    public SkelCompiler(Class remoteInterface) {
-        super(remoteInterface);
-    }
-
-    public SkelCompiler(Class remoteInterface, GenOptions go) {
-        super(remoteInterface, go);
-    }
-
-    //
-    // Methods
-    //
+import org.apache.geronimo.interop.generator.*;
+import org.apache.geronimo.interop.util.JavaClass;
+import org.apache.geronimo.interop.util.ProcessUtil;
+import org.apache.geronimo.interop.adapter.Adapter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SkelCompiler extends Compiler {
+    private final Log log = LogFactory.getLog(SkelCompiler.class);
+
+    private ValueTypeContext      vtc = new ValueTypeContext();
+
+    private static JParameter     objInputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.class, "input");
+    private static JParameter     objOutputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.class, "output");
+
+    private String                  inStreamName = "getInputStream";
+    private String                  outStreamName = "getOutputStream";
+
+    private HashMap                 packages = new HashMap();
+
+    public SkelCompiler(GenOptions go, ClassLoader cl) {
+        super(go, cl);
+    }
 
     public void addMethodGetIds(JClass jc) {
-        /*
-        public String[] getIds()
-        {
-            return _ids;
-        }
-        */
+        //
+        // Method Template:
+        //
+        // public String[] getIds()
+        // {
+        //     return _ids;
+        // }
+        //
 
-        JMethod jm = jc.newMethod(new JReturnType(String.class, true),
+        JMethod jm = jc.newMethod(new JReturnType(String[].class),
                                   "getIds",
                                   (JParameter[]) null,
                                   (Class[]) null);
@@ -76,12 +66,14 @@
     }
 
     public void addMethodRegisterMethod(JClass jc) {
-        /*
-        public void registerMethod( String name, int id )
-        {
-            _methodMap.put( name, new Integer(id) );
-        }
-        */
+        //
+        // Method Template:
+        //
+        // public void registerMethod( String name, int id )
+        // {
+        //     _methodMap.put( name, new Integer(id) );
+        // }
+        //
 
         JMethod jm = jc.newMethod(new JReturnType(void.class),
                                   "registerMethod",
@@ -93,18 +85,20 @@
     }
 
     public void addMethodGetObjectRef(JClass jc, Class c) {
-        /*
-        public ObjectRef $getObjectRef()
-        {
-            ObjectRef or = new ObjectRef();
-            or.$setID("RMI:mark.comps.Add:0000000000000000");
-            or.$setObjectKey( "mark.comps.Add" );
-            return or;
-        }
-        */
+        //
+        // Method Template:
+        //
+        //  public ObjectRef getObjectRef()
+        // {
+        //     ObjectRef or = new ObjectRef();
+        //     or.$setID("RMI:mark.comps.Add:0000000000000000");
+        //     or.$setObjectKey( "mark.comps.Add" );
+        //     return or;
+        // }
+        //
 
-        JMethod jm = jc.newMethod(new JReturnType("ObjectRef"),
-                                  "$getObjectRef",
+        JMethod jm = jc.newMethod(new JReturnType(org.apache.geronimo.interop.rmi.iiop.ObjectRef.class),
+                                  "getObjectRef",
                                   (JParameter[]) null,
                                   (Class[]) null);
 
@@ -115,14 +109,16 @@
     }
 
     public void addMethodGetSkeleton(JClass jc) {
-        /*
-        public RemoteInterface $getSkeleton()
-        {
-            return this;
-        }
-        */
+        //
+        // Method Template
+        //
+        // public RemoteInterface $getSkeleton()
+        // {
+        //     return this;
+        // }
+        //
 
-        JMethod jm = jc.newMethod(new JReturnType("RemoteInterface"),
+        JMethod jm = jc.newMethod(new JReturnType(org.apache.geronimo.interop.rmi.iiop.RemoteInterface.class),
                                   "$getSkeleton",
                                   (JParameter[]) null,
                                   (Class[]) null);
@@ -143,17 +139,20 @@
         return rc;
     }
 
-    public void addMethod(Method m, JClass jc) {
+    public void addMethod(MethodOverload mo, JClass jc, GenOptions go) {
         String invokeCall;
+        Method m = mo.method;
         String name = m.getName();
         JParameter[] sparms = getMethodParms(m);
-        JParameter[] iparms = new JParameter[]{_objInputVar, _objOutputVar};
+        JParameter[] iparms = new JParameter[]{objInputVar, objOutputVar};
+        String vtVarName = null;
+        JCodeStatement codeStmt = null;
 
-        if (!isSimpleIDL() && !throwsAnRMIRemoteException(m)) {
+        if (!go.isSimpleIdl() && !throwsAnRMIRemoteException(m)) {
             error("Method " + m.getName() + " does not throw java.rmi.RemoteException or subclass, unable to generate its skeleton method.");
         }
 
-        JMethod jm = jc.newMethod(new JReturnType(void.class), name, iparms, null);
+        JMethod jm = jc.newMethod(new JReturnType(void.class), mo.iiop_name, iparms, null);
 
         JVariable jrc = null;
         String rc = m.getReturnType().getName();
@@ -161,8 +160,8 @@
             jrc = jm.newLocalVariable(m.getReturnType(), "rc");
         }
 
-        JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement();
-        JTryStatement ts = tcfs.getTryStatement();
+        ArrayList   declareStatementList = new ArrayList( 20 );
+        JStatement  invokeStatement = null;
 
         invokeCall = "_servant." + name + "(";
 
@@ -178,7 +177,7 @@
 
                     jcs = new JCodeStatement("input." + readMethod + "()");
                 } else {
-                    String vtVarName = _vtc.getValueTypeVarName(jc, sparms[i]);
+                    vtVarName = vtc.getValueTypeVarName(jc, sparms[i]);
                     if (vtVarName != null) {
                         jcs = new JCodeStatement("(" + sparms[i].getTypeDecl() + ") input.readObject( " + vtVarName + " )");
                     } else {
@@ -186,7 +185,7 @@
                     }
                 }
 
-                ts.addStatement(new JDeclareStatement(sparms[i], new JExpression(jcs)));
+                declareStatementList.add(new JDeclareStatement(sparms[i], new JExpression(jcs)));
 
                 invokeCall += " " + sparms[i].getName();
                 if (i + 1 < sparms.length) {
@@ -203,37 +202,118 @@
 
         invokeCall = invokeCall + ";";
 
-        ts.addStatement(new JCodeStatement(invokeCall));
-
-        JVariable jv = new JVariable(java.lang.Exception.class, "ex");
-        JCatchStatement cs = tcfs.newCatch(jv);
-        cs.addStatement(new JCodeStatement(jv.getName() + ".printStackTrace();"));
-
-        jv = new JVariable(java.lang.Error.class, "er");
-        cs = tcfs.newCatch(jv);
-        cs.addStatement(new JCodeStatement(jv.getName() + ".printStackTrace();"));
-
-        jm.addStatement(tcfs);
+        invokeStatement = new JCodeStatement(invokeCall);
 
+        JStatement writeResultStatement = null;
         if (jrc != null) {
             String writeMethod = getWriteMethod(jrc);
-            JCodeStatement jcs = null;
+            codeStmt = null;
 
             if (writeMethod != null) {
                 // Primitive Type
                 // Cast not needed since each method returns the primitive datatype.
 
-                jcs = new JCodeStatement("output." + writeMethod + "( " + jrc.getName() + " );");
+                codeStmt = new JCodeStatement("output." + writeMethod + "( " + jrc.getName() + " );");
             } else {
-                String vtVarName = _vtc.getValueTypeVarName(jc, jrc);
+                vtVarName = vtc.getValueTypeVarName(jc, jrc);
+                if (vtVarName != null) {
+                    codeStmt = new JCodeStatement("output.writeObject( " + vtVarName + ", " + jrc.getName() + " );");
+                } else {
+                    codeStmt = new JCodeStatement("// Code Gen Error: Class '" + jrc.getTypeDecl() + " is not a valid value type.");
+                }
+            }
+
+            writeResultStatement = codeStmt;
+        }
+
+        //
+        // The exception handling block:
+        //
+        //            try
+        //            {
+        //                invoke method()
+        //            }
+        //            catch (java.lang.Exception $ex_1)
+        //            {
+        //                Listed here are the individual catches that the method can throw
+        //                if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.NotFound)
+        //                {
+        //                    $output.writeException(type$4, $ex_1);
+        //                    return;
+        //                }
+        //                if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.CannotProceed)
+        //                {
+        //                    $output.writeException(type$5, $ex_1);
+        //                    return;
+        //                }
+        //                throw $ex_1;
+        //            }
+
+        Class[] excepts = m.getExceptionTypes();
+        JVariable jvExcept = null;
+        JVariable jvTmp = null;
+
+        JCatchStatement catchStmt = null;
+
+        if (excepts != null && excepts.length > 0)
+        {
+            JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement();
+            JTryStatement ts = tcfs.getTryStatement();
+
+            if (declareStatementList.size() > 0)
+            {
+                for( int i=0; i<declareStatementList.size(); i++ )
+                {
+                    ts.addStatement( (JStatement)declareStatementList.get(i) );
+                }
+            }
+
+            ts.addStatement( invokeStatement );
+
+            jvExcept = new JVariable(java.lang.Exception.class, "ex");
+            catchStmt = tcfs.newCatch(jvExcept);
+
+            for( int i=0; excepts != null && i < excepts.length; i++ )
+            {
+                jvTmp = new JVariable( excepts[i], "exvar" );
+                vtVarName = vtc.getValueTypeVarName(jc, jvTmp);
+                codeStmt = null;
                 if (vtVarName != null) {
-                    jcs = new JCodeStatement("output.writeObject( " + vtVarName + ", " + jrc.getName() + " );");
+                    codeStmt = new JCodeStatement("output.writeException( " + vtVarName + ", " + jvExcept.getName() + ");" );
                 } else {
-                    jcs = new JCodeStatement("// Code Gen Error: Class '" + jrc.getTypeDecl() + " is not a valid value type.");
+                    codeStmt = new JCodeStatement("// Code Gen Error: Class '" + sparms[i].getTypeDecl() + " is not a valid value type.");
+                }
+
+                JIfStatement ifs = new JIfStatement( new JExpression(
+                        new JCodeStatement( jvExcept.getName() + " instanceof " + excepts[i].getName() ) ));
+                ifs.addStatement( codeStmt );
+                ifs.addStatement( new JCodeStatement( "return;" ));
+                catchStmt.addStatement( ifs );
+            }
+
+            if (writeResultStatement != null)
+            {
+                ts.addStatement( writeResultStatement );
+            }
+
+            jm.addStatement(tcfs);
+        }
+        else
+        {
+            if (declareStatementList.size() > 0)
+            {
+                for( int i=0; i<declareStatementList.size(); i++ )
+                {
+                    jm.addStatement( (JStatement)declareStatementList.get(i) );
                 }
             }
 
-            ts.addStatement(jcs);
+            jm.addStatement( invokeStatement );
+
+            if (writeResultStatement != null)
+            {
+                jm.addStatement( writeResultStatement );
+            }
         }
     }
 
@@ -288,132 +368,203 @@
         return rc;
     }
 
-    protected void error(String msg) {
-        System.out.println("Error: " + msg);
-    }
-
-    protected void error(String msg, Throwable t) {
-        error(msg);
-        t.printStackTrace();
-    }
+    public void generate() throws GenException {
 
-    public void generate()
-            throws Exception {
-        _vtc.clear();
+        GenOptions go = getGenOptions();
+        List interfaces = go.getInterfaces();
+        Iterator intf = null;
 
-        if (!isSimpleIDL() && !isClassARMIRemote(_riClass)) {
-            error("Class '" + _riClass.getName() + "' must be an instance of either java.rmi.Remote or of a subclass.");
+        if (interfaces != null) {
+            intf = interfaces.iterator();
         }
 
-        ClassLoader cl = _riClass.getClassLoader();
-        if (cl == null) {
-            cl = ClassLoader.getSystemClassLoader();
+        JavaGenerator jg = new JavaGenerator(genOptions);
+
+        if (go.isSimpleIdl()) {
+            inStreamName = "getSimpleInputStream";
+            outStreamName = "getSimpleOutputStream";
+        } else {
+            inStreamName = "getInputStream";
+            outStreamName = "getOutputStream";
         }
 
-        String fullGenDir = _genOptions.getGenDir();
+        String riClassName = "";
+        Class  riClass = null;
+        String skelClassName = "";
+        String pkgName = "";
+        JPackage pkg = null;
 
-        JavaGenerator jg = new JavaGenerator(_genOptions);
+        while (intf != null && intf.hasNext() ) {
+            // Clear the value type cache.
+            vtc.clear();
 
-        String className = _riClass.getName();
+            riClassName = (String)intf.next();
 
-        JPackage p = new JPackage("");
-        if (_riClass.getPackage() != null) {
-            p = new JPackage(_riClass.getPackage().getName());
-            className = className.substring(className.lastIndexOf(".") + 1);
-        }
 
-        JClass jc = p.newClass(className + "_Skeleton");
+            try {
+                riClass = getClassLoader().loadClass( riClassName );
+            } catch (Exception ex) {
+                throw new GenException( "Generate Skels Failed:", ex );
+            }
 
-        /*
-        jw.comment( "" );
-        jw.comment( "CORBA RMI-IIOP Skeleton Generator" );
-        jw.comment( "  Interface: " + c.getName() );
-        jw.comment( "  Date: " + (new Date(System.currentTimeMillis())).toString() );
-        jw.comment( "" );
-        */
-
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectInputStream");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectOutputStream");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteObject");
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop.server", "Adapter");
-        jc.addImport("java.util", "HashMap");
-
-        jc.setExtends("RemoteObject");
-        jc.addImplements("RemoteInterface");
-
-        JField idsField = jc.newField(String[].class, "_ids", new JExpression(new JCodeStatement("{ \"" + _riClass.getName() + "\", \"RMI:" + _riClass.getName() + ":0000000000000000\"}")), true);
-        JField methodsField = jc.newField(java.util.HashMap.class, "_methods", new JExpression(new JCodeStatement("new HashMap(10)")));
-        JField servantField = jc.newField(_riClass, "_servant", new JExpression(new JCodeStatement("null")));
-
-        JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null);
-        jcCon.addStatement(new JCodeStatement("super();"));
-
-        addMethodRegisterMethod(jc);
-        addMethodGetIds(jc);
-        addMethodGetSkeleton(jc);
-        addMethodGetObjectRef(jc, _riClass);
-
-        JMethod jmInvoke = jc.newMethod(new JReturnType(void.class),
-                                        "$invoke",
-                                        new JParameter[]{new JParameter(String.class, "methodName"),
-                                                         new JParameter(byte[].class, "objectKey"),
-                                                         new JParameter(Object.class, "instance"),
-                                                         _objInputVar,
-                                                         _objOutputVar},
-                                        (Class[]) null);
-
-        jmInvoke.setModifier(Modifier.PUBLIC, true);
-
-        JLocalVariable jvM = jmInvoke.newLocalVariable(Integer.class, "m", new JExpression(new JCodeStatement("(Integer)_methods.get(methodName)")));
-
-        jmInvoke.addStatement(new JCodeStatement("if (m == null)"));
-        jmInvoke.addStatement(new JCodeStatement("{"));
-        jmInvoke.addStatement(new JCodeStatement("    throw new org.omg.CORBA.BAD_OPERATION(methodName);"));
-        jmInvoke.addStatement(new JCodeStatement("}"));
-        jmInvoke.addStatement(new JCodeStatement(""));
-        jmInvoke.addStatement(new JCodeStatement("_servant = (" + _riClass.getName() + ")instance;"));
-        jmInvoke.addStatement(new JCodeStatement(""));
-        jmInvoke.addStatement(new JCodeStatement("if (m.intValue() < 0)"));
-        jmInvoke.addStatement(new JCodeStatement("{"));
-        jmInvoke.addStatement(new JCodeStatement("    super.invoke( m.intValue(), objectKey, instance, input, output );"));
-        jmInvoke.addStatement(new JCodeStatement("}"));
-        jmInvoke.addStatement(new JCodeStatement(""));
-
-        JSwitchStatement ss = new JSwitchStatement(new JExpression(new JCodeStatement("m.intValue()")));
-        JCaseStatement cs = null;
-        jmInvoke.addStatement(ss);
+            if (!go.isSimpleIdl() && !isClassARMIRemote(riClass)) {
+                error("Class '" + riClass.getName() + "' must be an instance of either java.rmi.Remote or of a subclass.");
+            }
 
-        Method m[] = null;
+            pkgName = JavaClass.getNamePrefix(riClassName);
+            skelClassName = JavaClass.getNameSuffix(riClassName);
+            pkg = (JPackage) packages.get( pkgName );
+            if (pkg == null)
+            {
+                pkg = new JPackage( pkgName );
+                packages.put( pkgName, pkg );
+            }
 
-        if (isSimpleIDL()) {
-            m = _riClass.getMethods();
-        } else {
-            m = _riClass.getDeclaredMethods();
-        }
+            JClass jc = pkg.newClass(skelClassName + "_Skeleton");
 
-        if (m != null && m.length > 0) {
-            int i;
-            for (i = 0; i < m.length; i++) {
+            jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface");
+            jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef");
+            jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteObject");            
+
+            jc.setExtends("RemoteObject");
+            jc.addImplements("RemoteInterface");
+
+            JField idsField = jc.newField(String[].class, "_ids", new JExpression(new JCodeStatement("{ \"" + riClass.getName() + "\", \"RMI:" + riClass.getName() + ":0000000000000000\"}")), true);
+            idsField.setModifiers(Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL);
+
+            JField servantField = jc.newField(riClass, "_servant", new JExpression(new JCodeStatement("null")));
+            servantField.setModifiers(Modifier.PRIVATE);
+
+            JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null);
+            jcCon.addStatement(new JCodeStatement("super();"));
+
+            // Replaced with the method in the RemoteObject parent class
+            //addMethodRegisterMethod(jc);
+
+            addMethodGetIds(jc);
+
+            // Not used anymore
+            //addMethodGetSkeleton(jc);
+
+            addMethodGetObjectRef(jc, riClass);
+
+            JMethod jmInvoke = jc.newMethod(new JReturnType(void.class),
+                                            "invoke",
+                                            new JParameter[]{new JParameter(String.class, "methodName"),
+                                                             new JParameter(byte[].class, "objectKey"),
+                                                             new JParameter(Adapter.class, "adapter"),
+                                                             objInputVar,
+                                                             objOutputVar},
+                                            (Class[]) null);
+
+            jmInvoke.setModifier(Modifier.PUBLIC);
+
+            JLocalVariable jvM = jmInvoke.newLocalVariable(Integer.class, "m", new JExpression(new JCodeStatement("getMethodId(methodName); // (Integer)_methods.get(methodName)")));
+
+            JIfStatement jis = new JIfStatement(new JExpression(new JCodeStatement(jvM.getName() + " == null")));
+            jis.addStatement(new JCodeStatement("throw new org.omg.CORBA.BAD_OPERATION(methodName);"));
+            jmInvoke.addStatement(jis);
+
+            jmInvoke.addStatement(new JCodeStatement("_servant = (" + riClass.getName() + ")adapter.getServant(); //instance;"));
+
+            JIfStatement jis2 = new JIfStatement(new JExpression(new JCodeStatement(jvM.getName() + ".intValue() < 0")));
+            jis2.addStatement(new JCodeStatement("super.invoke( " + jvM.getName() + ".intValue(), objectKey, adapter, input, output );"));
+            jmInvoke.addStatement(jis2);
+
+            JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement();
+            JTryStatement ts = tcfs.getTryStatement();
+
+            JSwitchStatement switchStmt = new JSwitchStatement(new JExpression(new JCodeStatement("m.intValue()")));
+            JCaseStatement caseStmt = null;
+            ts.addStatement(switchStmt);
+
+            Method m[] = getMethods( riClass, go );
+            MethodOverload mo[] = null;
+            mo = getMethodOverloads( m );
+
+            for (int i = 0; mo != null && i < mo.length; i++)
+            {
                 // Enter a new method id in the _methods hashtable.
-                jcCon.addStatement(new JCodeStatement("registerMethod( \"" + m[i].getName() + "\", " + i + ");"));
+                jcCon.addStatement(new JCodeStatement("registerMethod( \"" + mo[i].iiop_name + "\", " + i + ");"));
 
                 // Add a new case statement to the invoke swtich
-                cs = ss.newCase(new JExpression(new JCodeStatement("" + i)));
-                cs.addStatement(new JCodeStatement(m[i].getName() + "(input,output);"));
+                caseStmt = switchStmt.newCase(new JExpression(new JCodeStatement("" + i)));
+                caseStmt.addStatement(new JCodeStatement(mo[i].iiop_name + "(input,output);"));
 
                 // Generate the method wrapper
-                addMethod(m[i], jc);
+                addMethod(mo[i], jc, go);
             }
+
+            JCatchStatement catchStmt = null;
+            JVariable jvExcept = null;
+
+            jvExcept = new JVariable(java.lang.Error.class, "erEx");
+            catchStmt = tcfs.newCatch(jvExcept);
+            catchStmt.addStatement(new JCodeStatement( "throw new org.apache.geronimo.interop.SystemException( " + jvExcept.getName() + " );" ) );
+
+            jvExcept = new JVariable(java.lang.RuntimeException.class, "rtEx");
+            catchStmt = tcfs.newCatch(jvExcept);
+            catchStmt.addStatement(new JCodeStatement( "throw " + jvExcept.getName() + ";" ) );
+
+            jvExcept = new JVariable(java.lang.Exception.class, "exEx");
+            catchStmt = tcfs.newCatch(jvExcept);
+            catchStmt.addStatement(new JCodeStatement( "throw new org.apache.geronimo.interop.SystemException( " + jvExcept.getName() + " );" ) );
+
+            jmInvoke.addStatement( tcfs );
         }
 
-        jg.generate(p);
+        Set pkgSet = packages.keySet();
+        Iterator pkgIt = pkgSet.iterator();
+        String skelPkg = "";
+
+        while (pkgIt.hasNext())
+        {
+            skelPkg = (String) pkgIt.next();
+            pkg = (JPackage)packages.get(skelPkg);
+            System.out.println("Generating Package: " + skelPkg);
+            jg.generate(pkg);
+        }
     }
 
     public void compile()
             throws Exception {
+
+        Set pkg = packages.keySet();
+        Iterator pkgIt = pkg.iterator();
+        String skelPkg = "";
+
+        /*
+         * Each of the packages were generated under go.getGenSrcDir().
+         *
+         * Go through all the packages and run the compiler on *.java
+         */
+
+        GenOptions  go = getGenOptions();
+        String classpath = adjustPath(go.getClasspath());
+        String srcpath = adjustPath(go.getGenSrcDir());
+
+        String filesToCompile = "";
+        String javacCmd = "";
+
+        while (pkgIt.hasNext())
+        {
+            skelPkg = (String) pkgIt.next();
+            skelPkg = skelPkg.replace( '.', File.separatorChar );
+            filesToCompile = adjustPath(go.getGenSrcDir() + File.separator + skelPkg + File.separator + "*.java");
+
+            System.out.println("Compiling Package: " + filesToCompile);
+
+            javacCmd = "javac -d " + go.getGenClassDir() +
+                            ( go.isCompileDebug() ? " -g" : "" ) +
+                            " -classpath " + classpath + " " +
+                            " -sourcepath " + srcpath + " " + filesToCompile;
+
+            System.out.println( "Lauching: " + javacCmd );
+
+            ProcessUtil pu = ProcessUtil.getInstance();
+            pu.setEcho(System.out);
+            pu.run(javacCmd, (String[]) null, "./" );
+        }
     }
 
     public Class getSkelClass() {
@@ -429,62 +580,27 @@
         return c;
     }
 
-    public static void main(String args[])
-            throws Exception {
-        boolean generate = false;
-        boolean compile = false;
-        boolean simpleIDL = false;
-        String ri = "";
-        GenOptions go = new GenOptions();
-
-        go.setGenDir("./src");
-        go.setOverwrite(false);
-        go.setVerbose(false);
-
-        for (int i = 0; i < args.length; i++) {
-            if (args[i].equals("-g")) {
-                generate = true;
-            } else if (args[i].equals("-c")) {
-                compile = true;
-            } else if (args[i].equals("-d") && ((i + 1) < args.length)) {
-                go.setGenDir(args[++i]);
-            } else if (args[i].equals("-v")) {
-                go.setVerbose(true);
-            } else if (args[i].equals("-o")) {
-                go.setOverwrite(true);
-            } else if (args[i].equals("-s")) {
-                simpleIDL = true;
-            } else if (args[i].startsWith("-")) {
-                System.out.println("Warning: Ignoring unrecognized options: '" + args[i] + "'");
-            } else {
-                ri = args[i];
-            }
-        }
-
-        Class riClass = Class.forName(ri);
-
-        SkelCompiler sg = new SkelCompiler(riClass, go);
+    public static void main(String args[]) throws Exception {
+        GenOptions go = null;
 
-        sg.setSimpleIDL(simpleIDL);
+        try
+        {
+            go = new GenOptions( "./skels", args );
+        }
+        catch( GenWarning gw )
+        {
+            gw.printStackTrace();
+        }
 
-        if (generate) {
-            if (go.isVerbose()) {
-                System.out.println("Generating: " + ri);
-            }
+        ClassLoader cl = ClassLoader.getSystemClassLoader();
+        SkelCompiler sg = new SkelCompiler( go, cl );
 
+        if (go.isGenerate()) {
             sg.generate();
         }
 
-        if (compile) {
-            if (go.isVerbose()) {
-                System.out.println("Compiling: " + ri);
-            }
-
+        if (go.isCompile()) {
             sg.compile();
         }
-
-        // sg.setSimpleIDL( true );
-        // sg.generate( "org.apache.geronimo.interop.rmi.iiop.NameServiceOperations");
     }
 }
-

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java Fri Mar 25 03:54:30 2005
@@ -23,56 +23,27 @@
 import org.apache.geronimo.interop.rmi.iiop.RemoteObject;
 import org.apache.geronimo.interop.util.ThreadContext;
 
-
 public class SkelFactory {
-    protected static SkelFactory _sf = new SkelFactory();
+    private static SkelFactory sf = new SkelFactory();
 
     protected SkelFactory() {
     }
 
     public static SkelFactory getInstance() {
-        return _sf;
+        return sf;
     }
 
-    // private data
-
-    private static HashMap _skelClassMap;
-
-    // internal methods
+    private static HashMap skelClassMap;
 
     protected void init() {
-        _skelClassMap = new HashMap();
+        skelClassMap = new HashMap();
     }
 
+    /*
     protected Class loadStub(Class remoteInterface) {
         String className = remoteInterface.getName();
         String skelClassName = className + "_Skeleton";
 
-        /*
-        StubClass sc = new StubClass();
-        if (sc.skelClass == null)
-        {
-            // Try generating skel class now.
-            System.out.println( "TODO: StubFactory.loadStub(): className = " + className );
-            StubCompiler skelCompiler = StubCompiler.getInstance(remoteInterface);
-            sc.skelClass = skelCompiler.getStubClass();
-        }
-
-        if (sc.skelClass != null)
-        {
-            try
-            {
-                sc.getInstance = sc.skelClass.getMethod("$getInstance", ArrayUtil.EMPTY_CLASS_ARRAY);
-            }
-            catch (Exception ex)
-            {
-                throw new SystemException(ex);
-            }
-        }
-
-        return sc;
-        */
-
         Class sc = null;
         try {
             sc = Class.forName(skelClassName);
@@ -84,19 +55,19 @@
 
         return sc;
     }
+    */
 
-    // public methods
-
+    /*
     public RemoteObject getSkel(Class remoteInterface) {
         System.out.println("SkelFactory.getSkel(): remoteInterface: " + remoteInterface);
         try {
-            Class sc = (Class) _skelClassMap.get(remoteInterface);
+            Class sc = (Class) skelClassMap.get(remoteInterface);
             if (sc == null) {
-                synchronized (_skelClassMap) {
-                    sc = (Class) _skelClassMap.get(remoteInterface);
+                synchronized (skelClassMap) {
+                    sc = (Class) skelClassMap.get(remoteInterface);
                     if (sc == null) {
                         sc = loadStub(remoteInterface);
-                        _skelClassMap.put(remoteInterface, sc);
+                        skelClassMap.put(remoteInterface, sc);
                     }
                 }
             }
@@ -106,8 +77,11 @@
             throw new SystemException(ex);
         }
     }
+    */
 
+    /*
     public Object getSkel(String remoteInterface) {
         return getSkel(ThreadContext.loadClass(remoteInterface));
     }
+    */
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubClass.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubClass.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubClass.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubClass.java Fri Mar 25 03:54:30 2005
@@ -21,7 +21,22 @@
 
 
 public class StubClass {
-    public Class stubClass;
+    private Class stubClass;
+    private Method getInstanceMethod;
 
-    public Method getInstance;
+    public StubClass( Class stubClass, Method getInstanceMethod )
+    {
+        this.stubClass = stubClass;
+        this.getInstanceMethod = getInstanceMethod;
+    }
+
+    public Class getStubClass()
+    {
+        return stubClass;
+    }
+
+    public Method getGetInstanceMethod()
+    {
+        return getInstanceMethod;
+    }
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubCompiler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubCompiler.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubCompiler.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubCompiler.java Fri Mar 25 03:54:30 2005
@@ -18,93 +18,65 @@
 package org.apache.geronimo.interop.rmi.iiop.compiler;
 
 import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.geronimo.interop.generator.GenOptions;
-import org.apache.geronimo.interop.generator.JBlockStatement;
-import org.apache.geronimo.interop.generator.JCatchStatement;
-import org.apache.geronimo.interop.generator.JClass;
-import org.apache.geronimo.interop.generator.JCodeStatement;
-import org.apache.geronimo.interop.generator.JConstructor;
-import org.apache.geronimo.interop.generator.JExpression;
-import org.apache.geronimo.interop.generator.JField;
-import org.apache.geronimo.interop.generator.JForStatement;
-import org.apache.geronimo.interop.generator.JIfElseIfElseStatement;
-import org.apache.geronimo.interop.generator.JIfStatement;
-import org.apache.geronimo.interop.generator.JLocalVariable;
-import org.apache.geronimo.interop.generator.JMethod;
-import org.apache.geronimo.interop.generator.JPackage;
-import org.apache.geronimo.interop.generator.JParameter;
-import org.apache.geronimo.interop.generator.JReturnType;
-import org.apache.geronimo.interop.generator.JTryCatchFinallyStatement;
-import org.apache.geronimo.interop.generator.JTryStatement;
-import org.apache.geronimo.interop.generator.JVariable;
-import org.apache.geronimo.interop.generator.JavaGenerator;
+import java.io.File;
+import java.util.*;
+
+import org.apache.geronimo.interop.generator.*;
 import org.apache.geronimo.interop.util.JavaClass;
 import org.apache.geronimo.interop.util.ProcessUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
+public class StubCompiler extends Compiler {
+    private final Log log = LogFactory.getLog(StubCompiler.class);
 
-public class StubCompiler
-        extends Compiler {
-    protected ValueTypeContext _vtc = new ValueTypeContext();
-    protected static JParameter _objInputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.class, "input");
-    protected static JParameter _objOutputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.class, "output");
-
-    protected String _stubClassName = "";
-    protected Class _stubClass = null;
-
-    protected String _inStreamName = "getInputStream";
-    protected String _outStreamName = "getOutputStream";
-
-    public StubCompiler(Class riClass) {
-        super(riClass);
-        init();
-    }
-
-    public StubCompiler(Class riClass, GenOptions go) {
-        super(riClass, go);
-        init();
-    }
-
-    protected void init() {
-        String className = _riClass.getName();
-        _stubClassName = JavaClass.addPackageSuffix(className, "iiop_stubs") + "_Stub";
-    }
+    private ValueTypeContext        vtc = new ValueTypeContext();
 
-    protected void addMethod(JClass jc, JReturnType jrc, String name, JParameter[] jparms, Class[] excepts) {
-//        java.lang.Object $key_1 = $getRequestKey();
-//        for (int $retry = 0; ; $retry++)
-//        {
-//            try
-//            {
-//                org.apache.geronimo.interop.rmi.iiop.client.Connection $connection_2 = this.$connect();
-//                org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream $output_3 = $connection_2.getSimpleOutputStream();  // simple idl
-//                org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream $output_3 = $connection_2.getOutputStream();        // rmi-iiop
-//                $output_3.writeObject(type$1, p1);
-//                $connection_2.invoke(this, "_is_a", $key_1, $retry);
-//                org.apache.geronimo.interop.rmi.iiop.ObjectInputStream $input_4 = $connection_2.getSimpleInputStream();     // simple idl
-//                org.apache.geronimo.interop.rmi.iiop.ObjectInputStream $input_4 = $connection_2.getInputStream();           // rmi-iiop
-//                $connection_2.forget($key_1);
-//                $connection_2.close();
-//                java.lang.String $et_5 = $connection_2.getExceptionType();
-//                if ($et_5 != null)
-//                {
-//                    throw org.apache.geronimo.interop.rmi.iiop.SystemExceptionFactory.getException($connection_2.getException());
-//                }
-//                boolean $djc_result;
-//                $djc_result = $input_4.readBoolean();
-//                return $djc_result;
-//            }
-//            catch (org.apache.geronimo.interop.rmi.iiop.client.RetryInvokeException $ex_6)
-//            {
-//                if ($retry == 3)
-//                {
-//                    throw $ex_6.getRuntimeException();
-//                }
-//            }
-//        }
+    private String                  inStreamName = "getInputStream";
+    private String                  outStreamName = "getOutputStream";
+
+    private HashMap                 packages = new HashMap();
+
+    public StubCompiler(GenOptions go, ClassLoader cl) {
+        super(go, cl);
+    }
+
+    protected void addMethod(JClass jc, String iiopMethodName, JReturnType jrc,
+                             String name, JParameter[] jparms, Class[] excepts) {
+        //
+        // Method Template:
+        //
+        // java.lang.Object $key_1 = $getRequestKey();
+        // for (int $retry = 0; ; $retry++)
+        // {
+        //     try
+        //     {
+        //         org.apache.geronimo.interop.rmi.iiop.client.Connection $connection_2 = this.$connect();
+        //         org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream $output_3 = $connection_2.getSimpleOutputStream();  // simple idl
+        //         org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream $output_3 = $connection_2.getOutputStream();        // rmi-iiop
+        //         $output_3.writeObject(type$1, p1);
+        //         $connection_2.invoke(this, "_is_a", $key_1, $retry);
+        //         org.apache.geronimo.interop.rmi.iiop.ObjectInputStream $input_4 = $connection_2.getSimpleInputStream();     // simple idl
+        //         org.apache.geronimo.interop.rmi.iiop.ObjectInputStream $input_4 = $connection_2.getInputStream();           // rmi-iiop
+        //         $connection_2.forget($key_1);
+        //         $connection_2.close();
+        //         java.lang.String $et_5 = $connection_2.getExceptionType();
+        //         if ($et_5 != null)
+        //         {
+        //             throw org.apache.geronimo.interop.rmi.iiop.SystemExceptionFactory.getException($connection_2.getException());
+        //         }
+        //         boolean $djc_result;
+        //         $djc_result = $input_4.readBoolean();
+        //         return $djc_result;
+        //     }
+        //     catch (org.apache.geronimo.interop.rmi.iiop.client.RetryInvokeException $ex_6)
+        //     {
+        //         if ($retry == 3)
+        //         {
+        //             throw $ex_6.getRuntimeException();
+        //         }
+        //     }
+        // }
 
         //JParameter jpID = new JParameter( java.lang.String.class, "id" );
         JMethod jm = jc.newMethod(jrc, name, jparms, excepts);
@@ -135,7 +107,7 @@
         }
 
         jbs.addStatement(new JCodeStatement(jlvConn.getName() + " = this.$connect();"));
-        jbs.addStatement(new JCodeStatement(jlvOutput.getName() + " = " + jlvConn.getName() + "." + _outStreamName + "();"));
+        jbs.addStatement(new JCodeStatement(jlvOutput.getName() + " = " + jlvConn.getName() + "." + outStreamName + "();"));
 
         String writeMethod = null;
         String writeCall = "";
@@ -145,15 +117,15 @@
             if (writeMethod != null) {
                 writeCall = writeMethod + "( " + jparms[i].getName() + " )";
             } else {
-                writeCall = "writeObject( " + _vtc.getValueTypeVarName(jc, jparms[i]) + ", " + jparms[i].getName() + ")";
+                writeCall = "writeObject( " + vtc.getValueTypeVarName(jc, jparms[i]) + ", " + jparms[i].getName() + ")";
             }
 
             jbs.addStatement(new JCodeStatement(jlvOutput.getName() + "." + writeCall + ";"));
         }
 
-        jbs.addStatement(new JCodeStatement(jlvConn.getName() + ".invoke(this, \"" + name + "\", " + jlvKey.getName() + ", $retry);"));
+        jbs.addStatement(new JCodeStatement(jlvConn.getName() + ".invoke(this, \"" + iiopMethodName + "\", " + jlvKey.getName() + ", $retry);"));
         if (jlvRc != null) {
-            jbs.addStatement(new JCodeStatement(jlvInput.getName() + " = " + jlvConn.getName() + "." + _inStreamName + "();"));
+            jbs.addStatement(new JCodeStatement(jlvInput.getName() + " = " + jlvConn.getName() + "." + inStreamName + "();"));
         }
         jbs.addStatement(new JCodeStatement(jlvConn.getName() + ".forget(" + jlvKey.getName() + ");"));
         jbs.addStatement(new JCodeStatement(jlvConn.getName() + ".close();"));
@@ -171,7 +143,7 @@
             if (readMethod != null) {
                 readCall = jlvInput.getName() + "." + readMethod + "()";
             } else {
-                readCall = "(" + jlvRc.getTypeDecl() + ")" + jlvInput.getName() + "." + "readObject( " + _vtc.getValueTypeVarName(jc, jlvRc) + ")";
+                readCall = "(" + jlvRc.getTypeDecl() + ")" + jlvInput.getName() + "." + "readObject( " + vtc.getValueTypeVarName(jc, jlvRc) + ")";
             }
 
             jbs.addStatement(new JCodeStatement(jlvRc.getName() + " = " + readCall + ";"));
@@ -191,200 +163,167 @@
         jfs.addStatement(tcfs);
     }
 
-    // public methods
-
-    public void addMethod_is_a(JClass jc) {
+    protected void addMethod_is_a(JClass jc) {
         JParameter jpID = new JParameter(java.lang.String.class, "id");
-        addMethod(jc, new JReturnType(boolean.class),
+        addMethod(jc, "_is_a", new JReturnType(boolean.class),
                   "_is_a",
                   new JParameter[]{jpID},
                   (Class[]) null);
 
     }
 
-    public void addMethod(Method m, JClass jc) {
+    protected void addMethod(MethodOverload mo, JClass jc) {
+        Method m = mo.method;
+
         String name = m.getName();
         JParameter[] sparms = getMethodParms(m);
 
-        addMethod(jc, new JReturnType(m.getReturnType()),
+        addMethod(jc, mo.iiop_name, new JReturnType(m.getReturnType()),
                   name,
                   sparms,
                   m.getExceptionTypes());
 
     }
 
-    protected Method[] getMethods() {
-        Method myMethods[] = _riClass.getDeclaredMethods();
-        Method myOpsMethods[] = null;
-        Class myInterfaces[] = _riClass.getInterfaces();
-
-        if (myInterfaces != null && myInterfaces.length > 0) {
-            String opsName = _riClass.getName() + "Operations";
-
-            for (int i = 0; i < myInterfaces.length; i++) {
-                if (myInterfaces[i].getName().equals(opsName)) {
-                    myOpsMethods = myInterfaces[i].getDeclaredMethods();
-                    break;
-                }
-            }
-        }
-
-        Method m[] = null;
+    public void generate() throws GenException {
+        GenOptions go = getGenOptions();
+        List interfaces = go.getInterfaces();
+        Iterator intf = null;
 
-        if (myOpsMethods == null) {
-            m = myMethods;
-        } else {
-            m = new Method[myMethods.length + myOpsMethods.length];
-            System.arraycopy(myMethods, 0, m, 0, myMethods.length);
-            System.arraycopy(myOpsMethods, 0, m, myMethods.length, myOpsMethods.length);
+        if (interfaces != null) {
+            intf = interfaces.iterator();
         }
 
-        return m;
-    }
-
-    public void generate()
-            throws Exception {
-        _vtc.clear();
+        JavaGenerator jg = new JavaGenerator(genOptions);
 
-        if (_simpleIDL) {
-            _inStreamName = "getSimpleInputStream";
-            _outStreamName = "getSimpleOutputStream";
+        if (go.isSimpleIdl()) {
+            inStreamName = "getSimpleInputStream";
+            outStreamName = "getSimpleOutputStream";
+        } else {
+            inStreamName = "getInputStream";
+            outStreamName = "getOutputStream";
         }
 
-        JavaGenerator jg = new JavaGenerator(_genOptions);
-
-        String className;
-        JPackage p = new JPackage(JavaClass.getNamePrefix(_stubClassName));
-        className = JavaClass.getNameSuffix(_stubClassName);
+        String riClassName = "";
+        Class  riClass = null;
+        String stubClassName = "";
+        JPackage pkg = null;
 
-        JClass jc = p.newClass(className);
-        jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef");
-        jc.setExtends("ObjectRef");
-        jc.addImplements(_riClass.getName());
+        while (intf != null && intf.hasNext() ) {
+            // Clear the value type cache.
+            vtc.clear();
 
-        JField idsField = jc.newField(String[].class, "_ids", new JExpression(new JCodeStatement("{ \"" + _riClass.getName() + "\", \"RMI:" + _riClass.getName() + ":0000000000000000\"}")), true);
+            riClassName = (String)intf.next();
+            stubClassName = JavaClass.addPackageSuffix(riClassName, "iiop_stubs") + "_Stub";
 
-        JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null);
-        jcCon.addStatement(new JCodeStatement("super();"));
+            try {
+                riClass = getClassLoader().loadClass( riClassName );
+            } catch (Exception ex) {
+                throw new GenException( "Generate Stubs Failed:", ex );
+            }
 
-        addMethod_is_a(jc);
+            String pkgName = JavaClass.getNamePrefix(stubClassName);
+            pkg = (JPackage) packages.get( pkgName );
+            if (pkg == null)
+            {
+                pkg = new JPackage( pkgName );
+                packages.put( pkgName, pkg );
+            }
 
-        Method m[] = null;
-        m = getMethods();
-        for (int i = 0; m != null && i < m.length; i++) {
-            addMethod(m[i], jc);
+            String className = JavaClass.getNameSuffix(stubClassName);
+            JClass jc = pkg.newClass(className);
+            jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef");
+            jc.setExtends("ObjectRef");
+            jc.addImplements(riClass.getName());
+
+            JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null);
+            jcCon.addStatement(new JCodeStatement("super();"));
+
+            addMethod_is_a(jc);
+
+            Method m[] = getMethods( riClass, go );
+            MethodOverload mo[] = null;
+            mo = getMethodOverloads( m );
+            for (int i = 0; mo != null && i < mo.length; i++) {
+                addMethod( mo[i], jc );
+            }
         }
 
-        jg.generate(p);
+        Set pkgSet = packages.keySet();
+        Iterator pkgIt = pkgSet.iterator();
+        String stubPkg = "";
+
+        while (pkgIt.hasNext())
+        {
+            stubPkg = (String) pkgIt.next();
+            pkg = (JPackage)packages.get(stubPkg);
+            System.out.println("Generating Package: " + stubPkg);
+            jg.generate(pkg);
+        }
     }
 
     public void compile()
             throws Exception {
-        String className = _riClass.getName();
-        String stubClassName = JavaClass.addPackageSuffix(className, "iiop_stubs");
-        String stubPackage = JavaClass.getNamePrefix(stubClassName);
-
-        System.out.println("Compiling Package: " + stubPackage);
-        System.out.println("Compiling Stub: " + stubClassName);
-
-        String javac = "javac -d ../classes -classpath ../classes;D:/Dev/3rdparty.jag/ejb21/ejb-2_1-api.jar " + stubPackage.replace('.', '/') + "/*.java";
-
-        ProcessUtil pu = ProcessUtil.getInstance();
-        pu.setEcho(System.out);
-        pu.run(javac, (String[]) null, "./src");
-    }
 
-    public Class getStubClass() {
-        System.out.println("StubCompiler.getStubClass(): riClass: " + _riClass);
+        Set pkg = packages.keySet();
+        Iterator pkgIt = pkg.iterator();
+        String stubPkg = "";
 
-        if (_stubClass == null) {
-            try {
-                _stubClass = Class.forName(_stubClassName);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+        /*
+         * Each of the packages were generated under go.getGenSrcDir().
+         *
+         * Go through all the packages and run the compiler on *.java
+         */
 
-            try {
-                if (_stubClass == null) {
-                    generate();
-                    compile();
-                    _stubClass = Class.forName(_stubClassName);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
+        GenOptions  go = getGenOptions();
+        String classpath = adjustPath(go.getClasspath());
+        String srcpath = adjustPath(go.getGenSrcDir());
 
-        return _stubClass;
-    }
+        String filesToCompile = "";
+        String javacCmd = "";
 
-    public static void main(String args[])
-            throws Exception {
-        boolean generate = false;
-        boolean compile = false;
-        boolean loadclass = false;
-        boolean simpleidl = false;
-        List interfaces = new LinkedList();
-        GenOptions go = new GenOptions();
-
-        go.setGenDir("./");
-        go.setOverwrite(false);
-        go.setVerbose(false);
-
-        for (int i = 0; i < args.length; i++) {
-            if (args[i].equals("-g")) {
-                generate = true;
-            } else if (args[i].equals("-c")) {
-                compile = true;
-            } else if (args[i].equals("-l")) {
-                loadclass = true;
-            } else if (args[i].equals("-s")) {
-                simpleidl = true;
-            } else if (args[i].equals("-d") && ((i + 1) < args.length)) {
-                go.setGenDir(args[++i]);
-            } else if (args[i].equals("-v")) {
-                go.setVerbose(true);
-            } else if (args[i].equals("-o")) {
-                go.setOverwrite(true);
-            } else if (args[i].startsWith("-")) {
-                System.out.println("Warning: Ignoring unrecognized options: '" + args[i] + "'");
-            } else {
-                interfaces.add(args[i]);
-            }
-        }
+        while (pkgIt.hasNext())
+        {
+            stubPkg = (String) pkgIt.next();
+            stubPkg = stubPkg.replace( '.', File.separatorChar );
+            filesToCompile = adjustPath(go.getGenSrcDir() + File.separator + stubPkg + File.separator + "*.java");
 
-        Iterator i = interfaces.iterator();
-        while (i != null && i.hasNext()) {
-            String intfName = (String) i.next();
-
-            if (intfName.startsWith("RMI:")) {
-                simpleidl = false;
-                intfName = intfName.substring(4);
-            } else if (intfName.startsWith("IDL:")) {
-                simpleidl = true;
-                intfName = intfName.substring(4);
-            }
+            System.out.println("Compiling Package: " + filesToCompile);
 
-            Class riClass = Class.forName(intfName);
-            StubCompiler sg = new StubCompiler(riClass, go);
-            sg.setSimpleIDL(simpleidl);
+            javacCmd = "javac -d " + go.getGenClassDir() +
+                            ( go.isCompileDebug() ? " -g" : "" ) +
+                            " -classpath " + classpath + " " +
+                            " -sourcepath " + srcpath + " " + filesToCompile;
 
-            if (generate) {
-                sg.generate();
-            }
+            System.out.println( "Lauching: " + javacCmd );
 
-            if (compile) {
-                sg.compile();
-            }
+            ProcessUtil pu = ProcessUtil.getInstance();
+            pu.setEcho(System.out);
+            pu.run(javacCmd, (String[]) null, "./" );
+        }
+    }
 
-            if (loadclass) {
-                Class c = sg.getStubClass();
-                System.out.println("StubClass: " + c);
-            }
+    public static void main(String args[]) throws Exception {
+        GenOptions go = null;
+
+        try
+        {
+            go = new GenOptions( "./stubs", args );
+        }
+        catch( GenWarning gw )
+        {
+            gw.printStackTrace();
         }
 
-        // sg.setSimpleIDL( true );
-        // sg.generate( "org.apache.geronimo.interop.rmi.iiop.NameServiceOperations");
-    }
+        ClassLoader cl = ClassLoader.getSystemClassLoader();
+        StubCompiler sg = new StubCompiler( go, cl );
+
+        if (go.isGenerate()) {
+            sg.generate();
+        }
 
+        if (go.isCompile()) {
+            sg.compile();
+        }
+    }
 }

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubFactory.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubFactory.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/StubFactory.java Fri Mar 25 03:54:30 2005
@@ -24,34 +24,29 @@
 import org.apache.geronimo.interop.util.JavaClass;
 import org.apache.geronimo.interop.util.ThreadContext;
 
-
 public class StubFactory {
-    protected static StubFactory _sf;
+    protected static StubFactory sf;
 
     protected StubFactory() {
     }
 
     public static StubFactory getInstance() {
-        if (_sf == null) {
+        if (sf == null) {
             synchronized (StubFactory.class) {
-                if (_sf == null) {
-                    _sf = new StubFactory();
-                    _sf.init();
+                if (sf == null) {
+                    sf = new StubFactory();
+                    sf.init();
                 }
             }
         }
 
-        return _sf;
+        return sf;
     }
 
-    // private data
-
-    private static HashMap _stubClassMap;
-
-    // internal methods
+    private static HashMap stubClassMap;
 
     protected void init() {
-        _stubClassMap = new HashMap();
+        stubClassMap = new HashMap();
     }
 
     protected Class loadStub(Class remoteInterface) {
@@ -76,9 +71,9 @@
             // Try generating stub class now.
             //
 
-            StubCompiler stubCompiler = new StubCompiler(remoteInterface);
-            System.out.println("StubFactory.loadStub(): stubCompiler: " + stubCompiler);
-            sc = stubCompiler.getStubClass();
+            //StubCompiler stubCompiler = new StubCompiler(remoteInterface);
+            //System.out.println("StubFactory.loadStub(): stubCompiler: " + stubCompiler);
+            //sc = stubCompiler.getStubClass();
             System.out.println("StubFactory.loadStub(): sc: " + sc);
         }
 
@@ -99,20 +94,18 @@
         return sc;
     }
 
-    // public methods
-
     public ObjectRef getStub(Class remoteInterface) {
         System.out.println("StubFactory.getStub(): remoteInterface: " + remoteInterface);
         try {
-            Class sc = (Class) _stubClassMap.get(remoteInterface);
+            Class sc = (Class) stubClassMap.get(remoteInterface);
             System.out.println("StubFactory.getStub(): sc: " + sc);
             if (sc == null) {
-                synchronized (_stubClassMap) {
-                    sc = (Class) _stubClassMap.get(remoteInterface);
+                synchronized (stubClassMap) {
+                    sc = (Class) stubClassMap.get(remoteInterface);
                     if (sc == null) {
                         sc = loadStub(remoteInterface);
                         System.out.println("StubFactory.getStub(): sc: " + sc);
-                        _stubClassMap.put(remoteInterface, sc);
+                        stubClassMap.put(remoteInterface, sc);
                     }
                 }
             }



Mime
View raw message