Return to www.inductionframework.org

com.acciente.commons.loader
Class JavaSourceClassDefLoader

java.lang.Object
  extended by com.acciente.commons.loader.JavaSourceClassDefLoader
All Implemented Interfaces:
ClassDefLoader

public class JavaSourceClassDefLoader
extends java.lang.Object
implements ClassDefLoader

An class definition loader that compiles and loads Java source files.


Constructor Summary
JavaSourceClassDefLoader()
           
JavaSourceClassDefLoader(com.acciente.commons.javac.JavaCompilerManager oJavaCompilerManager, java.io.File oSourceDirectory)
           
 
Method Summary
 ClassDef getClassDef(java.lang.String sClassName)
          Load the byte code and other information about the specified class
 com.acciente.commons.javac.JavaCompilerManager getJavaCompilerManager()
           
 java.lang.String getPackageNamePrefix()
          Returns the package name prefix set by a call to setPackageNamePrefix() or a null string if no package name prefix was ever set.
 ResourceDef getResourceDef(java.lang.String sResourceName)
          Load the data and other information about the specified resource
 java.io.File getSourceDirectory()
          Returns the source directory from which this classloader loads java source files
 void setJavaCompilerManager(com.acciente.commons.javac.JavaCompilerManager oJavaCompilerManager)
           
 void setPackageNamePrefix(java.lang.String sPackageNamePrefix)
          A package name prefix that represents the prefix that should be removed from the class name passed to loadClass() before attempting to convert the class's package name to a sub-directory off the specified source directory.
 void setSourceDirectory(java.io.File sSourceDirectory)
          Sets the directory from which this classloader will attempt to java source files
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaSourceClassDefLoader

public JavaSourceClassDefLoader()

JavaSourceClassDefLoader

public JavaSourceClassDefLoader(com.acciente.commons.javac.JavaCompilerManager oJavaCompilerManager,
                                java.io.File oSourceDirectory)
Method Detail

getClassDef

public ClassDef getClassDef(java.lang.String sClassName)
                     throws java.lang.ClassNotFoundException
Description copied from interface: ClassDefLoader
Load the byte code and other information about the specified class

Specified by:
getClassDef in interface ClassDefLoader
Parameters:
sClassName - the name of the class for which a definition is requested
Returns:
a class definition if this class definition loader is able to locate and successfully load the byte code for the class. If the class could not be located a null is returned, if the class was located but the load failed an exception is thrown.
Throws:
java.lang.ClassNotFoundException - if this loader was able to locate the class definition was unable to sucessfully load it

getResourceDef

public ResourceDef getResourceDef(java.lang.String sResourceName)
Description copied from interface: ClassDefLoader
Load the data and other information about the specified resource

Specified by:
getResourceDef in interface ClassDefLoader
Parameters:
sResourceName - the name of the class for which a definition is requested
Returns:
a resource definition if this class definition loader is able to locate and successfully load the data for the resource. If the resource could not be located a null is returned, if the resource was located but the load failed again a null is returned (since the getResource() and getResourceAsStreamMethods() do not have checked exceptions in their signature).

getSourceDirectory

public java.io.File getSourceDirectory()
Returns the source directory from which this classloader loads java source files

Returns:
a File object representing a directory path

setSourceDirectory

public void setSourceDirectory(java.io.File sSourceDirectory)
Sets the directory from which this classloader will attempt to java source files

Parameters:
sSourceDirectory - a File object representing a directory path

getPackageNamePrefix

public java.lang.String getPackageNamePrefix()
Returns the package name prefix set by a call to setPackageNamePrefix() or a null string if no package name prefix was ever set.

Returns:
null or a package name without a terminating period (e.g: foo.bar and NOT foo.bar.)

setPackageNamePrefix

public void setPackageNamePrefix(java.lang.String sPackageNamePrefix)
A package name prefix that represents the prefix that should be removed from the class name passed to loadClass() before attempting to convert the class's package name to a sub-directory off the specified source directory. For consistency this setting also causes the class loader to enfore that all the package name of classes loaded by this classloader start with the specified package name prefix. Following is an illustration of how is parameter may be used. Assume we have source files in a directory /project/foobar/src, lets also assume that we want to reliably restrict this class loader to only load source files in the folder /project/foobar/src/foobar/controller. So for so security we set the source directory of this classoader to /project/foobar/src/foobar/controller. Now if we ask this classloader to load the class foobar.controller.HelloWorld it would (unsuccessfully) try to look for a source file named: "/project/foobar/src/foobar/controller/foobar/controller/HelloWorld.java" computed using: SourceDir="/project/foobar/src/foobar/controller" + InferredSourceFilePath="/foobar/controller/HelloWorld.java" To get the correct behaviour in the above example the PackageNamePrefix of this class loader must be set to "foobar.controller". The prefix "foobar.controller" is then removed from the package name of class before using it to compute the source file path for the class foobar.controller.HelloWorld.

Parameters:
sPackageNamePrefix - null or a package name without a terminating period (e.g: foo.bar and NOT foo.bar.)

getJavaCompilerManager

public com.acciente.commons.javac.JavaCompilerManager getJavaCompilerManager()

setJavaCompilerManager

public void setJavaCompilerManager(com.acciente.commons.javac.JavaCompilerManager oJavaCompilerManager)

Return to www.inductionframework.org

Copyright (c) 2008 Acciente, LLC. All rights reserved.