|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
org.codehaus.janino.JavaSourceClassLoader
public class JavaSourceClassLoader
A ClassLoader
that, unlike usual ClassLoader
s,
does not load byte code, but reads JavaTM source code and then scans, parses,
compiles and loads it into the virtual machine.
As with any ClassLoader
, it is not possible to "update" classes after they've been
loaded. The way to achieve this is to give up on the JavaSourceClassLoader
and create
a new one.
Nested Class Summary | |
---|---|
static interface |
JavaSourceClassLoader.ProtectionDomainFactory
|
Constructor Summary | |
---|---|
JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader,
java.io.File[] optionalSourcePath,
java.lang.String optionalCharacterEncoding,
EnumeratorSet debuggingInformation)
Set up a JavaSourceClassLoader that finds JavaTM source code in a file
that resides in either of the directories specified by the given source path. |
|
JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader,
ResourceFinder sourceFinder,
java.lang.String optionalCharacterEncoding,
EnumeratorSet debuggingInformation)
Set up a JavaSourceClassLoader that finds JavaTM source code through
a given ResourceFinder . |
Method Summary | |
---|---|
protected java.lang.Class |
defineBytecode(java.lang.String className,
byte[] ba)
Calls ClassLoader.defineClass(java.lang.String, byte[], int, int)
or ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain) ,
depending on whether or not a JavaSourceClassLoader.ProtectionDomainFactory was set. |
protected java.lang.Class |
defineBytecodes(java.lang.String name,
java.util.Map bytecodes)
Define a set of classes, like ClassLoader.defineClass(java.lang.String, byte[], int, int) . |
protected java.lang.Class |
findClass(java.lang.String name)
Implementation of ClassLoader.findClass(String) . |
protected java.util.Map |
generateBytecodes(java.lang.String name)
Find, scan, parse the right compilation unit. |
static void |
main(java.lang.String[] args)
Read JavaTM source code for a given class name, scan, parse, compile and load it into the virtual machine, and invoke its "main()" method with the given args. |
void |
setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
|
void |
setProtectionDomainFactory(JavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)
|
void |
setWarningHandler(WarningHandler optionalWarningHandler)
|
Methods inherited from class java.lang.ClassLoader |
---|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader, java.io.File[] optionalSourcePath, java.lang.String optionalCharacterEncoding, EnumeratorSet debuggingInformation)
JavaSourceClassLoader
that finds JavaTM source code in a file
that resides in either of the directories specified by the given source path.
You can specify to include certain debugging information in the generated class files, which
is useful if you want to debug through the generated classes (see
Scanner.Scanner(String, Reader)
).
parentClassLoader
- See ClassLoader
optionalSourcePath
- A collection of directories that are searched for JavaTM source files in the given orderoptionalCharacterEncoding
- The encoding of the JavaTM source files (null
for platform default encoding)debuggingInformation
- What kind of debugging information to generate, see DebuggingInformation
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader, ResourceFinder sourceFinder, java.lang.String optionalCharacterEncoding, EnumeratorSet debuggingInformation)
JavaSourceClassLoader
that finds JavaTM source code through
a given ResourceFinder
.
You can specify to include certain debugging information in the generated class files, which
is useful if you want to debug through the generated classes (see
Scanner.Scanner(String, Reader)
).
parentClassLoader
- See ClassLoader
sourceFinder
- Used to locate additional source filesoptionalCharacterEncoding
- The encoding of the JavaTM source files (null
for platform default encoding)debuggingInformation
- What kind of debugging information to generate, see DebuggingInformation
Method Detail |
---|
public static void main(java.lang.String[] args)
Usage is as follows:
java [ java-option ] org.codehaus.janino.JavaSourceClassLoader [ option ] ... class-name [ arg ] ... java-option Any valid option for the Java Virtual Machine (e.g. "-classpath colon-separated-list-of-class-directories") option: -sourcepath colon-separated-list-of-source-directories -encoding character-encoding -g Generate all debugging info"); -g:none Generate no debugging info"); -g:{lines,vars,source} Generate only some debugging info"); -cache dir Cache compiled classes here");
public void setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
UnitCompiler.setCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler)
public void setWarningHandler(WarningHandler optionalWarningHandler)
Parser.setWarningHandler(WarningHandler)
,
UnitCompiler.setCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler)
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
ClassLoader.findClass(String)
.
findClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected java.util.Map generateBytecodes(java.lang.String name) throws java.lang.ClassNotFoundException
null
if no source code could be found
java.lang.ClassNotFoundException
- on compilation problemsprotected java.lang.Class defineBytecodes(java.lang.String name, java.util.Map bytecodes) throws java.lang.ClassFormatError
ClassLoader.defineClass(java.lang.String, byte[], int, int)
.
If the bytecodes
contains an entry for name
, then the
Class
defined for that name is returned.
bytecodes
- String name => byte[] bytecode
java.lang.ClassFormatError
protected java.lang.Class defineBytecode(java.lang.String className, byte[] ba) throws java.lang.ClassFormatError
ClassLoader.defineClass(java.lang.String, byte[], int, int)
or ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain)
,
depending on whether or not a JavaSourceClassLoader.ProtectionDomainFactory
was set.
java.lang.ClassFormatError
setProtectionDomainFactory(org.codehaus.janino.JavaSourceClassLoader.ProtectionDomainFactory)
public void setProtectionDomainFactory(JavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)
|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |