Class Loader
- java.lang.Object
-
- java.lang.ClassLoader
-
- de.ufinke.cubaja.cafebabe.Loader
-
public class Loader extends ClassLoader
ClassLoaderwhich loads generated bytecode. AGeneratormust be set bysetGenerator(de.ufinke.cubaja.cafebabe.Generator)beforefindClass(java.lang.String)is called indirectly byClassLoader.loadClass(java.lang.String).There may be a system property
de.ufinke.cubaja.cafebabe.dumpwith a path name as its value. If the property exists, the 'loaded' bytecode will be dumped into the given directory.Because of the dependencies between
setGeneratorandfindClass, this class is not threadsafe.- Author:
- Uwe Finke
-
-
Constructor Summary
Constructors Constructor Description Loader()Default constructor.Loader(ClassLoader parentLoader)Constructor with explicit parent class loader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Class<?>createClass(Generator generator, Object... nameSuffix)static Class<?>createClass(Class<?> contextClass, Generator generator, Object... nameSuffix)Convenience method to generate and load a class.protected Class<?>findClass(String className)Calls the generator and defines theClass.voidsetGenerator(Generator generator)Sets the generator.-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
Loader
public Loader()
Default constructor. Parent class loader is the system class loader.
-
Loader
public Loader(ClassLoader parentLoader)
Constructor with explicit parent class loader.- Parameters:
parentLoader- parent class loader
-
-
Method Detail
-
createClass
public static Class<?> createClass(Class<?> contextClass, Generator generator, Object... nameSuffix) throws ClassNotFoundException
Convenience method to generate and load a class.
Creates a
Loaderwith theClassLoaderof a context class as parent loader and passes theGeneratorto it. The name of the generated class is'Generated'plus the givennameSuffixes, each separated by an underline character. If anameSuffixis of typeClass, the class name is used as nameSuffix. Dots in anameSuffixare replaced by underlines.- Parameters:
contextClass- context classgenerator- generatornameSuffix- optional name suffixes to build the name of the generated class- Returns:
- generated class
- Throws:
ClassNotFoundException- when the context class could not be found
-
createClass
public static Class<?> createClass(Generator generator, Object... nameSuffix) throws ClassNotFoundException
- Parameters:
generator- generatornameSuffix- optional name suffixes to build the name of the generated class- Returns:
- generated class
- Throws:
ClassNotFoundException- when the context class could not be found
-
setGenerator
public void setGenerator(Generator generator)
Sets the generator.- Parameters:
generator- the generator
-
findClass
protected Class<?> findClass(String className) throws ClassNotFoundException
Calls the generator and defines theClass.- Overrides:
findClassin classClassLoader- Parameters:
className- name of class to find- Throws:
ClassNotFoundException
-
-