janino.net

org.codehaus.janino
Class JavaSourceClassLoader

  extended by 
      extended by org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
          extended by org.codehaus.janino.JavaSourceClassLoader
Direct Known Subclasses:
CachingJavaSourceClassLoader

public class JavaSourceClassLoader
extends AbstractJavaSourceClassLoader

A that, unlike usual 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 , 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
 
Nested classes/interfaces inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
AbstractJavaSourceClassLoader.ProtectionDomainFactory
 
Field Summary
 
Fields inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
optionalProtectionDomainFactory
 
Constructor Summary
JavaSourceClassLoader()
           
JavaSourceClassLoader( parentClassLoader)
           
JavaSourceClassLoader( parentClassLoader, [] optionalSourcePath,  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( parentClassLoader, JavaSourceIClassLoader iClassLoader)
          Constructs a JavaSourceClassLoader that finds classes through an JavaSourceIClassLoader.
JavaSourceClassLoader( parentClassLoader, ResourceFinder sourceFinder,  optionalCharacterEncoding)
          Constructs a JavaSourceClassLoader that finds Java™ source code through a given ResourceFinder.
 
Method Summary
protected   findClass( name)
          Implementation of .
protected  <,byte[]> generateBytecodes( name)
          Find, scan, parse the right compilation unit.
 void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
           
 void setDebuggingInfo(boolean debugSource, boolean debugLines, boolean debugVars)
           
 void setSourceFileCharacterEncoding( optionalCharacterEncoding)
           
 void setSourcePath([] sourcePath)
           
 void setWarningHandler(WarningHandler optionalWarningHandler)
           
 
Methods inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
main, setProtectionDomainFactory
 
Methods inherited from class java.lang.
, , , , , , , , , , , , , , , , , , , , , , , , , , ,
 
Methods inherited from class java.lang.
, , , , , , , , , ,
 

Constructor Detail

JavaSourceClassLoader

public JavaSourceClassLoader()

JavaSourceClassLoader

public JavaSourceClassLoader( parentClassLoader)

JavaSourceClassLoader

public JavaSourceClassLoader( parentClassLoader,
                             [] optionalSourcePath,
                              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
optionalSourcePath - A collection of directories that are searched for Java™ source files in the given order
optionalCharacterEncoding - The encoding of the Java™ source files (null for platform default encoding)

JavaSourceClassLoader

public JavaSourceClassLoader( parentClassLoader,
                             ResourceFinder sourceFinder,
                              optionalCharacterEncoding)
Constructs 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
sourceFinder - Used to locate additional source files
optionalCharacterEncoding - The encoding of the Java™ source files (null for platform default encoding)

JavaSourceClassLoader

public JavaSourceClassLoader( parentClassLoader,
                             JavaSourceIClassLoader iClassLoader)
Constructs a JavaSourceClassLoader that finds classes through an JavaSourceIClassLoader.

Method Detail

setSourcePath

public void setSourcePath([] sourcePath)
Specified by:
setSourcePath in class AbstractJavaSourceClassLoader
Parameters:
sourcePath - The sequence of directories to search for Java™ source files

setSourceFileCharacterEncoding

public void setSourceFileCharacterEncoding( 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 generated
debugLines - Whether variables debugging information should be generated
debugVars - Whether source file debugging information should be generated

setCompileErrorHandler

public void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
See Also:
UnitCompiler.setCompileErrorHandler(org.codehaus.commons.compiler.ErrorHandler)

setWarningHandler

public void setWarningHandler(WarningHandler optionalWarningHandler)
See Also:
Parser.setWarningHandler(WarningHandler), UnitCompiler.setCompileErrorHandler(org.codehaus.commons.compiler.ErrorHandler)

findClass

protected  findClass( name)
                   throws 
Implementation of .

Overrides:
in class
Throws:

generateBytecodes

protected <,byte[]> generateBytecodes( name)
                                        throws 
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:
- on compilation problems

janino.net