| java.lang.Object org.cojen.util.ClassInjector
ClassInjector | public class ClassInjector (Code) | | 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.
author: Brian S O'Neill |
create | public static ClassInjector create()(Code) | | Create a ClassInjector for defining one class. The parent ClassLoader
used is the one which loaded the ClassInjector class.
|
create | public static ClassInjector create(String prefix, ClassLoader parent)(Code) | | Create a ClassInjector for defining one class. The prefix is optional,
which is used as the start of the auto-generated class name. If the
parent ClassLoader is not specified, it will default to the ClassLoader of
the ClassInjector class.
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.
Parameters: prefix - optional class name prefix Parameters: parent - optional parent ClassLoader |
createExplicit | public static ClassInjector createExplicit(String name, ClassLoader parent)(Code) | | Create a ClassInjector for defining one class with an explicit name. If
the parent ClassLoader is not specified, it will default to the
ClassLoader of the ClassInjector class.
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.
Parameters: name - required class name Parameters: parent - optional parent ClassLoader throws: IllegalArgumentException - if name is null |
defineClass | public Class defineClass(ClassFile cf)(Code) | | Define the new class from a ClassFile object.
the newly created class throws: IllegalStateException - if new class has already been definedor if a stream has already been opened |
getClassName | public String getClassName()(Code) | | Returns the name that must be given to the new class.
|
|
|