|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.objectweb.fractal.julia.asm.AbstractClassGenerator
org.objectweb.fractal.julia.asm.InterceptorClassGenerator
A class generator to generate Interceptor classes. This
generator produces sub classes of a given class that implement a given set
of interfaces by adding interception code to the original code of each
method (this original code just forwards method calls to the getFcItfDelegate object). The interception
code is generated by CodeGenerator and/or ClassTransformer
objects.
The original code of each method is visited and adapted on the fly by the
code adapters returned by the code generators (see CodeGenerator),
resulting in a modified code that includes the interception
code generated by each code generator.
For example, if the original code void m () { impl.m() } is modified by the code adapter returned by a code generator A into:
void m () {
// pre code A
try {
impl.m();
} finally {
// post code A
}
}
and by the code adapter returned by a code generator B into:
void m () {
// pre code B
impl.m();
// post code B
}
then the original code will be modified by A and B, in this order (the last
code adapter is applied first), into:
void m () {
// pre code A
try {
// pre code B
impl.m();
// post code B
} finally {
// post code A
}
}
If the original code is modified by B and A, the result is:
void m () {
// pre code B
// pre code A
try {
impl.m();
} finally {
// post code A
}
// post code B
}
The complete class generated for an interface I containing only the
above m method, and with A = LifeCycleCodeGenerator and B =
TraceCodeGenerator, in this order, is the following (if there is more
than one interface, some additional casts are used - as in the InterfaceClassGenerator class):
public class XYZ
implements I, Interceptor, Generated
{
private I impl;
private UVW lc;
public XYZ (Object impl) {
setFcItfDelegate(impl);
}
public void m () {
synchronized(lc) {
if (lc.fcState != 2)
lc.incrementFcInvocationCounter();
else
lc.fcInvocationCounter++;
}
try {
System.err.println("Entering public abstract void I.m()");
impl.m();
System.err.println("Leaving public abstract void I.m()");
} finally {
synchronized (lc) {
if (lc.fcState != 2)
lc.decrementFcInvocationCounter();
else
lc.fcInvocationCounter--;
}
}
}
// overriden Controller methods
public void initFcController (InitializationContext ic) {
lc = (UVW)ic.getInterface("lifecycle-controller");
}
// Interceptor methods
public Object getFcItfDelegate () {
return impl;
}
public void setFcItfDelegate (Object o) {
impl = (I)o;
}
public Object clone () {
XYZ clone = new XYZ(impl);
clone.lc = lc;
return clone;
}
// Generated methods
public String getFcGeneratorParameters () {
return "((...InterceptorClassGenerator ...LifeCycleCodeGenerator
...TraceCodeGenerator) java.lang.Object (I) (...) in)";
}
}
This class generator can be used in two different ways, corresponding to
the optimization levels of
components:
Interceptor interface is not implemented.ClassTransformers can be used only with the
mergeControllersInterceptorsAndContent option. These transformers
transform the "user component" class, before the interception code is
added by the CodeGenerators. If class transformers are
used, the generated class is not generated as a sub class of the given
super class: instead, the code of this super class (and of its own super
class) is directly copied (after tranformation) into the generated class.
| Field Summary | |
|---|---|
Tree |
args
The arguments of the class that is being generated. |
ClassTransformer[] |
classTransformers
The class transformers used by this interceptor class generator. |
Tree |
codeGenDescs
Descriptors of the code generators used by this class generator. |
CodeGenerator[] |
codeGens
The code generators used by this interceptor class generator. |
Class[] |
controllerClasses
The controller classes that can be used by the generated interceptor class. |
String |
implFieldDesc
The "impl" field descriptor. |
String |
implFieldName
The "impl" field name. |
boolean |
in
true if the class to be generated is an input interceptor class. |
boolean |
isComposite
Indicates if the interceptors are generated for a composite component. |
boolean |
mergeAll
Indicates if the controller, interceptor and content classes are merged. |
boolean |
mergeInterceptors
Indicates if the controller and interceptor classes are merged. |
| Fields inherited from class org.objectweb.fractal.julia.asm.AbstractClassGenerator |
|---|
cw, interfaces, loader, name, parameters, superClass |
| Constructor Summary | |
|---|---|
InterceptorClassGenerator()
|
|
| Method Summary | |
|---|---|
protected boolean |
computeMaxs()
Returns true. |
byte[] |
generateClass(String name,
Tree args,
Loader loader)
Initializes the specific fields of this class before calling the overriden method. |
protected void |
generateConstructor()
Generates the constructor of the class to be generated. |
protected void |
generateDefaultMethods()
Calls the overriden method and generates the "impl" field and the methods of the Interceptor interface. |
protected void |
generateInterfaceMethods()
Generates the methods of the interfaces to be implemented by the class to be generated. |
protected void |
generateMethod(Method m)
Generates the interception code for the given method. |
protected List |
getImplementedInterfaces()
Adds Interceptor to the list returned by the overriden
method. |
protected String |
getSource()
Returns the source of the class to be generated. |
void |
initialize(Tree args)
Initializes this object with the given arguments. |
protected void |
parseArgs(Tree args)
Initializes this class generator with the given arguments. |
| Methods inherited from class org.objectweb.fractal.julia.asm.AbstractClassGenerator |
|---|
generateHeader, getOpcodeOffset, getSize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public Tree args
public Tree codeGenDescs
public CodeGenerator[] codeGens
public ClassTransformer[] classTransformers
public Class[] controllerClasses
public boolean in
public boolean mergeInterceptors
public boolean mergeAll
public boolean isComposite
public String implFieldName
public String implFieldDesc
| Constructor Detail |
public InterceptorClassGenerator()
| Method Detail |
public void initialize(Tree args)
initialize in interface Initializableargs - the descriptors of the code generators to be used by this
interceptor class generator. This tree must be a list of object
descriptors (see @link Loader#createObject createObject}, each object
descriptor describing a CodeGenerator.
public byte[] generateClass(String name,
Tree args,
Loader loader)
throws ClassGenerationException
generateClass in interface ClassGeneratorgenerateClass in class AbstractClassGeneratorname - the name of the class to be generated.args - a tree of the form "(object descriptor superClass (itf1 ...
itfN) (class1 ... classM) in|out)", where itf1 ... itfN are the names
of the interfaces that the generated class must implement, class1 ...
classM are the names of the controller classes that can used by the
generated interceptor class, and in or out indicates if an input or
output interceptor class must be generated.loader - the class loader to be used to generate the specified class.
This parameter, which may be null, can be a class loader, a
class, or any other object (the class loader is then found by using
the getClass() and getClassLoader() methods).
ClassGenerationException - if any other problem occurs.protected void parseArgs(Tree args)
AbstractClassGenerator
parseArgs in class AbstractClassGeneratorargs - the descriptor of the class to be generated.protected boolean computeMaxs()
computeMaxs in class AbstractClassGeneratorprotected String getSource()
getSource in class AbstractClassGenerator
protected List getImplementedInterfaces()
throws ClassGenerationException
Interceptor to the list returned by the overriden
method. In fact this interface is not added if the interceptors are merged
with the controller objects, and if isComposite is false.
getImplementedInterfaces in class AbstractClassGeneratorClassGenerationException - if a problem occurs.
protected void generateConstructor()
throws ClassGenerationException
AbstractClassGenerator
generateConstructor in class AbstractClassGeneratorClassGenerationException - if a problem occurs.
protected void generateDefaultMethods()
throws ClassGenerationException
Interceptor interface. This method also
generates the "initFcController" method, by concatenating the code
generated by the generateInitCode
method of each code generator. If the interceptor and controller objects
are merged, and if isComposite is false, this method just calls the
overriden method and sets the "impl" field to the "fcContent" field.
generateDefaultMethods in class AbstractClassGeneratorClassGenerationException - if a problem occurs.
protected void generateInterfaceMethods()
throws ClassGenerationException
AbstractClassGeneratorgenerateMethod for
each method of each interface to be implemented (generateMethod is called only once per method, even for those that are
specified in several interfaces).
generateInterfaceMethods in class AbstractClassGeneratorClassGenerationException - if a problem occurs.
protected void generateMethod(Method m)
throws ClassGenerationException
generateMethod in class AbstractClassGeneratorm - the method to be generated.
ClassGenerationException - if a problem occurs.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||