|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.cojen.util.ClassInjector
public class ClassInjector
ClassInjector allows transient classes to be loaded, where a transient class is defined as being dynamically created at runtime. Unless explicit, the name given to transient classes is randomly assigned to prevent name collisions and to discourage referencing the classname persistently outside the runtime environment.
Classes defined by ClassInjector may be unloaded, if no references to it exist. Once unloaded, they cannot be loaded again by name since the original bytecode was never preserved.
Debugging can be enabled via the java command-line option "-Dcojen.util.ClassInjector.DEBUG=true". This causes all generated classes to be written to the temp directory, and a message is written to System.out indicating exactly where.
Method Summary | |
---|---|
static ClassInjector |
create()
Create a ClassInjector for defining one class. |
static ClassInjector |
create(String prefix,
ClassLoader parent)
Create a ClassInjector for defining one class. |
static ClassInjector |
createExplicit(String name,
ClassLoader parent)
Create a ClassInjector for defining one class with an explicit name. |
Class |
defineClass(ClassFile cf)
Define the new class from a ClassFile object. |
String |
getClassName()
Returns the name that must be given to the new class. |
Class |
getNewClass()
Returns the newly defined class. |
OutputStream |
openStream()
Open a stream to define the new class into. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static ClassInjector create()
public static ClassInjector create(String prefix, ClassLoader parent)
If the parent loader was used for loading injected classes, the new class will be loaded by it. This allows auto-generated classes access to package accessible members, as long as they are defined in the same package.
prefix
- optional class name prefixparent
- optional parent ClassLoaderpublic static ClassInjector createExplicit(String name, ClassLoader parent)
If the parent loader was used for loading injected classes, the new class will be loaded by it. This allows auto-generated classes access to package accessible members, as long as they are defined in the same package.
name
- required class nameparent
- optional parent ClassLoader
IllegalArgumentException
- if name is nullpublic String getClassName()
public OutputStream openStream() throws IllegalStateException
IllegalStateException
- if new class has already been defined
or if a stream has already been openedpublic Class defineClass(ClassFile cf)
IllegalStateException
- if new class has already been defined
or if a stream has already been openedpublic Class getNewClass() throws IllegalStateException, ClassFormatError
IllegalStateException
- if class was never defined
ClassFormatError
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |