|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
org.acm.seguin.project.ProjectClassLoader
public class ProjectClassLoader
Used to load classes within ant with a different claspath from that used to start ant. Note that it is possible to force a class into this loader even when that class is on the system classpath by using the forceLoadClass method. Any subsequent classes loaded by that class will then use this loader rather than the system class loader.
Constructor Summary | |
---|---|
ProjectClassLoader(java.lang.ClassLoader parent,
boolean parentFirst)
Creates an empty class loader. |
|
ProjectClassLoader(java.lang.ClassLoader parent,
Project project,
boolean parentFirst)
Creates a classloader for the given project. |
|
ProjectClassLoader(Project project)
Creates a classloader for the given project. |
|
ProjectClassLoader(Project project,
boolean parentFirst)
Creates a classloader for the given project. |
Method Summary | |
---|---|
void |
addLoaderPackageRoot(java.lang.String packageRoot)
Adds a package root to the list of packages which must be loaded using this loader. |
void |
addPathElement(java.lang.String pathElement)
Adds an element to the classpath to be searched. |
void |
addSystemPackageRoot(java.lang.String packageRoot)
Adds a package root to the list of packages which must be loaded on the parent loader. |
void |
cleanup()
Cleans up any resources held by this classloader. |
java.lang.Class |
findClass(java.lang.String name)
Searches for and load a class on the classpath of this class loader. |
protected java.util.Enumeration |
findResources(java.lang.String name)
Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath. |
java.lang.Class |
forceLoadClass(java.lang.String classname)
Loads a class through this class loader even if that class is available on the parent classpath. |
java.lang.Class |
forceLoadSystemClass(java.lang.String classname)
Loads a class through this class loader but defer to the parent class loader. |
java.lang.String |
getClasspath()
Returns the classpath this classloader will consult. |
java.net.URL |
getResource(java.lang.String name)
Finds the resource with the given name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Returns a stream to read the requested resource name. |
static void |
initializeClass(java.lang.Class theClass)
Forces initialization of a class in a JDK 1.1 compatible, albeit hacky way. |
protected java.lang.Class |
loadClass(java.lang.String classname,
boolean resolve)
Loads a class with this class loader. |
protected void |
log(java.lang.String message)
Logs a message through the project object if one has been provided. |
void |
setIsolated(boolean isolated)
Sets whether this classloader should run in isolated mode. |
Methods inherited from class java.lang.ClassLoader |
---|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ProjectClassLoader(Project project)
project
- The project to which this classloader is to belong.
Must not be null
.public ProjectClassLoader(java.lang.ClassLoader parent, Project project, boolean parentFirst)
parent
- The parent classloader to which unsatisfied loading
attempts are delegated. May be null
,
in which case the classloader which loaded this
class is used as the parent.project
- The project to which this classloader is to belong.
Must not be null
.parentFirst
- If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.public ProjectClassLoader(Project project, boolean parentFirst)
project
- The project to which this classloader is to belong.
Must not be null
.parentFirst
- If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.public ProjectClassLoader(java.lang.ClassLoader parent, boolean parentFirst)
parent
- The parent classloader to which unsatisfied loading
attempts are delegated. May be null
,
in which case the classloader which loaded this
class is used as the parent.parentFirst
- If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.Method Detail |
---|
protected void log(java.lang.String message)
message
- The message to log.
Should not be null
.priority
- The logging priority of the message.public void addPathElement(java.lang.String pathElement) throws ProjectException
pathElement
- The path element to add. Must not be
null
.
ProjectException
- if the given path element cannot be resolved
against the project.public java.lang.String getClasspath()
public void setIsolated(boolean isolated)
isolated
- Whether or not this classloader should run in
isolated mode.public static void initializeClass(java.lang.Class theClass)
theClass
- The class to initialize.
Must not be null
.public void addSystemPackageRoot(java.lang.String packageRoot)
packageRoot
- The root of all packages to be included.
Should not be null
.public void addLoaderPackageRoot(java.lang.String packageRoot)
packageRoot
- The root of all packages to be included.
Should not be null
.public java.lang.Class forceLoadClass(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- The name of the class to be loaded.
Must not be null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public java.lang.Class forceLoadSystemClass(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- The name of the class to be loaded.
Must not be null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public java.io.InputStream getResourceAsStream(java.lang.String name)
getResourceAsStream
in class java.lang.ClassLoader
name
- The name of the resource for which a stream is required.
Must not be null
.
null
if the
resource cannot be found on the loader's classpath.public java.net.URL getResource(java.lang.String name)
getResource
in class java.lang.ClassLoader
name
- The name of the resource for which a stream is required.
Must not be null
.
null
if the
resource could not be found or the caller doesn't have
adequate privileges to get the resource.protected java.util.Enumeration findResources(java.lang.String name) throws java.io.IOException
findResources
in class java.lang.ClassLoader
name
- The resource name to search for.
Must not be null
.
java.io.IOException
- if I/O errors occurs (can't happen)protected java.lang.Class loadClass(java.lang.String classname, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
classname
- The name of the class to be loaded.
Must not be null
.resolve
- true
if all classes upon which this class
depends are to be loaded.
java.lang.ClassNotFoundException
- if the requested class does not exist
on the system classpath (when not in isolated mode) or this loader's
classpath.public java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.lang.ClassLoader
name
- The name of the class to be loaded. Must not be
null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public void cleanup()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |