public class JavaSourceClassLoader extends AbstractJavaSourceClassLoader
ClassLoader
that, unlike usual ClassLoader
s,
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.
AbstractJavaSourceClassLoader.ProtectionDomainFactory
Modifier and Type | Field and Description |
---|---|
protected boolean |
debugLines |
protected boolean |
debugSource |
protected boolean |
debugVars |
optionalProtectionDomainFactory
Constructor and Description |
---|
JavaSourceClassLoader() |
JavaSourceClassLoader(ClassLoader parentClassLoader) |
JavaSourceClassLoader(ClassLoader parentClassLoader,
File[] optionalSourcePath,
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. |
JavaSourceClassLoader(ClassLoader parentClassLoader,
ResourceFinder sourceFinder,
String optionalCharacterEncoding)
Set up a
JavaSourceClassLoader that finds Java™ source code through
a given ResourceFinder . |
Modifier and Type | Method and Description |
---|---|
protected Class |
defineBytecode(String className,
byte[] ba) |
protected Class |
defineBytecodes(String name,
Map bytecodes)
Define a set of classes, like
ClassLoader.defineClass(java.lang.String, byte[], int, int) . |
protected Class |
findClass(String name)
Implementation of
ClassLoader.findClass(String) . |
protected Map |
generateBytecodes(String name)
Find, scan, parse the right compilation unit.
|
void |
setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler) |
void |
setDebuggingInfo(boolean debugSource,
boolean debugLines,
boolean debugVars) |
void |
setSourceFileCharacterEncoding(String optionalCharacterEncoding) |
void |
setSourcePath(File[] sourcePath) |
void |
setWarningHandler(WarningHandler optionalWarningHandler) |
main, setProtectionDomainFactory
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected boolean debugSource
protected boolean debugLines
protected boolean debugVars
public JavaSourceClassLoader()
public JavaSourceClassLoader(ClassLoader parentClassLoader)
public JavaSourceClassLoader(ClassLoader parentClassLoader, File[] optionalSourcePath, String optionalCharacterEncoding)
JavaSourceClassLoader
that finds Java™ source code in a file
that resides in either of the directories specified by the given source path.parentClassLoader
- See ClassLoader
optionalSourcePath
- 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)public JavaSourceClassLoader(ClassLoader parentClassLoader, ResourceFinder sourceFinder, String optionalCharacterEncoding)
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)
).
parentClassLoader
- See ClassLoader
sourceFinder
- Used to locate additional source filesoptionalCharacterEncoding
- The encoding of the Java™ source files (null
for platform
default encoding)public void setSourcePath(File[] sourcePath)
setSourcePath
in class AbstractJavaSourceClassLoader
sourcePath
- The sequence of directories to search for Java™ source filespublic void setSourceFileCharacterEncoding(String optionalCharacterEncoding)
setSourceFileCharacterEncoding
in class AbstractJavaSourceClassLoader
optionalCharacterEncoding
- if null
, use platform default encodingpublic void setDebuggingInfo(boolean debugSource, boolean debugLines, boolean debugVars)
setDebuggingInfo
in class AbstractJavaSourceClassLoader
debugSource
- Whether line number debugging information should be generateddebugLines
- Whether variables debugging information should be generateddebugVars
- Whether source file debugging information should be generatedpublic void setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
public void setWarningHandler(WarningHandler optionalWarningHandler)
protected Class findClass(String name) throws ClassNotFoundException
ClassLoader.findClass(String)
.findClass
in class ClassLoader
ClassNotFoundException
protected Map generateBytecodes(String name) throws ClassNotFoundException
null
if no source code could be foundClassNotFoundException
- on compilation problemsprotected Class defineBytecodes(String name, Map bytecodes)
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[] bytecodeClassFormatError
Copyright © 2001–2016. All rights reserved.