geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r191366 - in /geronimo/trunk/modules/interop: ./ src/java/org/apache/geronimo/interop/generator/ src/java/org/apache/geronimo/interop/rmi/iiop/portable/ src/test-data/ src/test-data/META-INF/ src/test-resources/
Date Sun, 19 Jun 2005 22:25:21 GMT
Author: dain
Date: Sun Jun 19 15:25:18 2005
New Revision: 191366

URL: http://svn.apache.org/viewcvs?rev=191366&view=rev
Log:
Added portable stub generator
PortableStubCompiler contains utility methods to mangle overloaded operation names
Added name manger tests

Added:
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/IiopOperation.java
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/PortableStubCompiler.java
    geronimo/trunk/modules/interop/src/test-data/
      - copied from r190662, geronimo/trunk/modules/interop/src/test-resources/
    geronimo/trunk/modules/interop/src/test-data/nameMangler.properties
Removed:
    geronimo/trunk/modules/interop/project.properties
    geronimo/trunk/modules/interop/src/test-data/META-INF/
    geronimo/trunk/modules/interop/src/test-resources/
Modified:
    geronimo/trunk/modules/interop/project.xml
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/generator/GenOptions.java

Modified: geronimo/trunk/modules/interop/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/project.xml?rev=191366&r1=191365&r2=191366&view=diff
==============================================================================
--- geronimo/trunk/modules/interop/project.xml (original)
+++ geronimo/trunk/modules/interop/project.xml Sun Jun 19 15:25:18 2005
@@ -88,25 +88,4 @@
             <version>${mx4j_version}</version>
         </dependency>
     </dependencies>
