|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.iternine.jeppetto.enhance.ClassLoadingUtil
public final class ClassLoadingUtil
Provides utility methods for defining javassist CtClass objects in
arbitrary ClassLoaders.
Foo, and the code:
CtClass myFooExtension = ...; // use javassist to 'extend' Foo and inject bytecode Class cls = myFooExtension.toClass(); Foo foo = (Foo) cls.newInstance();The last line of this sample code would throw a ClassCastException because Foo, on the left, was loaded by the system classloader and MyFooExtension, on the right, was loaded in another classloader. To work around this, use this utility:
CtClass myFooExtension = ...; // same as above Class cls = ClassLoadingUtil.toClass(myFooExtension, Foo.class.getClassLoader(), null); Foo foo = (Foo) cls.newInstance();And enjoy!
| Method Summary | ||
|---|---|---|
static
|
toClass(javassist.CtClass ctClass)
Installs the given CtClass into the current class-loader and returns
it as a new class. |
|
static
|
toClass(javassist.CtClass ctClass,
ClassLoader loader,
ProtectionDomain domain)
Installs the given CtClass into the given class-loader and returns
it as a new class. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> Class<T> toClass(javassist.CtClass ctClass)
throws javassist.CannotCompileException
CtClass into the current class-loader and returns
it as a new class.
T - class typectClass - class to load
javassist.CannotCompileException - if the class cannot be compiled
public static <T> Class<T> toClass(javassist.CtClass ctClass,
ClassLoader loader,
ProtectionDomain domain)
throws javassist.CannotCompileException
CtClass into the given class-loader and returns
it as a new class.
T - class typectClass - class to loadloader - class-loader to install intodomain - protection domain, may be null
javassist.CannotCompileException - if the class cannot be compiled
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||