edu.ucsb.ccs.jcontractor.transformation
Class ClassTransformer

java.lang.Object
  |
  +--edu.ucsb.ccs.jcontractor.transformation.ClassTransformer

public class ClassTransformer
extends java.lang.Object

A ClassTransformer executes a complex transformation on a JavaClass object. The complex transform is made up of simpler transforms that are carried out in sequence on the class itself and on each method.

Transformations are stored as a list, and are executed in the order that they appear. The list may be modified with insert(Transformation) and append(Transformation). Use the transform(JavaClass) method to apply the transformations to a class.

Version:
$Id: ClassTransformer.java,v 1.11 2002/07/13 22:57:05 parkera Exp $
Author:
Parker Abercrombie
See Also:
Transformation

Constructor Summary
ClassTransformer(InstrumentationFilter filter)
          Create an empty ClassTransformer.
 
Method Summary
 void append(Transformation t)
          Add a Transformation at the end of the transformation list.
 org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
          Get the ConstantPoolGen object that is to be used to build the constant pool for the current class.
 org.apache.bcel.classfile.JavaClass getCurrentClass()
          Get the class that the transformer is transforming.
 org.apache.bcel.generic.InstructionFactory getInstructionFactory()
          Get the instruction factory that should be used to create instructions.
 InstrumentationFilter getInstrumentationFilter()
          Get the instrumentation filter that determines which classes are instrumented and to what level.
 MethodSet getMethodSet()
          Get the method set that holds working copies of the methods in the current class.
 java.util.Hashtable getSharedInfo()
          Get the shared data table.
 void insert(Transformation t)
          Insert a transformation at the beginning of the list.
 void setInstructionFactory(org.apache.bcel.generic.InstructionFactory factory)
          Set the instruction factory to be used to create bytecode for the current class.
 void setInstrumentationFilter(InstrumentationFilter filter)
          Set the instrumentation filter that determines which classes are instrumented and to what level.
 int size()
          Get the number of transformations in the transformer.
 void transform(org.apache.bcel.classfile.JavaClass javaclass)
          Transform a class.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassTransformer

public ClassTransformer(InstrumentationFilter filter)
Create an empty ClassTransformer.

Method Detail

transform

public void transform(org.apache.bcel.classfile.JavaClass javaclass)
               throws AbortTransformationException
Transform a class. Each Transform in `transforms' will be offered the opportunity to operate on the class. The transforms will be applied in the order in which they appear in the `transforms' list.

Parameters:
javaclass - a class to transform.
AbortTransformationException

insert

public void insert(Transformation t)
Insert a transformation at the beginning of the list.

Parameters:
t - a transformation to insert. Note: a Transformation can be added to only one ClassTransformer. Henceforth, t will be attached to this ClassTransformation, overriding any previous affiliation.

append

public void append(Transformation t)
Add a Transformation at the end of the transformation list.

Parameters:
t - a transformation to insert. Note: a Transformation can be added to only one ClassTransformer. Henceforth, t will be attached to this ClassTransformation, overriding any previous affiliation.

size

public int size()
Get the number of transformations in the transformer.

Returns:
the number of transformations.

getCurrentClass

public org.apache.bcel.classfile.JavaClass getCurrentClass()
Get the class that the transformer is transforming. The current class is only meaningful when executing the transform method, so only Transformation objects should call this method.

Returns:
the class being transformed.

getConstantPoolGen

public org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
Get the ConstantPoolGen object that is to be used to build the constant pool for the current class. This is only meaningful when executing the transform method (when there is a current class), so only Transformation objects should call this method.

Returns:
a ConstantPoolGen for the current class.

getMethodSet

public MethodSet getMethodSet()
Get the method set that holds working copies of the methods in the current class. This set is only meaningful when executing the transform method, so only Transformation objects should call this method.

Returns:
a MethodSet containing working copies of the methods contained in the current class. Transformations are allowed to add, modify, and remove methods in the set.

getSharedInfo

public java.util.Hashtable getSharedInfo()
Get the shared data table. This table is provided so that Transformations can communicate with each other in a crude way. If one transformation has a piece of data needed by a subsequent transformation, it may store it in this table, indexed by a published key. This table is cleared between calls to transform.

Returns:
the shared data table.

getInstructionFactory

public org.apache.bcel.generic.InstructionFactory getInstructionFactory()
Get the instruction factory that should be used to create instructions. This factory has been initialized with the correct constant pool for the current class.

Returns:
the instruction factory that is to be used to create bytecode to insert into the current class.

setInstructionFactory

public void setInstructionFactory(org.apache.bcel.generic.InstructionFactory factory)
Set the instruction factory to be used to create bytecode for the current class. The constant pool in this factory will be set by the transform(JavaClass) method, so it is not neccessary to reset the factory after every class is transformed.

Parameters:
factory - the new instruction factory.

setInstrumentationFilter

public void setInstrumentationFilter(InstrumentationFilter filter)
Set the instrumentation filter that determines which classes are instrumented and to what level.

Parameters:
filter - the new filter.
See Also:
getInstrumentationFilter()

getInstrumentationFilter

public InstrumentationFilter getInstrumentationFilter()
Get the instrumentation filter that determines which classes are instrumented and to what level.

Returns:
the filter that determines which classes are instrumented.
See Also:
setInstrumentationFilter(InstrumentationFilter)