org.objectweb.fractal.rmi
Class ClassGeneratorImpl

java.lang.Object
  extended by org.objectweb.fractal.rmi.ClassGeneratorImpl
All Implemented Interfaces:
org.objectweb.asm.Opcodes, ClassLoaderController, ClassGenerator

public class ClassGeneratorImpl
extends java.lang.Object
implements org.objectweb.asm.Opcodes, ClassGenerator, ClassLoaderController


Field Summary
protected  java.lang.ClassLoader cl
          A class loader used by this component to load classes
protected  org.objectweb.util.monolog.api.Logger logger
          The logger used to log messages.
 
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5
 
Constructor Summary
ClassGeneratorImpl()
           
 
Method Summary
 java.lang.Class generateClass(java.lang.String className)
          Generates a skeleton or a stub Class for a class of a given name.
 java.lang.Class generateClass(java.lang.String className, java.lang.ClassLoader cl)
          Generates a skeleton or a stub Class for a class of a given name.
protected  void generateConstructor(org.objectweb.asm.ClassVisitor cv, java.lang.String superClass)
          Generates an empty constructor for the given class.
protected  void generateSkeletonClass(org.objectweb.asm.ClassVisitor cv, java.lang.Class itf)
          Generates a skeleton class for the given Java interface.
protected  void generateSkeletonMethod(org.objectweb.asm.ClassVisitor cv, java.lang.String name, java.lang.Class itf)
          Generates a skeleton's send method.
protected  void generateStubClass(org.objectweb.asm.ClassVisitor cv, java.lang.Class itf)
          Generates a stub class for the given Java interface.
protected  void generateStubMethod(org.objectweb.asm.ClassVisitor cv, java.lang.String name, java.lang.reflect.Method m, int index)
          Generates a stub method.
 java.lang.ClassLoader getFcClassLoader()
          Returns a class loader used by this component
protected  boolean isClassParameter(java.lang.reflect.Method m, int p)
          Returns true if the specified parameter contains the name of a class.
 java.lang.Class loadClass(java.lang.String className)
          Loads a class of a given name
 void setFcClassLoader(java.lang.ClassLoader cl)
          Sets the class loader used by this component
protected static void sort(java.lang.reflect.Method[] methods)
          Sorts the given methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.objectweb.util.monolog.api.Logger logger
The logger used to log messages. May be null.


cl

protected java.lang.ClassLoader cl
A class loader used by this component to load classes

Constructor Detail

ClassGeneratorImpl

public ClassGeneratorImpl()
Method Detail

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Description copied from interface: ClassGenerator
Loads a class of a given name

Specified by:
loadClass in interface ClassGenerator
Parameters:
className - name of the class to be loaded
Returns:
the Class object
Throws:
java.lang.ClassNotFoundException

generateClass

public java.lang.Class generateClass(java.lang.String className,
                                     java.lang.ClassLoader cl)
Description copied from interface: ClassGenerator
Generates a skeleton or a stub Class for a class of a given name. If the name ends with _Stub a stub is generated, if the name ends with _Skel a skeleton is generated.

Specified by:
generateClass in interface ClassGenerator
Parameters:
className - name of the class for which a stub or a skeleton is to be generated
cl - a class loader to be used to generate the stub/skeleton
Returns:
the Class object

generateClass

public java.lang.Class generateClass(java.lang.String className)
Description copied from interface: ClassGenerator
Generates a skeleton or a stub Class for a class of a given name. If the name ends with _Stub a stub is generated, if the name ends with _Skel a skeleton is generated.

Specified by:
generateClass in interface ClassGenerator
Parameters:
className - name of the class for which a stub or a skeleton is to be generated
Returns:
the Class object

generateStubClass

protected void generateStubClass(org.objectweb.asm.ClassVisitor cv,
                                 java.lang.Class itf)
Generates a stub class for the given Java interface. This method generates a sub class of the Stub class that implements the given interface, by using the given class visitor.

Parameters:
cv - the class visitor to be used to generate the stub class.
itf - the Java interface that the stub class must implement.

generateSkeletonClass

protected void generateSkeletonClass(org.objectweb.asm.ClassVisitor cv,
                                     java.lang.Class itf)
Generates a skeleton class for the given Java interface. This method generates a sub class of the Skeleton class whose target is an object implementing the given interface, by using the given class visitor.

