javassist.tools.reflect
Class Reflection

java.lang.Object
  extended by javassist.tools.reflect.Reflection
All Implemented Interfaces:
Translator

public class Reflection
extends java.lang.Object
implements Translator

The class implementing the behavioral reflection mechanism.

If a class is reflective, then all the method invocations on every instance of that class are intercepted by the runtime metaobject controlling that instance. The methods inherited from the super classes are also intercepted except final methods. To intercept a final method in a super class, that super class must be also reflective.

To do this, the original class file representing a reflective class:

is modified so that it represents a class:

See Also:
ClassMetaobject, Metaobject, Loader, Compiler

Constructor Summary
Reflection()
          Constructs a new Reflection object.
 
Method Summary
 boolean makeReflective(java.lang.Class clazz, java.lang.Class metaobject, java.lang.Class metaclass)
          Produces a reflective class.
 boolean makeReflective(CtClass clazz, CtClass metaobject, CtClass metaclass)
          Produces a reflective class.
 boolean makeReflective(java.lang.String classname, java.lang.String metaobject, java.lang.String metaclass)
          Produces a reflective class.
 void onLoad(ClassPool pool, java.lang.String classname)
          Inserts hooks for intercepting accesses to the fields declared in reflective classes.
 void start(ClassPool pool)
          Initializes the object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflection

public Reflection()
Constructs a new Reflection object.

Method Detail

start

public void start(ClassPool pool)
           throws NotFoundException
Initializes the object.

Specified by:
start in interface Translator
Parameters:
pool - the ClassPool that this translator should use.
Throws:
NotFoundException - if a CtClass cannot be found.
See Also:
Loader

onLoad

public void onLoad(ClassPool pool,
                   java.lang.String classname)
            throws CannotCompileException,
                   NotFoundException
Inserts hooks for intercepting accesses to the fields declared in reflective classes.

Specified by:
onLoad in interface Translator
Parameters:
pool - the ClassPool that this translator should use.
classname - the name of the class being loaded.
Throws:
CannotCompileException - if the code transformation by this method fails.
NotFoundException - if a CtClass cannot be found.
See Also:
Loader

makeReflective

public boolean makeReflective(java.lang.String classname,
                              java.lang.String metaobject,
                              java.lang.String metaclass)
                       throws CannotCompileException,
                              NotFoundException
Produces a reflective class. If the super class is also made reflective, it must be done before the sub class.

Parameters:
classname - the name of the reflective class
metaobject - the class name of metaobjects.
metaclass - the class name of the class metaobject.
Returns:
false if the class is already reflective.
Throws:
CannotCompileException
NotFoundException
See Also:
Metaobject, ClassMetaobject

makeReflective

public boolean makeReflective(java.lang.Class clazz,
                              java.lang.Class metaobject,
                              java.lang.Class metaclass)
                       throws CannotCompileException,
                              NotFoundException
Produces a reflective class. If the super class is also made reflective, it must be done before the sub class.

Parameters:
clazz - the reflective class.
metaobject - the class of metaobjects. It must be a subclass of Metaobject.
metaclass - the class of the class metaobject. It must be a subclass of ClassMetaobject.
Returns:
false if the class is already reflective.
Throws:
CannotCompileException
NotFoundException
See Also:
Metaobject, ClassMetaobject

makeReflective

public boolean makeReflective(CtClass clazz,
                              CtClass metaobject,
                              CtClass metaclass)
                       throws CannotCompileException,
                              CannotReflectException,
                              NotFoundException
Produces a reflective class. It modifies the given CtClass object and makes it reflective. If the super class is also made reflective, it must be done before the sub class.

Parameters:
clazz - the reflective class.
metaobject - the class of metaobjects. It must be a subclass of Metaobject.
metaclass - the class of the class metaobject. It must be a subclass of ClassMetaobject.
Returns:
false if the class is already reflective.
Throws:
CannotCompileException
CannotReflectException
NotFoundException
See Also:
Metaobject, ClassMetaobject


Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2010 Shigeru Chiba. All Rights Reserved.