-
-
-    <!-- =================== -->
-    <!-- Build Specification -->
-    <!-- =================== -->
-
-    <build>
-        <unitTest>
-            <includes>
-                <include>**/*Test.java</include>
-            </includes>
-            <excludes>
-                <exclude>**/Abstract*.java</exclude>
-            </excludes>
-            <resources>
-                <resource>
-                    <directory>${basedir}/src/test-resources</directory>
-                </resource>
-            </resources>
-        </unitTest>
-    </build>
 </project>

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/generator/GenOptions.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/generator/GenOptions.java?rev=191366&r1=191365&r2=191366&view=diff
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/generator/GenOptions.java
(original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/generator/GenOptions.java
Sun Jun 19 15:25:18 2005
@@ -17,11 +17,8 @@
  */
 package org.apache.geronimo.interop.generator;
 
-import org.apache.geronimo.interop.rmi.iiop.compiler.StubCompiler;
-
-import java.util.List;
 import java.util.LinkedList;
-import java.util.Iterator;
+import java.util.List;
 
 public class GenOptions {
     // -gs  genSrcDir
@@ -35,70 +32,116 @@
     // -cd  compiledebug
     // -lc  loadclass
 
-    private String      genSrcDir = "./src";
-    private String      genClassDir = "./classes";
-    private boolean     overwrite = false;
-    private boolean     verbose = false;
-    private boolean     simpleidl = false;
-    private String      classpath = "";
-    private boolean     generate = true;
-    private boolean     compile = false;
-    private boolean     compileDebug = false;
-    private boolean     loadclass = false;
+    private String genSrcDir = "./src";
+    private String genClassDir = "./classes";
+    private boolean overwrite = false;
+    private boolean verbose = false;
+    private boolean simpleIdl = false;
+    private String classpath = "";
+    private boolean generate = true;
+    private boolean compile = false;
+    private boolean compileDebug = false;
+    private boolean loadclass = false;
 
-    private List        interfaces = new LinkedList();
+    private List interfaces = new LinkedList();
 
-    public GenOptions( String defaultSrcDir, String args[] )
-        throws GenWarning, GenException {
+    public GenOptions() {
+    }
+
+    public GenOptions(String defaultSrcDir, String args[]) throws GenWarning, GenException
{
         genSrcDir = defaultSrcDir;
-        parseOptions( args );
+        parseOptions(args);
     }
 
     public String getGenSrcDir() {
         return genSrcDir;
     }
 
+    public void setGenSrcDir(String genSrcDir) {
+        this.genSrcDir = genSrcDir;
+    }
+
     public String getGenClassDir() {
         return genClassDir;
     }
 
+    public void setGenClassDir(String genClassDir) {
+        this.genClassDir = genClassDir;
+    }
+
     public boolean isOverwrite() {
         return overwrite;
     }
 
+    public void setOverwrite(boolean overwrite) {
+        this.overwrite = overwrite;
+    }
+
     public boolean isVerbose() {
         return verbose;
     }
 
+    public void setVerbose(boolean verbose) {
+        this.verbose = verbose;
+    }
+
     public boolean isSimpleIdl() {
-        return simpleidl;
+        return simpleIdl;
+    }
+
+    public void setSimpleIdl(boolean simpleIdl) {
+        this.simpleIdl = simpleIdl;
     }
 
     public String getClasspath() {
         return classpath;
     }
 
+    public void setClasspath(String classpath) {
+        this.classpath = classpath;
+    }
+
     public boolean isGenerate() {
         return generate;
     }
 
+    public void setGenerate(boolean generate) {
+        this.generate = generate;
+    }
+
     public boolean isCompile() {
         return compile;
     }
 
+    public void setCompile(boolean compile) {
+        this.compile = compile;
+    }
+
     public boolean isCompileDebug() {
         return compileDebug;
     }
 
+    public void setCompileDebug(boolean compileDebug) {
+        this.compileDebug = compileDebug;
+    }
+
     public boolean isLoadclass() {
         return loadclass;
     }
 
+    public void setLoadclass(boolean loadclass) {
+        this.loadclass = loadclass;
+    }
+
     public List getInterfaces() {
         return interfaces;
     }
 
-    protected void parseOptions(String args[]) throws GenException, GenWarning {
+    public void setInterfaces(List interfaces) {
+        this.interfaces = interfaces;
+    }
+
+    public void parseOptions(String args[]) throws GenException, GenWarning {
         GenWarning genWarning = null;
 
         for (int i = 0; i < args.length; i++) {
@@ -111,24 +154,24 @@
             } else if (args[i].equals("-l")) {
                 loadclass = true;
             } else if (args[i].equals("-s")) {
-                simpleidl = true;
+                simpleIdl = true;
             } else if (args[i].equals("-gs")) {
                 if ((i + 1) < args.length) {
                     genSrcDir = args[++i];
                 } else {
-                    throw new GenException( "-gs requires an source output diretory." );
+                    throw new GenException("-gs requires an source output diretory.");
                 }
             } else if (args[i].equals("-cp")) {
                 if ((i + 1) < args.length) {
                     classpath = args[++i];
                 } else {
-                    throw new GenException( "-cp requires a classpath directory." );
+                    throw new GenException("-cp requires a classpath directory.");
                 }
             } else if (args[i].equals("-gc")) {
                 if ((i + 1) < args.length) {
                     genClassDir = args[++i];
                 } else {
-                    throw new GenException( "-gc requires an class output diretory." );
+                    throw new GenException("-gc requires an class output diretory.");
                 }
             } else if (args[i].equals("-v")) {
                 verbose = true;
@@ -138,9 +181,9 @@
                 String msg = "Ignoring unrecognized options: '" + args[i] + "'";
                 if (genWarning != null) {
                     // just a cheap way of chaining the warnings...
-                    genWarning = new GenWarning( msg, genWarning);
+                    genWarning = new GenWarning(msg, genWarning);
                 } else {
-                    genWarning = new GenWarning( msg );
+                    genWarning = new GenWarning(msg);
                 }
             } else {
                 interfaces.add(args[i]);

Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/IiopOperation.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/IiopOperation.java?rev=191366&view=auto
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/IiopOperation.java
(added)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/IiopOperation.java
Sun Jun 19 15:25:18 2005
@@ -0,0 +1,54 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.interop.rmi.iiop.portable;
+
+import java.lang.reflect.Method;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IiopOperation {
+    private final String name;
+    private final Method method;
+
+    public IiopOperation(String name, Method method) {
+        assert name != null;
+        assert method != null;
+        this.method = method;
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Method getMethod() {
+        return method;
+    }
+
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    public boolean equals(Object other) {
+        if (other instanceof IiopOperation) {
+            IiopOperation iiopOperation = (IiopOperation) other;
+            return name.equals(iiopOperation.name);
+        }
+        return false;
+    }
+}

Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/PortableStubCompiler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/PortableStubCompiler.java?rev=191366&view=auto
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/PortableStubCompiler.java
(added)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/portable/PortableStubCompiler.java
Sun Jun 19 15:25:18 2005
@@ -0,0 +1,536 @@
+/**
+ *
+ *  Copyright 2004-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.interop.rmi.iiop.portable;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.interop.generator.GenException;
+import org.apache.geronimo.interop.generator.GenOptions;
+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.JExpression;
+import org.apache.geronimo.interop.generator.JField;
+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.JType;
+import org.apache.geronimo.interop.generator.JVariable;
+import org.apache.geronimo.interop.generator.JavaGenerator;
+import org.omg.CORBA.SystemException;
+import org.omg.CORBA.portable.ApplicationException;
+import org.omg.CORBA.portable.IDLEntity;
+import org.omg.CORBA.portable.RemarshalException;
+
+public class PortableStubCompiler {
+    private HashMap packages = new HashMap();
+    private final GenOptions genOptions;
+    private final ClassLoader classLoader;
+
+    public PortableStubCompiler(GenOptions genOptions, ClassLoader classLoader) {
+        this.genOptions = genOptions;
+        this.classLoader = classLoader;
+    }
+
+    public void generate() throws GenException {
+        JavaGenerator javaGenerator = new JavaGenerator(genOptions);
+
+        List interfaces = genOptions.getInterfaces();
+        for (Iterator iterator = interfaces.iterator(); iterator.hasNext();) {
+            String interfaceName = (String) iterator.next();
+
+            // load the interface class
+            Class interfaceClass = null;
+            try {
+                interfaceClass = classLoader.loadClass(interfaceName);
+            } catch (Exception ex) {
+                throw new GenException("Generate Stubs Failed:", ex);
+            }
+
+
+            // get the package object
+            String packageName = getPackageName(interfaceName);
+            JPackage jpackage = (JPackage) packages.get(packageName);
+            if (jpackage == null) {
+                jpackage = new JPackage(packageName);
+                packages.put(packageName, jpackage);
+            }
+
+
+            // build the basic class object
+            String className = "_" + getClassName(interfaceName) + "_Stub_DAIN";
+            JClass jclass = jpackage.newClass(className);
+            jclass.addImport("javax.rmi.CORBA", "Stub");
+            jclass.setExtends("Stub");
+            jclass.addImplements(interfaceClass.getName());
+
+            addMethod_ids(jclass, interfaceName);
+
+            IiopOperation[] iiopOperations = createIiopOperations(interfaceClass);
+            for (int i = 0; iiopOperations != null && i < iiopOperations.length;
i++) {
+                addMethod(iiopOperations[i], jclass);
+            }
+        }
+
+        for (Iterator iterator = packages.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String packageName = (String) entry.getKey();
+            JPackage jpackage = (JPackage) entry.getValue();
+
+            System.out.println("Generating Package: " + packageName);
+            javaGenerator.generate(jpackage);
+        }
+    }
+
+    private static String getClassName(String interfaceName) {
+        int endIndex = interfaceName.lastIndexOf('.');
+        if (endIndex < 0) {
+            return interfaceName;
+        }
+        return interfaceName.substring(endIndex + 1);
+    }
+
+    private static String getPackageName(String interfaceName) {
+        int endIndex = interfaceName.lastIndexOf('.');
+        if (endIndex < 0) {
+            return "";
+        }
+        return interfaceName.substring(0, endIndex);
+    }
+
+    public static Method[] getAllMethods(Class intfClass) {
+        LinkedList methods = new LinkedList();
+
+        LinkedList stack = new LinkedList();
+        stack.addFirst(intfClass);
+
+        Set visited = new HashSet();
+        while (!stack.isEmpty()) {
+            Class intf = (Class) stack.removeFirst();
+            methods.addAll(Arrays.asList(intf.getDeclaredMethods()));
+            visited.add(intf);
+
+            Class myInterfaces[] = intfClass.getInterfaces();
+            for (int i = 0; i < myInterfaces.length; i++) {
+                Class myInterface = myInterfaces[i];
+                if (!visited.contains(myInterface)) {
+                    stack.addFirst(myInterface);
+                }
+            }
+        }
+
+        return (Method[]) methods.toArray(new Method[methods.size()]);
+    }
+
+    public static IiopOperation[] createIiopOperations(Class intfClass) {
+        Method[] methods = getAllMethods(intfClass);
+
+        // index the methods by name
+        HashMap methodsByName = new HashMap(methods.length);
+        for (int i = 0; i < methods.length; i++) {
+            List methodList = (ArrayList) methodsByName.get(methods[i].getName());
+            if (methodList == null) {
+                methodList = new ArrayList(methods.length);
+                methodsByName.put(methods[i].getName(), methodList);
+            }
+            methodList.add(methods[i]);
+        }
+
+        List overloadList = new ArrayList(methodsByName.size());
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            String iiopName = method.getName();
+            if (((List) methodsByName.get(method.getName())).size() > 1) {
+                iiopName = buildOverloadMethodName(method);
+            }
+            overloadList.add(new IiopOperation(iiopName, method));
+        }
+
+        return (IiopOperation[]) overloadList.toArray(new IiopOperation[overloadList.size()]);
+    }
+
+    public static String buildOverloadMethodName(Method method) {
+        Class parameterTypes[] = method.getParameterTypes();
+        String name = method.getName() + "_";
+        if (parameterTypes.length ==0) {
+            name += "_";
+        } else {
+            for (int i = 0; i < parameterTypes.length; i++) {
+                Class parameterType = parameterTypes[i];
+                name += buildOverloadParameterName(parameterType);
+            }
+        }
+        return name.replace('.', '_');
+    }
+
+    public static String buildOverloadParameterName(Class parameterType) {
+        String name = "";
+
+        int arrayDimensions = 0;
+        while (parameterType.isArray()) {
+            arrayDimensions++;
+            parameterType = parameterType.getComponentType();
+        }
+
+        // arrays start with org_omg_boxedRMI_
+        if (arrayDimensions > 0) {
+            name += "_org_omg_boxedRMI";
+        }
+
+        // IDLEntity types must be prefixed with org_omg_boxedIDL_
+        if (IDLEntity.class.isAssignableFrom(parameterType)) {
+            name += "_org_omg_boxedIDL";
+        }
+
+        // determine the parameterType name... this is overriden for special corba types
+        String parameterTypeName = (String) overloadTypes.get(parameterType.getName());
+        if (parameterTypeName == null) {
+            parameterTypeName = parameterType.getName();
+        }
+
+        // add package
+        String packageName = getPackageName(parameterTypeName);
+        if (packageName.length() > 0) {
+            name += "_" + packageName;
+        }
+
+        // arrays now contain a dimension indicator
+        if (arrayDimensions > 0) {
+            name += "_" + "seq" + arrayDimensions;
+        }
+
+        // add the class name
+        name += "_" + getClassName(parameterTypeName);
+
+        return name;
+    }
+
+    private void addMethod(JClass jclass, String iiopMethodName, JReturnType jreturnType,
String name, JParameter[] jparameters, Class[] exceptions) {
+        //
+        // Method Template:
+        //
+        // if (!Util.isLocal(this)) {
+        //     try {
+        //         org.omg.CORBA_2_3.portable.InputStream in = null;
+        //         try {
+        //             org.omg.CORBA_2_3.portable.OutputStream out =
+        //                 (org.omg.CORBA_2_3.portable.OutputStream)
+        //                 _request("passAndReturnCheese__org_apache_geronimo_interop_rmi_iiop_compiler_Cheese",
true);
+        //             out.write_value((Serializable)arg0,Cheese.class);
+        //             in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(out);
+        //             return (Cheese) in.read_value(Cheese.class);
+        //         } catch (ApplicationException ex) {
+        //             in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
+        //             String id = in.read_string();
+        //             throw new UnexpectedException(id);
+        //         } catch (RemarshalException ex) {
+        //             return passAndReturnCheese(arg0);
+        //         } finally {
+        //             _releaseReply(in);
+        //         }
+        //     } catch (SystemException ex) {
+        //         throw Util.mapSystemException(ex);
+        //     }
+        // } else {
+        //     ServantObject so = _servant_preinvoke("passAndReturnCheese__org_apache_geronimo_interop_rmi_iiop_compiler_Cheese",Foo.class);
+        //     if (so == null) {
+        //         return passAndReturnCheese(arg0);
+        //     }
+        //     try {
+        //         Cheese arg0Copy = (Cheese) Util.copyObject(arg0,_orb());
+        //         Cheese result = ((Foo)so.servant).passAndReturnCheese(arg0Copy);
+        //         return (Cheese)Util.copyObject(result,_orb());
+        //     } catch (Throwable ex) {
+        //         Throwable exCopy = (Throwable)Util.copyObject(ex,_orb());
+        //         throw Util.wrapException(exCopy);
+        //     } finally {
+        //         _servant_postinvoke(so);
+        //     }
+        // }
+
+        JMethod jmethod = jclass.newMethod(jreturnType, name, jparameters, exceptions);
+
+        JTryCatchFinallyStatement outerTryCatchFinally = new JTryCatchFinallyStatement();
+        jmethod.addStatement(outerTryCatchFinally);
+        JTryStatement outerTry = outerTryCatchFinally.getTryStatement();
+
+        JLocalVariable inVar = outerTry.newLocalVariable(org.omg.CORBA_2_3.portable.InputStream.class,
+                "in",
+                new JExpression(new JCodeStatement("null")));
+
+        JTryCatchFinallyStatement innterTryCatchFinally = new JTryCatchFinallyStatement();
+        outerTry.addStatement(innterTryCatchFinally);
+        JTryStatement innerTry = innterTryCatchFinally.getTryStatement();
+
+        JLocalVariable outVar = innerTry.newLocalVariable(org.omg.CORBA_2_3.portable.OutputStream.class,
+                "out",
+                new JExpression(new JCodeStatement("(" + org.omg.CORBA_2_3.portable.OutputStream.class.getName()
+ ") _request(\"" + iiopMethodName + "\", true)")));
+
+        // Write the variables
+        for (int i = 0; i < jparameters.length; i++) {
+            JParameter jparameter = jparameters[i];
+
+            String writeMethod = getWriteMethod(jparameter);
+            String writeCall;
+            if (writeMethod != null) {
+                writeCall = writeMethod + "( " + jparameter.getName() + " )";
+            } else {
+                String cast = "";
+                if (!Serializable.class.isAssignableFrom(jparameter.getType())) {
+                    cast = "(java.io.Serializable)";
+                }
+                writeCall = "write_value(" + cast + jparameter.getName() + ", " + jparameter.getTypeDecl()
+ ".class)";
+            }
+
+            innerTry.addStatement(new JCodeStatement(outVar.getName() + "." + writeCall +
";"));
+        }
+
+        // invoke the method
+        String invoke = "_invoke(" + outVar.getName() + ");";
+        if (jreturnType.getType() != Void.TYPE) {
+            invoke = inVar.getName() + " = (" + inVar.getTypeDecl() + ")" + invoke;
+        }
+        innerTry.addStatement(new JCodeStatement(invoke));
+
+        // read the return value
+        if (jreturnType.getType() != Void.TYPE) {
+            String readMethod = getReadMethod(jreturnType);
+            String readCall = "";
+
+            if (readMethod != null) {
+                readCall = inVar.getName() + "." + readMethod + "()";
+            } else {
+                readCall = "(" + jreturnType.getTypeDecl() + ")" + inVar.getName() + ".read_value(
" + jreturnType.getTypeDecl() + ".class)";
+            }
+            innerTry.addStatement(new JCodeStatement("return " + readCall + ";"));
+        }
+
+        JVariable exVar = new JVariable(ApplicationException.class, "ex");
+        JCatchStatement jcatchStatement = innterTryCatchFinally.newCatch(exVar);
+
+        jcatchStatement.addStatement(new JCodeStatement(inVar.getName() + " = (" + inVar.getTypeDecl()
+ ") " + exVar.getName() + ".getInputStream();"));
+        JLocalVariable idVar = jcatchStatement.newLocalVariable(String.class,
+                "id",
+                new JExpression(new JCodeStatement(inVar.getName() + ".read_string()")));
+//        if (id.equals("IDL:org/apache/geronimo/interop/rmi/iiop/compiler/other/BlahEx:1.0"))
{
+//            throw (BlahException) in.read_value(BlahException.class);
+//        }
+//        if (id.equals("IDL:org/apache/geronimo/interop/rmi/iiop/compiler/BooEx:1.0")) {
+//            throw (BooException) in.read_value(BooException.class);
+//        }
+        for (int i = 0; i < exceptions.length; i++) {
+            Class exception = exceptions[i];
+            if (exception.equals(RemoteException.class)) {
+                continue;
+            }
+            String exceptionName = exception.getName().replace('.', '/');
+            if (exceptionName.endsWith("Exception")) {
+                exceptionName = exceptionName.substring(0, exceptionName.length() - "Exception".length());
+            }
+            exceptionName += "Ex";
+            JIfStatement jif = new JIfStatement(new JExpression(new JCodeStatement(idVar.getName()
+ ".equals(\"IDL:" + exceptionName + ":1.0\")")));
+            jif.addStatement(new JCodeStatement("throw (" + exception.getName() + ") in.read_value("
+ exception.getName() + ".class);"));
+            jcatchStatement.addStatement(jif);
+
+        }
+        jcatchStatement.addStatement(new JCodeStatement("throw new java.rmi.UnexpectedException("
+ idVar.getName() + ");"));
+
+        //         } catch (RemarshalException ex) {
+        //             return passAndReturnCheese(arg0);
+        exVar = new JVariable(RemarshalException.class, "ex");
+        jcatchStatement = innterTryCatchFinally.newCatch(exVar);
+
+        String remarshal = name + "(";
+        for (int i = 0; i < jparameters.length; i++) {
+            JParameter jparameter = jparameters[i];
+            if (i > 0) {
+                remarshal += ", ";
+            }
+            remarshal += jparameter.getName();
+        }
+        remarshal += ");";
+        if (jreturnType.getType() != Void.TYPE) {
+            remarshal = "return " + remarshal;
+        }
+        jcatchStatement.addStatement(new JCodeStatement(remarshal));
+
+        //         } finally {
+        //             _releaseReply(in);
+//        JBlockStatement jfinally = new JBlockStatement();
+        innterTryCatchFinally.addFinallyStatement(new JCodeStatement("_releaseReply(" + inVar.getName()
+ ");"));
+//        jfinally.addStatement(new JCodeStatement("_releaseReply(" + inVar.getName() + ");"));
+
+        //     } catch (SystemException ex) {
+        //         throw Util.mapSystemException(ex);
+        exVar = new JVariable(SystemException.class, "ex");
+        jcatchStatement = outerTryCatchFinally.newCatch(exVar);
+        jcatchStatement.addStatement(new JCodeStatement("throw javax.rmi.CORBA.Util.mapSystemException("
+ exVar.getName() + ");"));
+    }
+
+    private void addMethod_ids(JClass jclass, String interfaceName) {
+        //
+        // Method Template:
+        //
+        // private static final String[] _type_ids = {
+        //     "RMI:org.apache.geronimo.interop.rmi.iiop.portable.Foo:0000000000000000"
+        // };
+        //
+        // public String[] getIds()
+        // {
+        //     return _type_ids;
+        // }
+        //
+
+        JField typesField = jclass.newField(String[].class, "_type_ids", new JExpression(new
JCodeStatement("{ \"RMI:" + interfaceName + ":0000000000000000\" }")));
+        typesField.setModifiers(Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL);
+
+        JMethod jmethod = jclass.newMethod(new JReturnType(String[].class), "_ids", null,
null);
+        jmethod.addStatement(new JCodeStatement("return _type_ids;"));
+    }
+
+
+    private void addMethod(IiopOperation iiopOperation, JClass jclass) {
+        Method method = iiopOperation.getMethod();
+
+        JReturnType jreturnType = new JReturnType(method.getReturnType());
+
+        Class[] parameterTypes = method.getParameterTypes();
+        JParameter[] jparameters = new JParameter[parameterTypes.length];
+        for (int i = 0; i < parameterTypes.length; i++) {
+            jparameters[i] = new JParameter(parameterTypes[i], "arg" + i);
+        }
+
+        addMethod(jclass,
+                iiopOperation.getName(),
+                jreturnType,
+                method.getName(),
+                jparameters,
+                method.getExceptionTypes());
+    }
+
+//    public void compile()
+//            throws Exception {
+//
+//        Set pkg = packages.keySet();
+//        Iterator pkgIt = pkg.iterator();
+//        String stubPkg = "";
+//
+//        /*
+//         * Each of the packages were generated under go.getGenSrcDir().
+//         *
+//         * Go through all the packages and run the compiler on *.java
+//         */
+//        String classpath = new File(genOptions.getClasspath()).getAbsolutePath();
+//        String srcpath = new File(genOptions.getGenSrcDir()).getAbsolutePath();
+//
+//        String filesToCompile = "";
+//        String javacCmd = "";
+//
+//        while (pkgIt.hasNext()) {
+//            stubPkg = (String) pkgIt.next();
+//            stubPkg = stubPkg.replace('.', File.separatorChar);
+//            filesToCompile = new File(new File(genOptions.getGenSrcDir(), stubPkg), "*.java").getAbsolutePath();
+//
+//            System.out.println("Compiling Package: " + filesToCompile);
+//
+//            javacCmd = "javac -d " + genOptions.getGenClassDir() +
+//                    (genOptions.isCompileDebug() ? " -g" : "") +
+//                    " -classpath " + classpath + " " +
+//                    " -sourcepath " + srcpath + " " + filesToCompile;
+//
+//            System.out.println("Lauching: " + javacCmd);
+//
+//            ProcessUtil pu = ProcessUtil.getInstance();
+//            pu.setEcho(System.out);
+//            pu.run(javacCmd, null, "./");
+//        }
+//    }
+
+    private static HashMap readMethods;
+    private static HashMap writeMethods;
+    private static HashMap overloadTypes;
+
+    static {
+        readMethods = new HashMap();
+        readMethods.put("boolean", "read_boolean");
+        readMethods.put("char", "read_wchar");
+        readMethods.put("byte", "read_octet");
+        readMethods.put("short", "read_short");
+        readMethods.put("int", "read_long");
+        readMethods.put("long", "read_longlong");
+        readMethods.put("float", "read_float");
+        readMethods.put("double", "read_double");
+        readMethods.put("org.omg.CORBA.Object", "read_Object");
+
+        writeMethods = new HashMap();
+        writeMethods.put("boolean", "write_boolean");
+        writeMethods.put("char", "write_wchar");
+        writeMethods.put("byte", "write_octet");
+        writeMethods.put("short", "write_short");
+        writeMethods.put("int", "write_long");
+        writeMethods.put("long", "write_longlong");
+        writeMethods.put("float", "write_float");
+        writeMethods.put("double", "write_double");
+        writeMethods.put("org.omg.CORBA.Object", "write_Object");
+
+        overloadTypes = new HashMap();
+        overloadTypes.put("boolean", "boolean");
+        overloadTypes.put("char", "wchar");
+        overloadTypes.put("byte", "octet");
+        overloadTypes.put("short", "short");
+        overloadTypes.put("int", "long");
+        overloadTypes.put("long", "long_long");
+        overloadTypes.put("float", "float");
+        overloadTypes.put("double", "double");
+        overloadTypes.put("java.lang.Class", "javax.rmi.CORBA.ClassDesc");
+        overloadTypes.put("java.lang.String", "CORBA.WStringValue");
+        overloadTypes.put("org.omg.CORBA.Object", "Object");
+    }
+
+    protected String getWriteMethod(JVariable jvariable) {
+        if (jvariable != null) {
+            return (String) writeMethods.get(jvariable.getTypeDecl());
+        }
+        return null;
+    }
+
+    protected String getReadMethod(JType jtype) {
+        if (jtype != null) {
+            return (String) readMethods.get(jtype.getTypeDecl());
+        }
+        return null;
+    }
+
+}

Added: geronimo/trunk/modules/interop/src/test-data/nameMangler.properties
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/test-data/nameMangler.properties?rev=191366&view=auto
==============================================================================
--- geronimo/trunk/modules/interop/src/test-data/nameMangler.properties (added)
+++ geronimo/trunk/modules/interop/src/test-data/nameMangler.properties Sun Jun 19 15:25:18
2005
@@ -0,0 +1,137 @@
+abcdefg_nothing() = abcdefg_nothing
+abcdefg_pass_boolean(boolean) = abcdefg_pass_boolean
+abcdefg_pass_char(char) = abcdefg_pass_char
+abcdefg_pass_byte(byte) = abcdefg_pass_byte
+abcdefg_pass_int(int) = abcdefg_pass_int
+abcdefg_pass_long(long) = abcdefg_pass_long
+abcdefg_pass_float(float) = abcdefg_pass_float
+abcdefg_pass_double(double) = abcdefg_pass_double
+abcdefg_pass_BigDecimal(java.math.BigDecimal) = abcdefg_pass_BigDecimal
+abcdefg_pass_Class(java.lang.Class) = abcdefg_pass_Class
+abcdefg_pass_CORBA_Object(org.omg.CORBA.Object) = abcdefg_pass_CORBA_Object
+abcdefg_pass_CORBA_Any(org.omg.CORBA.Any) = abcdefg_pass_CORBA_Any
+abcdefg_pass_CORBA_TypeCode(org.omg.CORBA.TypeCode) = abcdefg_pass_CORBA_TypeCode
+abcdefg_pass_CheeseIDLEntity(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity)
= abcdefg_pass_CheeseIDLEntity
+abcdefg_pass_GenericInterface(org.apache.geronimo.interop.rmi.iiop.portable.other.GenericInterface)
= abcdefg_pass_GenericInterface
+abcdefg_pass_BlahException(org.apache.geronimo.interop.rmi.iiop.portable.other.BlahEx) =
abcdefg_pass_BlahException
+abcdefg_pass_BooException(org.apache.geronimo.interop.rmi.iiop.portable.BooException) = abcdefg_pass_BooException
+abcdefg_return_boolean() = abcdefg_return_boolean
+abcdefg_return_char() = abcdefg_return_char
+abcdefg_return_byte() = abcdefg_return_byte
+abcdefg_return_int() = abcdefg_return_int
+abcdefg_return_long() = abcdefg_return_long
+abcdefg_return_float() = abcdefg_return_float
+abcdefg_return_double() = abcdefg_return_double
+abcdefg_return_BigDecimal() = abcdefg_return_BigDecimal
+abcdefg_return_Class() = abcdefg_return_Class
+abcdefg_return_CORBA_Object() = abcdefg_return_CORBA_Object
+abcdefg_return_CORBA_Any() = abcdefg_return_CORBA_Any
+abcdefg_return_CORBA_TypeCode() = abcdefg_return_CORBA_TypeCode
+abcdefg_return_CheeseIDLEntity() = abcdefg_return_CheeseIDLEntity
+abcdefg_return_GenericInterface() = abcdefg_return_GenericInterface
+abcdefg_return_BlahException() = abcdefg_return_BlahException
+abcdefg_return_BooException() = abcdefg_return_BooException
+abcdefg_pass_return_boolean(boolean) = abcdefg_pass_return_boolean
+abcdefg_pass_return_char(char) = abcdefg_pass_return_char
+abcdefg_pass_return_byte(byte) = abcdefg_pass_return_byte
+abcdefg_pass_return_int(int) = abcdefg_pass_return_int
+abcdefg_pass_return_long(long) = abcdefg_pass_return_long
+abcdefg_pass_return_float(float) = abcdefg_pass_return_float
+abcdefg_pass_return_double(double) = abcdefg_pass_return_double
+abcdefg_pass_return_BigDecimal(java.math.BigDecimal) = abcdefg_pass_return_BigDecimal
+abcdefg_pass_return_Class(java.lang.Class) = abcdefg_pass_return_Class
+abcdefg_pass_return_CORBA_Object(org.omg.CORBA.Object) = abcdefg_pass_return_CORBA_Object
+abcdefg_pass_return_CORBA_Any(org.omg.CORBA.Any) = abcdefg_pass_return_CORBA_Any
+abcdefg_pass_return_CORBA_TypeCode(org.omg.CORBA.TypeCode) = abcdefg_pass_return_CORBA_TypeCode
+abcdefg_pass_return_CheeseIDLEntity(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity)
= abcdefg_pass_return_CheeseIDLEntity
+abcdefg_pass_boolean_arr(boolean[]) = abcdefg_pass_boolean_arr
+abcdefg_pass_char_arr(char[]) = abcdefg_pass_char_arr
+abcdefg_pass_byte_arr(byte[]) = abcdefg_pass_byte_arr
+abcdefg_pass_int_arr(int[]) = abcdefg_pass_int_arr
+abcdefg_pass_long_arr(long[]) = abcdefg_pass_long_arr
+abcdefg_pass_float_arr(float[]) = abcdefg_pass_float_arr
+abcdefg_pass_double_arr(double[]) = abcdefg_pass_double_arr
+abcdefg_pass_BigDecimal_arr(java.math.BigDecimal[]) = abcdefg_pass_BigDecimal_arr
+abcdefg_pass_Class_arr(java.lang.Class[]) = abcdefg_pass_Class_arr
+abcdefg_pass_CORBA_Object_arr(org.omg.CORBA.Object[]) = abcdefg_pass_CORBA_Object_arr
+abcdefg_pass_CORBA_Any_arr(org.omg.CORBA.Any[]) = abcdefg_pass_CORBA_Any_arr
+abcdefg_pass_CORBA_TypeCode_arr(org.omg.CORBA.TypeCode[]) = abcdefg_pass_CORBA_TypeCode_arr
+abcdefg_pass_CheeseIDLEntity_arr(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity[])
= abcdefg_pass_CheeseIDLEntity_arr
+abcdefg_pass_GenericInterface_arr(org.apache.geronimo.interop.rmi.iiop.portable.other.GenericInterface[])
= abcdefg_pass_GenericInterface_arr
+abcdefg_pass_BlahException_arr(org.apache.geronimo.interop.rmi.iiop.portable.other.BlahEx[])
= abcdefg_pass_BlahException_arr
+abcdefg_pass_BooException_arr(org.apache.geronimo.interop.rmi.iiop.portable.BooException[])
= abcdefg_pass_BooException_arr
+abcdefg_return_boolean_arr() = abcdefg_return_boolean_arr
+abcdefg_return_char_arr() = abcdefg_return_char_arr
+abcdefg_return_byte_arr() = abcdefg_return_byte_arr
+abcdefg_return_int_arr() = abcdefg_return_int_arr
+abcdefg_return_long_arr() = abcdefg_return_long_arr
+abcdefg_return_float_arr() = abcdefg_return_float_arr
+abcdefg_return_double_arr() = abcdefg_return_double_arr
+abcdefg_return_BigDecimal_arr() = abcdefg_return_BigDecimal_arr
+abcdefg_return_Class_arr() = abcdefg_return_Class_arr
+abcdefg_return_CORBA_Object_arr() = abcdefg_return_CORBA_Object_arr
+abcdefg_return_CORBA_Any_arr() = abcdefg_return_CORBA_Any_arr
+abcdefg_return_CORBA_TypeCode_arr() = abcdefg_return_CORBA_TypeCode_arr
+abcdefg_return_CheeseIDLEntity_arr() = abcdefg_return_CheeseIDLEntity_arr
+abcdefg_return_GenericInterface_arr() = abcdefg_return_GenericInterface_arr
+abcdefg_return_BlahException_arr() = abcdefg_return_BlahException_arr
+abcdefg_return_BooException_arr() = abcdefg_return_BooException_arr
+abcdefg_overload() = abcdefg_overload__
+abcdefg_overload(boolean) = abcdefg_overload__boolean
+abcdefg_overload(char) = abcdefg_overload__wchar
+abcdefg_overload(byte) = abcdefg_overload__octet
+abcdefg_overload(int) = abcdefg_overload__long
+abcdefg_overload(long) = abcdefg_overload__long_long
+abcdefg_overload(float) = abcdefg_overload__float
+abcdefg_overload(double) = abcdefg_overload__double
+abcdefg_overload(java.lang.String) = abcdefg_overload__CORBA_WStringValue
+abcdefg_overload(java.math.BigDecimal) = abcdefg_overload__java_math_BigDecimal
+abcdefg_overload(java.lang.Class) = abcdefg_overload__javax_rmi_CORBA_ClassDesc
+abcdefg_overload(java.lang.Object) = abcdefg_overload__java_lang_Object
+abcdefg_overload(org.omg.CORBA.Object) = abcdefg_overload__Object
+abcdefg_overload(org.omg.CORBA.Any) = abcdefg_overload__org_omg_boxedIDL_org_omg_CORBA_Any
+abcdefg_overload(org.omg.CORBA.TypeCode) = abcdefg_overload__org_omg_boxedIDL_org_omg_CORBA_TypeCode
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity) = abcdefg_overload__org_omg_boxedIDL_org_apache_geronimo_interop_rmi_iiop_portable_other_CheeseIDLEntity
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.GenericInterface) =
abcdefg_overload__org_apache_geronimo_interop_rmi_iiop_portable_other_GenericInterface
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.BlahEx) = abcdefg_overload__org_apache_geronimo_interop_rmi_iiop_portable_other_BlahEx
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.BooException) = abcdefg_overload__org_apache_geronimo_interop_rmi_iiop_portable_BooException
+abcdefg_overload(boolean[]) = abcdefg_overload__org_omg_boxedRMI_seq1_boolean
+abcdefg_overload(char[]) = abcdefg_overload__org_omg_boxedRMI_seq1_wchar
+abcdefg_overload(byte[]) = abcdefg_overload__org_omg_boxedRMI_seq1_octet
+abcdefg_overload(int[]) = abcdefg_overload__org_omg_boxedRMI_seq1_long
+abcdefg_overload(long[]) = abcdefg_overload__org_omg_boxedRMI_seq1_long_long
+abcdefg_overload(float[]) = abcdefg_overload__org_omg_boxedRMI_seq1_float
+abcdefg_overload(double[]) = abcdefg_overload__org_omg_boxedRMI_seq1_double
+abcdefg_overload(java.lang.String[]) = abcdefg_overload__org_omg_boxedRMI_CORBA_seq1_WStringValue
+abcdefg_overload(java.math.BigDecimal[]) = abcdefg_overload__org_omg_boxedRMI_java_math_seq1_BigDecimal
+abcdefg_overload(java.lang.Class[]) = abcdefg_overload__org_omg_boxedRMI_javax_rmi_CORBA_seq1_ClassDesc
+abcdefg_overload(java.lang.Object[]) = abcdefg_overload__org_omg_boxedRMI_java_lang_seq1_Object
+abcdefg_overload(org.omg.CORBA.Object[]) = abcdefg_overload__org_omg_boxedRMI_seq1_Object
+abcdefg_overload(org.omg.CORBA.Any[]) = abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_omg_CORBA_seq1_Any
+abcdefg_overload(org.omg.CORBA.TypeCode[]) = abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_omg_CORBA_seq1_TypeCode
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity[]) =
abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_apache_geronimo_interop_rmi_iiop_portable_other_seq1_CheeseIDLEntity
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.GenericInterface[])
= abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_other_seq1_GenericInterface
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.BlahEx[]) = abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_other_seq1_BlahEx
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.BooException[]) = abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_seq1_BooException
+abcdefg_overload(boolean[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_boolean
+abcdefg_overload(char[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_wchar
+abcdefg_overload(byte[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_octet
+abcdefg_overload(int[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_long
+abcdefg_overload(long[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_long_long
+abcdefg_overload(float[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_float
+abcdefg_overload(double[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_double
+abcdefg_overload(java.lang.String[][]) = abcdefg_overload__org_omg_boxedRMI_CORBA_seq2_WStringValue
+abcdefg_overload(java.math.BigDecimal[][]) = abcdefg_overload__org_omg_boxedRMI_java_math_seq2_BigDecimal
+abcdefg_overload(java.lang.Class[][]) = abcdefg_overload__org_omg_boxedRMI_javax_rmi_CORBA_seq2_ClassDesc
+abcdefg_overload(java.lang.Object[][]) = abcdefg_overload__org_omg_boxedRMI_java_lang_seq2_Object
+abcdefg_overload(org.omg.CORBA.Object[][]) = abcdefg_overload__org_omg_boxedRMI_seq2_Object
+abcdefg_overload(org.omg.CORBA.Any[][]) = abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_omg_CORBA_seq2_Any
+abcdefg_overload(org.omg.CORBA.TypeCode[][]) = abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_omg_CORBA_seq2_TypeCode
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.CheeseIDLEntity[][])
= abcdefg_overload__org_omg_boxedRMI_org_omg_boxedIDL_org_apache_geronimo_interop_rmi_iiop_portable_other_seq2_CheeseIDLEntity
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.GenericInterface[][])
= abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_other_seq2_GenericInterface
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.other.BlahEx[][]) = abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_other_seq2_BlahEx
+abcdefg_overload(org.apache.geronimo.interop.rmi.iiop.portable.BooException[][]) = abcdefg_overload__org_omg_boxedRMI_org_apache_geronimo_interop_rmi_iiop_portable_seq2_BooException
+abcdefg_throw_exception() = abcdefg_throw_exception
+abcdefg_pass_throw_exception(java.lang.String) = abcdefg_pass_throw_exception
+abcdefg_return_throw_exception() = abcdefg_return_throw_exception
+abcdefg_pass_return_throw_exception(java.lang.String) = abcdefg_pass_return_throw_exception



Mime
View raw message