Parameters:
cv - the class visitor to be used to generate the stub class.
itf - the Java interface implemented by the skeleton's target.

generateConstructor

protected void generateConstructor(org.objectweb.asm.ClassVisitor cv,
                                   java.lang.String superClass)
Generates an empty constructor for the given class.

Parameters:
cv - the class visitor to be used to generate the constructor.
superClass - the internal name of the super class of the generated class. This name is used to generate a call to the super constructor.

generateStubMethod

protected void generateStubMethod(org.objectweb.asm.ClassVisitor cv,
                                  java.lang.String name,
                                  java.lang.reflect.Method m,
                                  int index)
Generates a stub method. A stub method is of the following form:

           public <i>T</i> m (<i>T0 arg0</i>, ...) throws <i>E0</i>, ... {
             try {
               Marshaller marshaller = request();
               ReplyInterface reply = prepareInvocation(marshaller);
               marshaller.writeInt(<i>methodIndex</i>);
               marshaller.write<i>XXX</i>(<i>arg0</i>);
               ...
               invoke(marshaller);
               UnMarshaller unmarshaller = reply.listen();
               <i>T</i> result = (<i>T</i>)unmarshaller.read<i>XXX</i>();
               unmarshaller.close();
               return result;
             } catch (Exception e) {
               e = handleException(e);
               if (e instanceof <i>E0</i>) throw (<i>E0</i>)e;
               ...
               if (e instanceof RuntimeException) throw (RuntimeException)e;
               throw new RemoteException("server side exception", e);
             }
           }
 

Parameters:
cv - the class visitor to be used to generate the stub method.
name - the internal name of the generated stub class.
m - the signature of the method that must be generated.
index - the index of this method. This index will be marshalled by the generated stub method in each invocation message, to specify the method that must be called on the server side. This index is the index of the method in the sorted array of all the methods implemented by the stub.

generateSkeletonMethod

protected void generateSkeletonMethod(org.objectweb.asm.ClassVisitor cv,
                                      java.lang.String name,
                                      java.lang.Class itf)
Generates a skeleton's send method. The generated method is of the following form:

           public void send (UnMarshaller unmarshaller, ReplySession session)
             throws JonathanException
           {
             int methodIndex = unmarshaller.readInt();
             try {
               switch (methodIndex) {
                 case 0:
                   <i>T0 arg0</i> = unmarshaller.read<i>XXX</i>();
                   ...
                   unmarshaller.close();
                   <i>T</i> result = ((<i>I</i>)target).<i>m0</i>(<i>arg0</i>, ... );
                   Marshaller marshaller = session.prepareReply();
                   marshaller.write<i>XXX</i>(result);
                   session.send(marshaller);
                   session.close();
                   return;
                 ...
                 default:
                   handleInterfaceMethods(unmarshaller, session, methodIndex);
               }
             } catch (Exception e) {
               handleException(e, session);
             }
           }
 

Parameters:
cv - the class visitor to be used to generate the stub method.
name - the internal name of the generated stub class.
itf - the target object's interface that must be exported by the skeleton.

isClassParameter

protected boolean isClassParameter(java.lang.reflect.Method m,
                                   int p)
Returns true if the specified parameter contains the name of a class. This method is used to marshall a Class object, instead of a String, for parameters that contains class names, in order to enable these classes to be downloaded from the network if needed. The default implementation of this method returns true for:

Parameters:
m - a method.
p - index of a parameter of this method, or -1 to designate the return value.
Returns:
true if the specified parameter contains the name of a class.

sort

protected static void sort(java.lang.reflect.Method[] methods)
Sorts the given methods. This method is used to assign an unambiguous index to each method of an interface (the index of a method in the array returned by getMethods cannot directly be used for this purpose, since this method returns the methods in any order).

Parameters:
methods - the method array to be sorted.

getFcClassLoader

public java.lang.ClassLoader getFcClassLoader()
Description copied from interface: ClassLoaderController
Returns a class loader used by this component

Specified by:
getFcClassLoader in interface ClassLoaderController
Returns:
a class loader used by this component

setFcClassLoader

public void setFcClassLoader(java.lang.ClassLoader cl)
Description copied from interface: ClassLoaderController
Sets the class loader used by this component

Specified by:
setFcClassLoader in interface ClassLoaderController
Parameters:
cl - a class loader to be used by this component


Copyright © 2008 OW2 Consortium. All Rights Reserved.