| java.net.URLClassLoader org.apache.commons.logging.PathableClassLoader
PathableClassLoader | public class PathableClassLoader extends URLClassLoader (Code) | | A ClassLoader which sees only specified classes, and which can be
set to do parent-first or child-first path lookup.
Note that this classloader is not "industrial strength"; users
looking for such a class may wish to look at the Tomcat sourcecode
instead. In particular, this class may not be threadsafe.
Note that the ClassLoader.getResources method isn't overloaded here.
It would be nice to ensure that when child-first lookup is set the
resources from the child are returned earlier in the list than the
resources from the parent. However overriding this method isn't possible
as the java 1.4 version of ClassLoader declares this method final
(though the java 1.5 version has removed the final qualifier). As the
ClassLoader javadoc doesn't specify the order in which resources
are returned, it's valid to return the resources in any order (just
untidy) so the inherited implementation is technically ok.
|
Method Summary | |
public void | addLogicalLib(String[] logicalLibs) Specify a collection of logical libraries. | public void | addLogicalLib(String logicalLib) Specify a logical library to be included in the classpath used to
locate classes. | public void | addURL(URL url) Allow caller to explicitly add paths. | public URL | getResource(String name) Same as parent class method except that when parentFirst is false
the resource is looked for in the local classpath before the parent
loader is consulted. | public InputStream | getResourceAsStream(String name) Same as parent class method except that when parentFirst is false
the resource is looked for in the local classpath before the parent
loader is consulted. | public Enumeration | getResourcesInOrder(String name) Emulate a proper implementation of getResources which respects the
setting for parentFirst. | protected Class | loadClass(String name, boolean resolve) Override ClassLoader method. | public void | setParentFirst(boolean state) Specify whether this classloader should ask the parent classloader
to resolve a class first, before trying to resolve it via its own
classpath. | public void | useExplicitLoader(String prefix, ClassLoader loader) Specify a classloader to use for specific java packages. | public void | useSystemLoader(String prefix) For classes with the specified prefix, get them from the system
classpath which is active at the point this method is called. |
addLogicalLib | public void addLogicalLib(String[] logicalLibs)(Code) | | Specify a collection of logical libraries. See addLogicalLib.
|
addLogicalLib | public void addLogicalLib(String logicalLib)(Code) | | Specify a logical library to be included in the classpath used to
locate classes.
The specified lib name is used as a key into the system properties;
there is expected to be a system property defined with that name
whose value is a url that indicates where that logical library can
be found. Typically this is the name of a jar file, or a directory
containing class files.
Using logical library names allows the calling code to specify its
desired classpath without knowing the exact location of the necessary
classes.
|
addURL | public void addURL(URL url)(Code) | | Allow caller to explicitly add paths. Generally this not a good idea;
use addLogicalLib instead, then define the location for that logical
library in the build.xml file.
|
getResource | public URL getResource(String name)(Code) | | Same as parent class method except that when parentFirst is false
the resource is looked for in the local classpath before the parent
loader is consulted.
|
getResourceAsStream | public InputStream getResourceAsStream(String name)(Code) | | Same as parent class method except that when parentFirst is false
the resource is looked for in the local classpath before the parent
loader is consulted.
|
getResourcesInOrder | public Enumeration getResourcesInOrder(String name) throws IOException(Code) | | Emulate a proper implementation of getResources which respects the
setting for parentFirst.
Note that it's not possible to override the inherited getResources, as
it's declared final in java1.4 (thought that's been removed for 1.5).
The inherited implementation always behaves as if parentFirst=true.
|
loadClass | protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException(Code) | | Override ClassLoader method.
For each explicitly mapped package prefix, if the name matches the
prefix associated with that entry then attempt to load the class via
that entries' classloader.
|
setParentFirst | public void setParentFirst(boolean state)(Code) | | Specify whether this classloader should ask the parent classloader
to resolve a class first, before trying to resolve it via its own
classpath.
Checking with the parent first is the normal approach for java, but
components within containers such as servlet engines can use
child-first lookup instead, to allow the components to override libs
which are visible in shared classloaders provided by the container.
Note that the method getResources always behaves as if parentFirst=true,
because of limitations in java 1.4; see the javadoc for method
getResourcesInOrder for details.
This value defaults to true.
|
useExplicitLoader | public void useExplicitLoader(String prefix, ClassLoader loader)(Code) | | Specify a classloader to use for specific java packages.
|
useSystemLoader | public void useSystemLoader(String prefix)(Code) | | For classes with the specified prefix, get them from the system
classpath which is active at the point this method is called.
This method is just a shortcut for
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
|
|