OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | April 2006 Index

<--  Date Index     <--  Thread Index    

CVS update of fractalrmi/src/org/objectweb/fractal/rmi/stub (1 file)


    Date: Friday, April 28, 2006 @ 15:34:53
  Author: dillense
    Path: /cvsroot/fractal/fractalrmi/src/org/objectweb/fractal/rmi/stub

Modified: RmiStubFactory.java

added static main() method to manually generate stubs and skeletons


---------------------+
 RmiStubFactory.java |   82 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 63 insertions(+), 19 deletions(-)


Index: fractalrmi/src/org/objectweb/fractal/rmi/stub/RmiStubFactory.java
diff -u fractalrmi/src/org/objectweb/fractal/rmi/stub/RmiStubFactory.java:1.6 
fractalrmi/src/org/objectweb/fractal/rmi/stub/RmiStubFactory.java:1.7
--- fractalrmi/src/org/objectweb/fractal/rmi/stub/RmiStubFactory.java:1.6     
  Mon Aug 29 19:54:29 2005
+++ fractalrmi/src/org/objectweb/fractal/rmi/stub/RmiStubFactory.java   Fri 
Apr 28 15:34:53 2006
@@ -19,9 +19,10 @@
  * Contact: Eric.Bruneton@xxxxxxxxxxxxxxxxxxxx
  *
  * Author: Eric Bruneton
- *
+ * 
  * with some comments copied from Jonathan:
  *   org.objectweb.jonathan.apis.stub_factories.StubFactory (author: B. 
Dumant)
+ * Bruno Dillenseger added main method to generate stubs and skeletons (like 
a compiler).
  */
 
 package org.objectweb.fractal.rmi.stub;
@@ -65,11 +66,52 @@
  * identifies a method among the methods provided by a Java interface, 
followed
  * by the method's arguments, marshalled in the order of their declaration in
  * the method's signature.
+ * <p>
+ * In order to be able to manually generate stubs and skeletons before 
execution
+ * and avoid their generation at runtime (typically for performance reasons,
+ * although no real testing has been performed), this class can be used as a
+ * kind of a stub compiler through its main method, giving as arguments the 
Java
+ * interfaces you want to compile stubs for. Note that this generation is
+ * performed at byte code level only, i.e. it takes compiled interfaces as 
input
+ * and generates compiled stubs and skeletons classes. In other words, the
+ * interfaces (fully-qualified) names you specify must be compiled and 
reachable
+ * in the classpath, and the result is a corresponding set of stub and 
skeleton
+ * compiled classes (taking current directory as base directory).    
  */
 
 public class RmiStubFactory
   implements Opcodes, StubFactory, SkeletonFactory, BindingController
 {
+       /**
+        * This flag is set to true if generated stub classes must be written 
to files
+        */
+       static private boolean writeStubs = false;
+
+       /**
+        * This flag is set to true if generated skeleton classes must be 
written to files
+        */
+       static private boolean writeSkels = false;
+
+       /**
+        * FractalRMI stub and skeleton generator.
+        * @param interfaces a list of interface fully qualified names. These 
interfaces
+        * must be compiled already and reachable through the classpath.
+        * Stubs and skeletons are generated as compiled classes taking 
current directory
+        * as base directory.
+        */
+       static public void main(String[] interfaces)
+               throws Exception
+       {
+               writeStubs = true;
+               writeSkels = true;
+               int argc = interfaces.length;
+               Loader loader = new 
RmiStubFactory().getLoader(RmiStubFactory.class);
+               while (argc-- > 0)
+               {
+                       loader.findClass(getSkelClassName(interfaces[argc]));
+                       loader.findClass(getStubClassName(interfaces[argc]));
+               }
+       }
 
   /**
    * A map associating {@link Loader loaders} to their parent class loader.
@@ -96,7 +138,7 @@
   protected Logger logger;
 
   /**
-   * Constructs a new {@link RmiStubFactory}.
+   * Constructs a new {@link RmiStubFactory}
    */
 
   public RmiStubFactory () {
@@ -259,7 +301,7 @@
       super(parent);
     }
 
-    /**
+       /**
      * Finds the class whose name is given. If the given name is of the form
      * <i>prefix</i><tt>_Stub</tt> then this method calls the {@link
      * #generateStubClass generateStubClass} method with the <i>prefix</i> 
class
@@ -285,14 +327,15 @@
         if (logger != null && logger.isLoggable(BasicLevel.INFO)) {
           logger.log(BasicLevel.INFO, "Stub class generated: " + name);
         }
-        /*
-        try {
-          java.io.OutputStream os;
-          os = new java.io.FileOutputStream(name + ".class");
-          os.write(b);
-          os.close();
-        } catch (Exception e) {
-        }*/
+        if (writeStubs) {
+             try {
+               java.io.OutputStream os;
+               os = new java.io.FileOutputStream(name.replace('.', '/') + 
".class");
+               os.write(b);
+               os.close();
+             } catch (Exception e) {
+             }
+        }
         return defineClass(name, b, 0, b.length);
       } else if (isSkelClassName(name)) {
         Class itf = loadClass(resolveSkelClassName(name));
@@ -302,14 +345,15 @@
         if (logger != null && logger.isLoggable(BasicLevel.INFO)) {
           logger.log(BasicLevel.INFO, "Skeleton class generated: " + name);
         }
-        /*
-        try {
-          java.io.OutputStream os;
-          os = new java.io.FileOutputStream(name + ".class");
-          os.write(b);
-          os.close();
-        } catch (Exception e) {
-        }*/
+        if (writeSkels) {
+          try {
+            java.io.OutputStream os;
+            os = new java.io.FileOutputStream(name.replace('.', '/') + 
".class");
+            os.write(b);
+            os.close();
+          } catch (Exception e) {
+          }
+        }
         return defineClass(name, b, 0, b.length);
       } else {
         throw new ClassNotFoundException(name);



<--  Date Index     <--  Thread Index    

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.