koala.dynamicjava.interpreter
Class ClassFactory

java.lang.Object
  extended bykoala.dynamicjava.classfile.BytecodeComponent
      extended bykoala.dynamicjava.classfile.AttributeOwnerComponent
          extended bykoala.dynamicjava.classfile.ClassFile
              extended bykoala.dynamicjava.interpreter.ClassFactory

public class ClassFactory
extends ClassFile

The instances of this class dynamically create java classes


Field Summary
 
Fields inherited from class koala.dynamicjava.classfile.AttributeOwnerComponent
accessFlags, attributes
 
Fields inherited from class koala.dynamicjava.classfile.BytecodeComponent
constantPool, nameIndex
 
Constructor Summary
ClassFactory(int af, java.lang.String name, java.lang.String sname, java.lang.Class interp, java.lang.Class except, java.lang.String clid)
          Creates a new class factory for an innerclass
 
Method Summary
 void addConstantBooleanField(int af, java.lang.String ft, java.lang.String nm, java.lang.Boolean v)
          Adds a constant boolean field to the class.
 void addConstantDoubleField(int af, java.lang.String ft, java.lang.String nm, java.lang.Double v)
          Adds a constant double field to the class.
 void addConstantFloatField(int af, java.lang.String ft, java.lang.String nm, java.lang.Float v)
          Adds a constant float field to the class.
 void addConstantIntField(int af, java.lang.String ft, java.lang.String nm, java.lang.Integer v)
          Adds a constant int field to the class.
 void addConstantLongField(int af, java.lang.String ft, java.lang.String nm, java.lang.Long v)
          Adds a constant long field to the class.
 void addConstantStringField(int af, java.lang.String ft, java.lang.String nm, java.lang.String v)
          Adds a constant string field to the class.
 java.lang.String addConstructor(int af, java.lang.String[] pt, java.lang.String[] ex, java.lang.String sup, java.lang.String[] st)
          Adds a constructor to the class.
 void addField(int af, java.lang.String ft, java.lang.String nm)
          Adds a field to the class.
 InnerClassesEntry addInnerClassesEntry()
          Adds an InnerClasses entry
 java.lang.String addMethod(int af, java.lang.String rt, java.lang.String nm, java.lang.String[] pt, java.lang.String[] ex)
          Adds a method to the class.
 void addSuperMethodAccessor(int af, java.lang.String rt, java.lang.String nm, java.lang.String[] pt, java.lang.String[] ex)
          Adds a method that calls the supermethod of the given method
 java.lang.String createClassInitializer()
          Creates the class initializer.
 byte[] getByteCode()
          Returns the generated class
static java.lang.String getMethodIdentifier(java.lang.String cname, java.lang.String mname, java.lang.String[] pnames, java.lang.String clid)
          Computes a method identifier.
 
Methods inherited from class koala.dynamicjava.classfile.ClassFile
addInterface, createField, createMethod, getConstantPool, setAbstract, setFinal, setInnerClassesAttribute, setInterface, setPublic, setSuper, write
 
Methods inherited from class koala.dynamicjava.classfile.AttributeOwnerComponent
setAccessFlags, setSyntheticAttribute
 
Methods inherited from class koala.dynamicjava.classfile.BytecodeComponent
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFactory

public ClassFactory(int af,
                    java.lang.String name,
                    java.lang.String sname,
                    java.lang.Class interp,
                    java.lang.Class except,
                    java.lang.String clid)
Creates a new class factory for an innerclass

Parameters:
af - the access flags
name - the name of the class to create
sname - the name of the superclass
interp - the class of the interpreter used to evaluate the body of the methods. It must implement methods with the following signatures:
public static Object[] interpretArguments (String key, Object[] args)
public static Object invokeMethod (String key, Object obj, Object[] args)
except - the class of the exception used to manage exception throwing. It must implement a method with the following signature:
public Throwable getException().
clid - the class loader identifier
Method Detail

getMethodIdentifier

public static java.lang.String getMethodIdentifier(java.lang.String cname,
                                                   java.lang.String mname,
                                                   java.lang.String[] pnames,
                                                   java.lang.String clid)
Computes a method identifier. It starts with the name of the class followed by a '#'.

Parameters:
cname - the name of the class
mname - the name of the method
pnames - the names of the parameter classes
clid - the classloader identifier

createClassInitializer

public java.lang.String createClassInitializer()
Creates the class initializer.

Returns:
the method identifier

addConstructor

public java.lang.String addConstructor(int af,
                                       java.lang.String[] pt,
                                       java.lang.String[] ex,
                                       java.lang.String sup,
                                       java.lang.String[] st)
Adds a constructor to the class. The body is automatically generated.

Parameters:
af - the access flags
pt - the parameters types
ex - the exceptions thrown
sup - the name of the super constructor
st - the initialization method parameter types
Returns:
the constructor identifier

addField

public void addField(int af,
                     java.lang.String ft,
                     java.lang.String nm)
Adds a field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantIntField

public void addConstantIntField(int af,
                                java.lang.String ft,
                                java.lang.String nm,
                                java.lang.Integer v)
Adds a constant int field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantLongField

public void addConstantLongField(int af,
                                 java.lang.String ft,
                                 java.lang.String nm,
                                 java.lang.Long v)
Adds a constant long field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantFloatField

public void addConstantFloatField(int af,
                                  java.lang.String ft,
                                  java.lang.String nm,
                                  java.lang.Float v)
Adds a constant float field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantDoubleField

public void addConstantDoubleField(int af,
                                   java.lang.String ft,
                                   java.lang.String nm,
                                   java.lang.Double v)
Adds a constant double field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantBooleanField

public void addConstantBooleanField(int af,
                                    java.lang.String ft,
                                    java.lang.String nm,
                                    java.lang.Boolean v)
Adds a constant boolean field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addConstantStringField

public void addConstantStringField(int af,
                                   java.lang.String ft,
                                   java.lang.String nm,
                                   java.lang.String v)
Adds a constant string field to the class.

Parameters:
af - the access flags
ft - the field type
nm - the field name

addInnerClassesEntry

public InnerClassesEntry addInnerClassesEntry()
Adds an InnerClasses entry


addSuperMethodAccessor

public void addSuperMethodAccessor(int af,
                                   java.lang.String rt,
                                   java.lang.String nm,
                                   java.lang.String[] pt,
                                   java.lang.String[] ex)
Adds a method that calls the supermethod of the given method

Parameters:
af - the access flags
rt - the return type
nm - the name of the method
pt - the parameters types
ex - the exceptions thrown

addMethod

public java.lang.String addMethod(int af,
                                  java.lang.String rt,
                                  java.lang.String nm,
                                  java.lang.String[] pt,
                                  java.lang.String[] ex)
Adds a method to the class. The body is automatically generated.

Parameters:
af - the access flags
rt - the return type
nm - the name of the method
pt - the parameters types
ex - the exceptions thrown
Returns:
the method identifier

getByteCode

public byte[] getByteCode()
Returns the generated class



Copyright © 2001 Stephane Hillion. All Rights Reserved.