|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.codehaus.groovy.tools.RootLoader
public class RootLoader
This ClassLoader should be used as root of class loaders. Any RootLoader does have it's own classpath. When searching for a class or resource this classpath will be used. Parent Classloaders are ignored first. If a class or resource can't be found in the classpath of the RootLoader, then parent is checked.
Note: this is very against the normal behavior of classloaders. Normal is to first check parent and then look in the resources you gave this classloader. It's possible to add urls to the classpath at runtime through
Why using RootLoader?
If you have to load classes with multiple classloaders and a
classloader does know a class which depends on a class only
a child of this loader does know, then you won't be able to
load the class. To load the class the child is not allowed
to redirect it's search for the class to the parent first.
That way the child can load the class. If the child does not
have all classes to do this, this fails of course.
For example:
parentLoader (has classpath: a.jar;c.jar)
|
|
childLoader (has classpath: a.jar;b.jar;c.jar)
class C (from c.jar) extends B (from b.jar)
childLoader.find("C")
--> parentLoader does know C.class, try to load it
--> to load C.class it has to load B.class
--> parentLoader is unable to find B.class in a.jar or c.jar
--> NoClassDefFoundException!
if childLoader had tried to load the class by itself, there
would be no problem. Changing childLoader to be a RootLoader
instance will solve that problem.
Constructor Summary | |
---|---|
private |
RootLoader(java.lang.ClassLoader parent)
constructs a new RootLoader without classpath |
|
RootLoader(LoaderConfiguration lc)
constructs a new RootLoader with a @see LoaderConfiguration object which holds the classpath |
|
RootLoader(java.net.URL[] urls,
java.lang.ClassLoader parent)
constructs a new RootLoader with a parent loader and an array of URLs as classpath |
Method Summary | |
---|---|
void |
addURL(java.net.URL url)
adds an url to the classpath of this classloader |
private static java.lang.ClassLoader |
chooseParent()
|
protected java.lang.Class |
findClass(java.lang.String name)
|
java.net.URL |
getResource(java.lang.String name)
returns the URL of a resource, or null if it is not found |
protected java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
loads a class using the name of the class |
private java.lang.Class |
oldFindClass(java.lang.String name)
|
Methods inherited from class java.net.URLClassLoader |
---|
definePackage, findResource, findResources, getPermissions, getURLs, newInstance, newInstance |
Methods inherited from class java.security.SecureClassLoader |
---|
defineClass, defineClass |
Methods inherited from class java.lang.ClassLoader |
---|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResourceAsStream, 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 |
---|
private RootLoader(java.lang.ClassLoader parent)
parent
- the parent Loaderpublic RootLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
public RootLoader(LoaderConfiguration lc)
Method Detail |
---|
private static java.lang.ClassLoader chooseParent()
protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
public java.net.URL getResource(java.lang.String name)
getResource
in class java.lang.ClassLoader
public void addURL(java.net.URL url)
addURL
in class java.net.URLClassLoader
private java.lang.Class oldFindClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.net.URLClassLoader
java.lang.ClassNotFoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |