org.objectweb.fractal.julia.asm
Class ContextClassGenerator

java.lang.Object
  extended by org.objectweb.fractal.julia.asm.ContextClassGenerator
All Implemented Interfaces:
Opcodes, ClassGenerator

public class ContextClassGenerator
extends Object
implements Opcodes, ClassGenerator

A class generator to generate InitializationContext classes. This class generates classes of the following form:

 public class XYZ extends InitializationContext implements Generated {

   private static ComponentType componentType;
   private static ComponentType internalComponentType;

   public void create() {
     super.create();
     ComponentType compType;
     if (componentType == null) {
       TypeFactory tf = (TypeFactory)hints;
       componentType = tf.createFcType(new InterfaceType[] {
         tf.createFcItfType(...),
         ...
         tf.createFcItfType(...)
       });
       internalComponentType = tf.createFcType(new InterfaceType[] {
         tf.createFcItfType(...),
         ...
         tf.createFcItfType(...)
       });
     }
     compType = componentType;
     controllers.add(new controller-class1());
     ...
     controllers.add(new controller-classN());
   [ if (content == null) content = new content-class(); ]
     Component owner = null;
     Object impl = controllers.get(0);
     interfaces.put("component", owner = new interface-class1(..., impl));
     ...
     impl = controllers.get(I); // or impl = content;
   [ impl = new interceptor-classM(impl); ]
   [ controllers.add(impl);                      ]
     interfaces.put("...", new interface-classM(..., impl));
   [ internalInterfaces.put("...", new interface-classM(..., impl)); ]
     return;
   }

   public String getFcGeneratorParameters() {
     return "(... ...)";
   }
 }
 


Field Summary
 
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
ContextClassGenerator()
           
 
Method Summary
 void computeInterfaceTypes()
          Computes all the interface types of the component.
 byte[] generateClass(String name, Tree args, Loader loader, ClassLoader classLoader)
          Generates the class whose descriptor is given, with the given name.
 void generateCreateContent(MethodVisitor mv)
          Generates the code to create the component's content.
 void generateCreateControllers(MethodVisitor mv)
          Generates the code to create the component's controller objects.
 void generateCreateInterfaces(MethodVisitor mv)
          Generates the code to create the component interfaces.
 void generateCreateType(MethodVisitor mv)
          Generates the code to initialize the "componentType" and "internalComponentType" static fields of the generated class.
protected  Tree generateTreeDescriptor(Tree itfClassGen, Tree itf)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextClassGenerator

public ContextClassGenerator()
Method Detail

generateClass

public byte[] generateClass(String name,
                            Tree args,
                            Loader loader,
                            ClassLoader classLoader)
                     throws ClassGenerationException
Generates the class whose descriptor is given, with the given name.

Specified by:
generateClass in interface ClassGenerator
Parameters:
name - the name of the class to be generated.
args - the descriptor of the class to be generated. This descriptor must be of the form "(type-descriptor controller-descriptor content-descriptor)", where "type-descriptor" is of the form "((name signature isClient isOptional isCollection) ...)", "controller-descriptor" is of the form described in the Julia tutorial, and "content-descriptor" is a fully qualified class name or "EMPTY".
loader - the loader to be used to load or generate auxiliary classes, if needed.
classLoader - the class loader to be used to load auxiliary classes, if needed.
Returns:
a class named name and whose content is described by the given class descriptor.
Throws:
ClassGenerationException - if a problem occurs during the generation of the class.

computeInterfaceTypes

public void computeInterfaceTypes()
Computes all the interface types of the component. This method merges the control interface type descriptors and the functional interface type descriptors into a single descriptor "interfaceTypes"


generateCreateType

public void generateCreateType(MethodVisitor mv)
Generates the code to initialize the "componentType" and "internalComponentType" static fields of the generated class.

Parameters:
mv - the code visitor to be used to generate the code.

generateCreateControllers

public void generateCreateControllers(MethodVisitor mv)
                               throws ClassGenerationException
Generates the code to create the component's controller objects.

Parameters:
mv - the code visitor to be used to generate the code.
Throws:
ClassGenerationException - if a problem occurs

generateCreateContent

public void generateCreateContent(MethodVisitor mv)
                           throws ClassGenerationException
Generates the code to create the component's content.

Parameters:
mv - the code visitor to be used to generate the code.
Throws:
ClassGenerationException - if the component's content class cannot be found.

generateCreateInterfaces

public void generateCreateInterfaces(MethodVisitor mv)
                              throws ClassGenerationException
Generates the code to create the component interfaces.

Parameters:
mv - the code visitor to be used to generate the code.
Throws:
ClassGenerationException - if a problem occurs.

generateTreeDescriptor

protected Tree generateTreeDescriptor(Tree itfClassGen,
                                      Tree itf)