javassist.tools.reflect
Class Loader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by javassist.Loader
          extended by javassist.tools.reflect.Loader

public class Loader
extends Loader

A class loader for reflection.

To run a program, say MyApp, including a reflective class, you must write a start-up program as follows:

Then run this program as follows:

This command runs Main.main() with arg1, ... and Main.main() runs MyApp.main() with arg1, ... The Person class is modified to be a reflective class. Method calls on a Person object are intercepted by an instance of MyMetaobject.

Also, you can run MyApp in a slightly different way:

This program is run as follows:

The difference from the former one is that the class Main is loaded by javassist.tools.reflect.Loader whereas the class Main2 is not. Thus, Main belongs to the same name space (security domain) as MyApp whereas Main2 does not; Main2 belongs to the same name space as javassist.tools.reflect.Loader. For more details, see the notes in the manual page of javassist.Loader.

The class Main2 is equivalent to this class:

Note:

javassist.tools.reflect.Loader does not make a class reflective if that class is in a java.* or javax.* pacakge because of the specifications on the class loading algorithm of Java. The JVM does not allow to load such a system class with a user class loader.

To avoid this limitation, those classes should be statically modified with javassist.tools.reflect.Compiler and the original class files should be replaced.

See Also:
Reflection, Compiler, Loader

Field Summary
 
Fields inherited from class javassist.Loader
doDelegation
 
Constructor Summary
Loader()
          Constructs a new class loader.
 
Method Summary
static void main(java.lang.String[] args)
          Loads a class with an instance of Loader and calls main() in that class.
 boolean makeReflective(java.lang.String clazz, java.lang.String metaobject, java.lang.String metaclass)
          Produces a reflective class.
 
Methods inherited from class javassist.Loader
addTranslator, delegateLoadingOf, run, run, setClassPool, setDomain
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Loader

public Loader()
       throws CannotCompileException,
              NotFoundException
Constructs a new class loader.

Throws:
CannotCompileException
NotFoundException
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Loads a class with an instance of Loader and calls main() in that class.

Parameters:
args - command line parameters.
    args[0] is the class name to be loaded.
    args[1..n] are parameters passed to the target main().
Throws:
java.lang.Throwable

makeReflective

public boolean makeReflective(java.lang.String clazz,
                              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:
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


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