Top Description Inners Fields Constructors Methods
org.codehaus.commons.compiler

public abstract Class AbstractJavaSourceClassLoader

extends ClassLoader
Class Inheritance
Imports
java.io.File, .InputStream, java.lang.reflect.Method, java.nio.charset.Charset, java.security.ProtectionDomain, java.util.ArrayList, .List, .StringTokenizer, org.codehaus.commons.compiler.util.resource.ResourceFinder, org.codehaus.commons.nullanalysis.NotNullByDefault, .Nullable

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 AbstractJavaSourceClassLoader and create a new one.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
protected AbstractJavaSourceClassLoader.ProtectionDomainFactory

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public InputStream
getResourceAsStream(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.
public static void
main(String[] args)

Reads Java 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 arguments.

public abstract void
setDebuggingInfo(boolean
Whether line number debugging information should be generated
lines
,
boolean
Whether variables debugging information should be generated
vars
,
boolean
Whether source file debugging information should be generated
source
)

public final void
public abstract void
setSourceCharset(Charset
The character set to using when reading characters from a source file
charset
)

public void
setSourceFileCharacterEncoding(String
if null, use platform default encoding
charsetName
)

public abstract void
setSourceFinder(ResourceFinder
Is used when searching for Java source files
sourceFinder
)

public abstract void
setSourcePath(File[]
The sequence of directories to search for Java source files
sourcePath
)

private static File[]
splitPath(String string)

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

protectionDomainFactoryback to summary
protected AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory
Annotations
@Nullable
See Also
ClassLoader#defineClass(String, byte[], int, int, ProtectionDomain)

Constructor Detail

AbstractJavaSourceClassLoaderback to summary
public AbstractJavaSourceClassLoader()
AbstractJavaSourceClassLoaderback to summary
public AbstractJavaSourceClassLoader(ClassLoader parentClassLoader)

Method Detail

getResourceAsStreamback to summary
public InputStream getResourceAsStream(String name)

Overrides java.lang.ClassLoader.getResourceAsStream.

Doc from java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

The search order is described in the documentation for getResource(String).

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally.

Parameters
name:String

The resource name

Returns:InputStream

An input stream for reading the resource; null if the resource could not be found, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override
@NotNullByDefault:false
mainback to summary
public static void main(String[] args) throws Exception

Reads Java 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 arguments.

Usage is as follows:

  java AbstractJavaSourceClassLoader [ option ] ... class-name [ argument ] ...

  option:
    -sourcepath colon-separated-list-of-source-directories
    -encoding character-encoding
    -g                           Generate all debugging info
    -g:none                      Generate no debugging info
    -g:{source,lines,vars}       Generate only some debugging info
setDebuggingInfoback to summary
public abstract void setDebuggingInfo(boolean lines, boolean vars, boolean source)
Parameters
lines:boolean

Whether line number debugging information should be generated

vars:boolean

Whether variables debugging information should be generated

source:boolean

Whether source file debugging information should be generated

setProtectionDomainFactoryback to summary
public final void setProtectionDomainFactory(AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)
See Also
ClassLoader#defineClass(String, byte[], int, int, ProtectionDomain)
setSourceCharsetback to summary
public abstract void setSourceCharset(Charset charset)
Parameters
charset:Charset

The character set to using when reading characters from a source file

setSourceFileCharacterEncodingback to summary
public void setSourceFileCharacterEncoding(String charsetName)
Parameters
charsetName:String

if null, use platform default encoding

setSourceFinderback to summary
public abstract void setSourceFinder(ResourceFinder sourceFinder)
Parameters
sourceFinder:ResourceFinder

Is used when searching for Java source files

setSourcePathback to summary
public abstract void setSourcePath(File[] sourcePath)
Parameters
sourcePath:File[]

The sequence of directories to search for Java source files

splitPathback to summary
private static File[] splitPath(String string)
org.codehaus.commons.compiler back to summary

public Interface AbstractJavaSourceClassLoader.ProtectionDomainFactory


See Also
AbstractJavaSourceClassLoader#setProtectionDomainFactory

Method Summary

Modifier and TypeMethod and Description
public ProtectionDomain
getProtectionDomain(String
E.g. "pkg1/pkg2/Outer.java"
sourceResourceName
)

Method Detail

getProtectionDomainback to summary
public ProtectionDomain getProtectionDomain(String sourceResourceName)
Parameters
sourceResourceName:String

E.g. "pkg1/pkg2/Outer.java"