org.codehaus.janino
Class JavaSourceClassLoader
java.lang.Object
java.lang.ClassLoader
org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
org.codehaus.janino.JavaSourceClassLoader
- Direct Known Subclasses:
- CachingJavaSourceClassLoader
public class JavaSourceClassLoader
- extends AbstractJavaSourceClassLoader
A ClassLoader that, unlike usual ClassLoaders,
does not load byte code, but reads Java™ 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.
|
Method Summary |
protected java.lang.Class |
defineBytecode(java.lang.String className,
byte[] ba)
|
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. |
void |
setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
|
void |
setDebuggingInfo(boolean debugSource,
boolean debugLines,
boolean debugVars)
|
void |
setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding)
|
void |
setSourcePath(java.io.File[] sourcePath)
|
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 |
debugSource
protected boolean debugSource
debugLines
protected boolean debugLines
debugVars
protected boolean debugVars
JavaSourceClassLoader
public JavaSourceClassLoader()
JavaSourceClassLoader
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader)
JavaSourceClassLoader
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader,
java.io.File[] optionalSourcePath,
java.lang.String optionalCharacterEncoding)
- Set up a
JavaSourceClassLoader that finds Java™ source code in a file
that resides in either of the directories specified by the given source path.
- Parameters:
parentClassLoader - See ClassLoaderoptionalSourcePath - A collection of directories that are searched for Java™ source files in
the given orderoptionalCharacterEncoding - The encoding of the Java™ source files (null for platform
default encoding)
JavaSourceClassLoader
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader,
ResourceFinder sourceFinder,
java.lang.String optionalCharacterEncoding)
- Set up a
JavaSourceClassLoader that finds Java™ 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)).
- Parameters:
parentClassLoader - See ClassLoadersourceFinder - Used to locate additional source filesoptionalCharacterEncoding - The encoding of the Java™ source files (null for platform
default encoding)
setSourcePath
public void setSourcePath(java.io.File[] sourcePath)
- Specified by:
setSourcePath in class AbstractJavaSourceClassLoader
- Parameters:
sourcePath - The sequence of directories to search for Java™ source files
setSourceFileCharacterEncoding
public void setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding)
- Specified by:
setSourceFileCharacterEncoding in class AbstractJavaSourceClassLoader
- Parameters:
optionalCharacterEncoding - if null, use platform default encoding
setDebuggingInfo
public void setDebuggingInfo(boolean debugSource,
boolean debugLines,
boolean debugVars)
- Specified by:
setDebuggingInfo in class AbstractJavaSourceClassLoader
- Parameters:
debugSource - Whether line number debugging information should be generateddebugLines - Whether variables debugging information should be generateddebugVars - Whether source file debugging information should be generated
setCompileErrorHandler
public void setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
- See Also:
UnitCompiler.setCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler)
setWarningHandler
public void setWarningHandler(WarningHandler optionalWarningHandler)
- See Also:
Parser.setWarningHandler(WarningHandler),
UnitCompiler.setCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler)
findClass
protected java.lang.Class findClass(java.lang.String name)
throws java.lang.ClassNotFoundException
- Implementation of
ClassLoader.findClass(String).
- Overrides:
findClass in class java.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
generateBytecodes
protected java.util.Map generateBytecodes(java.lang.String name)
throws java.lang.ClassNotFoundException
- Find, scan, parse the right compilation unit. Compile the parsed compilation unit to
bytecode. This may cause more compilation units being scanned and parsed. Continue until
all compilation units are compiled.
- Returns:
- String name => byte[] bytecode, or
null if no source code could be found
- Throws:
java.lang.ClassNotFoundException - on compilation problems
defineBytecodes
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). If
the bytecodes contains an entry for name, then the Class defined for that name
is returned.
- Parameters:
bytecodes - String name => byte[] bytecode
- Throws:
java.lang.ClassFormatError
defineBytecode
protected java.lang.Class defineBytecode(java.lang.String className,
byte[] ba)
- Throws:
java.lang.ClassFormatError- See Also:
AbstractJavaSourceClassLoader.setProtectionDomainFactory(org.codehaus.commons.compiler.AbstractJavaSourceClassLoader.ProtectionDomainFactory)
Copyright © 2001-2012. All Rights Reserved.