org.apache.geronimo.kernel.config
Class MultiParentClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.apache.geronimo.kernel.config.MultiParentClassLoader
Direct Known Subclasses:
JarFileClassLoader

public class MultiParentClassLoader
extends URLClassLoader

A MultiParentClassLoader is a simple extension of the URLClassLoader that simply changes the single parent class loader model to support a list of parent class loaders. Each operation that accesses a parent, has been replaced with a operation that checks each parent in order. This getParent method of this class will always return null, which may be interpreted by the calling code to mean that this class loader is a direct child of the system class loader.


Constructor Summary
MultiParentClassLoader(Artifact id, URL[] urls)
          Creates a named class loader with no parents.
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent)
          Creates a named class loader as a child of the specified parent.
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents)
          Creates a named class loader as a child of the specified parents.
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses)
           
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses)
           
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, URLStreamHandlerFactory factory)
          Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory for accessing the urls..
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses)
           
MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)
          Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory for accessing the urls..
MultiParentClassLoader(MultiParentClassLoader source)
           
 
Method Summary
 void addURL(URL url)
           
 void destroy()
           
protected  void finalize()
           
 Enumeration<URL> findResources(String name)
           
 Artifact getId()
          Gets the id of this class loader.
 ClassLoader[] getParents()
          Gets the parents of this class loader.
 URL getResource(String name)
           
protected  Enumeration<URL> internalfindResources(String name)
           
 boolean isDestroyed()
           
protected  Class<?> loadClass(String name, boolean resolve)
          TODO This method should be removed and replaced with the best classLoading option.
protected  Class<?> loadClassInternal(String name, boolean resolve, LinkedList<ClassLoader> visitedClassLoaders)
          This method is an internal hook that allows us to be performant on Class lookups when multiparent classloaders are involved.
protected  Class<?> loadOptimizedClass(String name, boolean resolve)
          Optimized classloading.
protected  Class<?> loadSafeClass(String name, boolean resolve)
          This method executes the old class loading behaviour before optimization.
protected  void recursiveFind(Set<ClassLoader> knownClassloaders, List<Enumeration<URL>> enumerations, String name)
           
 String toString()
           
 
Methods inherited from class java.net.URLClassLoader
definePackage, findClass, findResource, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls)
Creates a named class loader with no parents.

Parameters:
id - the id of this class loader
urls - the urls from which this class loader will classes and resources

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader parent)
Creates a named class loader as a child of the specified parent.

Parameters:
id - the id of this class loader
urls - the urls from which this class loader will classes and resources
parent - the parent of this class loader

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader parent,
                              boolean inverseClassLoading,
                              String[] hiddenClasses,
                              String[] nonOverridableClasses)

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader parent,
                              URLStreamHandlerFactory factory)
Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory for accessing the urls..

Parameters:
id - the id of this class loader
urls - the urls from which this class loader will classes and resources
parent - the parent of this class loader
factory - the URLStreamHandlerFactory used to access the urls

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader[] parents)
Creates a named class loader as a child of the specified parents.

Parameters:
id - the id of this class loader
urls - the urls from which this class loader will classes and resources
parents - the parents of this class loader

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader[] parents,
                              boolean inverseClassLoading,
                              Collection hiddenClasses,
                              Collection nonOverridableClasses)

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader[] parents,
                              boolean inverseClassLoading,
                              String[] hiddenClasses,
                              String[] nonOverridableClasses)

MultiParentClassLoader

public MultiParentClassLoader(MultiParentClassLoader source)

MultiParentClassLoader

public MultiParentClassLoader(Artifact id,
                              URL[] urls,
                              ClassLoader[] parents,
                              URLStreamHandlerFactory factory)
Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory for accessing the urls..

Parameters:
id - the id of this class loader
urls - the urls from which this class loader will classes and resources
parents - the parents of this class loader
factory - the URLStreamHandlerFactory used to access the urls
Method Detail

getId

public Artifact getId()
Gets the id of this class loader.

Returns:
the id of this class loader

getParents

public ClassLoader[] getParents()
Gets the parents of this class loader.

Returns:
the parents of this class loader

addURL

public void addURL(URL url)
Overrides:
addURL in class URLClassLoader

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
TODO This method should be removed and replaced with the best classLoading option. Its intent is to provide a way for folks to switch back to the old classLoader if this fix breaks something.

Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

loadSafeClass

protected Class<?> loadSafeClass(String name,
                                 boolean resolve)
                          throws ClassNotFoundException
This method executes the old class loading behaviour before optimization.

Parameters:
name -
resolve -
Returns:
Throws:
ClassNotFoundException

loadOptimizedClass

protected Class<?> loadOptimizedClass(String name,
                                      boolean resolve)
                               throws ClassNotFoundException
Optimized classloading. This method is the normal way to resolve class loads. This method recursively calls its parents to resolve classloading requests. Here is the sequence of operations: 1. Call findClass to see if we already have this class loaded. 2. If not, call the SystemClassLoader which needs to be called anyway. 3. Check if inverse loading, if so look in our class loader. 4. Search our parents, recursively. Keeping track of which parents have already been called. Since MultiParentClassLoaders can appear more than once we do not search an already searched classloader. 5. Search our classloader.

Throws:
ClassNotFoundException

loadClassInternal

protected Class<?> loadClassInternal(String name,
                                     boolean resolve,
                                     LinkedList<ClassLoader> visitedClassLoaders)
                              throws ClassNotFoundException
This method is an internal hook that allows us to be performant on Class lookups when multiparent classloaders are involved. We can bypass certain lookups that have already occurred in the initiating classloader. Also, we track the classLoaders that are visited by adding them to an already vistied list. In this way, we can bypass redundant checks for the same class.

Parameters:
name -
visitedClassLoaders -
Returns:
Throws:
ClassNotFoundException

getResource

public URL getResource(String name)
Overrides:
getResource in class ClassLoader

findResources

public Enumeration<URL> findResources(String name)
                               throws IOException
Overrides:
findResources in class URLClassLoader
Throws:
IOException

recursiveFind

protected void recursiveFind(Set<ClassLoader> knownClassloaders,
                             List<Enumeration<URL>> enumerations,
                             String name)
                      throws IOException
Throws:
IOException

internalfindResources

protected Enumeration<URL> internalfindResources(String name)
                                          throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

isDestroyed

public boolean isDestroyed()

destroy

public void destroy()

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.