org.freecompany.brimstone.module
Class DelegatingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.freecompany.brimstone.module.DelegatingClassLoader
Direct Known Subclasses:
ModuleClassLoader

public class DelegatingClassLoader
extends java.net.URLClassLoader

The delegating class loader maintains a list of delegates to which looading commands will be propagated. This list is always traversed in order of insertion.


Field Summary
protected  org.freecompany.util.multicaster.Notification notifier
           
 
Constructor Summary
DelegatingClassLoader()
          Creates an delegating class loader with no parent and no source URLs.
DelegatingClassLoader(java.lang.ClassLoader parent)
          Creates an delegating class loader with no source URLs which uses the provided parent loader.
DelegatingClassLoader(java.net.URL[] urls)
          Creates an delegating class loader with no parent and with the specified source URLs.
DelegatingClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
          Creates an delegating class loader with the specified source URLs and which uses the provided parent loader.
 
Method Summary
 void addDelegate(java.lang.ClassLoader loader)
          Adds a class loader to the list of delegates.
 void addUrl(java.net.URL url)
          Exposes the ability to add locations to this class loader at runtime.
protected  java.lang.String dump()
          Dumps a string representation of the current threads local stack.
 java.net.URL getResource(java.lang.String name)
          Gets a resource using the contained set of delegates.
 java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
          Gets a set of resources using the contained set of delegates.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Loads a class using the contained set of delegates.
protected  org.freecompany.util.core.Pair<java.lang.ClassLoader,java.lang.String> pop()
          Pops the Pair on the top of the stack.
protected  void push(org.freecompany.util.core.Pair<java.lang.ClassLoader,java.lang.String> pair)
          Pushes a new Pair onto the thread local stack.
protected  boolean searching(java.lang.String name)
          Checks to see if the provided name is currently in the process of being loaded.
protected static java.lang.String shortName(java.lang.Class clazz)
          Strips extra characters from a fully qualified class name, leaving only the name within the package.
protected  boolean skip(java.lang.ClassLoader child, java.lang.String name)
          Checks the thread local state to determine whether the provided child needs to be skipped.
 java.lang.String toString()
           
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, 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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

notifier

protected org.freecompany.util.multicaster.Notification notifier
Constructor Detail

DelegatingClassLoader

public DelegatingClassLoader()
Creates an delegating class loader with no parent and no source URLs.


DelegatingClassLoader

public DelegatingClassLoader(java.lang.ClassLoader parent)
Creates an delegating class loader with no source URLs which uses the provided parent loader.


DelegatingClassLoader

public DelegatingClassLoader(java.net.URL[] urls)
Creates an delegating class loader with no parent and with the specified source URLs.


DelegatingClassLoader

public DelegatingClassLoader(java.net.URL[] urls,
                             java.lang.ClassLoader parent)
Creates an delegating class loader with the specified source URLs and which uses the provided parent loader.

Method Detail

addUrl

public void addUrl(java.net.URL url)
Exposes the ability to add locations to this class loader at runtime. This implementation does not promote the existing URLClassLoader.addURL(java.net.URL) method so as to avoid interfering with normal operation.

Parameters:
url - the url to add to the list of locations searched for class definitions.

addDelegate

public void addDelegate(java.lang.ClassLoader loader)
Adds a class loader to the list of delegates. Please note that the provided ClassLoader must not have this delegating class loader set as it's parent unless it is an instance of InvertedClassLoader or can otherwise make use of the methods in this loader that take a source as a parameter.

Parameters:
loader - the ClassLoader to add to the delegate list.

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Loads a class using the contained set of delegates. This method conforms to the standard delegation model, checking the parent first if one exists. If not, each child class loader is tried, in order, until one returns positively. State is tracked via a thread local variable.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - the name of the class to load.
Returns:
the Class definition found by this loader.
Throws:
java.lang.ClassNotFoundException - if the class can not be found.

getResources

public java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
                                                 throws java.io.IOException
Gets a set of resources using the contained set of delegates. The parent, if one exists, and each child are utilized to build a complete set of resources for the given name. State is tracked via a thread local variable.

Overrides:
getResources in class java.lang.ClassLoader
Parameters:
name - the name of the resource to list.
Returns:
the URL> of resources found by this class loader.
Throws:
java.io.IOException

getResource

public java.net.URL getResource(java.lang.String name)
Gets a resource using the contained set of delegates. This method conforms to the standard delegation model, checking the parent first if one exists. If not, each child class loader is tried, in order, until one returns positively. State is tracked via a thread local variable.

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - the name of the resource to get.
Returns:
the URL of the resource found by this class loader or null if no resource was found.

shortName

protected static final java.lang.String shortName(java.lang.Class clazz)
Strips extra characters from a fully qualified class name, leaving only the name within the package.

Parameters:
clazz - the Class for which to construct a short name.
Returns:
the class name within its package.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

push

protected void push(org.freecompany.util.core.Pair<java.lang.ClassLoader,java.lang.String> pair)
Pushes a new Pair onto the thread local stack.

Parameters:
pair - the pair of elements describing the latest loading event.

pop

protected org.freecompany.util.core.Pair<java.lang.ClassLoader,java.lang.String> pop()
Pops the Pair on the top of the stack.

Returns:
the top of the stack if it is not empty.
Throws:
EmptyStackException - if there are no entries on the stack.

searching

protected boolean searching(java.lang.String name)
Checks to see if the provided name is currently in the process of being loaded. This indicates that this thread is still within a ClassLoader.loadClass( String) call.

Parameters:
name - the current class being loaded.

skip

protected boolean skip(java.lang.ClassLoader child,
                       java.lang.String name)
Checks the thread local state to determine whether the provided child needs to be skipped.

Parameters:
child - child class loader to test.
name - the name of the resource being loaded.
Returns:
boolean indicating whether this child should be skipped.

dump

protected final java.lang.String dump()
Dumps a string representation of the current threads local stack.

Returns:
{$link String} representing the current stack state.