org.backsource.utils.lang
Class ReverseClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.backsource.utils.lang.ReverseClassLoader

public class ReverseClassLoader
extends java.net.URLClassLoader

A URLClassLoader wrapper that loads classes and resouces first from the leafs of the classloader tree, and not from the root as is the case with the sun classloader.

It is important to understand that all classes are loaded into the classloader wrapper and the new wrapper it created around its parent.

It is also important to know that if a URLClassLoader has a parent that is not a URLClassLoader, the normal classloading and resource finding mechanisms will be used.

May be really handy if you want to override a resource (or class) in a component loaded in leaf classloader, as is often the case in JBoss and Tomcat for example.

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Constructor Summary
ReverseClassLoader(java.net.URLClassLoader wrappedClassLoader)
          Wrap a URLClassLoader.
 
Method Summary
 java.net.URL findResource(java.lang.String name)
           
 java.net.URL getResource(java.lang.String name)
          Get resource through a bottom up search.
 java.lang.ClassLoader getWrappedClassLoader()
           
protected  java.lang.Class loadClass(ReverseClassLoader cl, java.lang.String name)
           
 java.lang.Class loadClass(java.lang.String name)
          Load a class by looking in this classloader and searching upwards as long as the parent classloaders are URLClassloader.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, 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

ReverseClassLoader

public ReverseClassLoader(java.net.URLClassLoader wrappedClassLoader)

Wrap a URLClassLoader.

The all URLs the classloader wikk be search first, and lodaded in this classloader, and not in the wrapped one.

Method Detail

getWrappedClassLoader

public java.lang.ClassLoader getWrappedClassLoader()

getResource

public java.net.URL getResource(java.lang.String name)
Get resource through a bottom up search. I.e try find the resource in the wrapped loader before proceding to the parent.


findResource

public java.net.URL findResource(java.lang.String name)

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException

Load a class by looking in this classloader and searching upwards as long as the parent classloaders are URLClassloader.

It is important to notice that the classes will be loaded in this classloader or in any of its contsucted parents (also ReverseClassLoader) and not in the wrapped classloader.

Throws:
java.lang.ClassNotFoundException

loadClass

protected java.lang.Class loadClass(ReverseClassLoader cl,
                                    java.lang.String name)
                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException


Copyright © 2000-2004 Backsource. All Rights Reserved.