A simple extension of UnifiedLoaderRepository3 that adds the notion of a
parent UnifiedLoaderRepository. Classes and resources are loaded from child
first and then the parent depending on the java2ParentDelegaton flag.
| Method from org.jboss.mx.loading.HeirarchicalLoaderRepository4 Detail: |
public UnifiedClassLoader4 getClassLoader(String name) {
return new UClWrapper(this);
}
Called by LoadMgr to obtain all class loaders. This returns a set of
PkgClassLoader with the HeirarchicalLoaderRepository3 ordered ahead of
the parent repository pkg class loaders |
public URL getResource(String name,
ClassLoader scl) {
URL resource = null;
if( java2ParentDelegaton == true )
{
// Try this repository
resource = parentRepository.getResource(name, scl);
// Next try our parent repository
if( resource == null )
resource = super.getResource(name, scl);
}
else
{
// Try this repository
resource = super.getResource(name, scl);
// Next try our parent repository
if( resource == null )
resource = parentRepository.getResource(name, scl);
}
return resource;
}
Find a resource from this repository. This first looks to this
repository and then the parent repository. |
public void getResources(String name,
ClassLoader cl,
List urls) {
if( java2ParentDelegaton == true )
{
// Get the parent repository resources
parentRepository.getResources(name, cl, urls);
// Next get this repositories resources
super.getResources(name, cl, urls);
}
else
{
// Get this repositories resources
super.getResources(name, cl, urls);
// Next get the parent repository resources
parentRepository.getResources(name, cl, urls);
}
}
Find all resource URLs for the given name. This is entails an
exhuastive search of this and the parent repository and is an expensive
operation. |
public URL[] getURLs() {
URL[] ourURLs = super.getURLs();
URL[] parentURLs = parentRepository.getURLs();
int size = ourURLs.length + parentURLs.length;
URL[] urls = new URL[size];
System.arraycopy(ourURLs, 0, urls, 0, ourURLs.length);
System.arraycopy(parentURLs, 0, urls, ourURLs.length, parentURLs.length);
return urls;
}
Obtain a listing of the URLs for all UnifiedClassLoaders associated with
the repository |
public boolean getUseParentFirst() {
return java2ParentDelegaton;
}
Get the use parent first flag. This indicates whether the parent
repository is consulted first for resource and class loading or if the
HeirchicalLoaderRepository is consulted first. |
UnifiedClassLoader4 internalGetClassLoader(String name) {
UnifiedClassLoader4 thisUCL = super.getClassLoader(name);
UnifiedClassLoader4 ucl = thisUCL;
if( ucl == null )
{
UnifiedClassLoader4 parentUCL = parentRepository.getClassLoader(name);
ucl = parentUCL;
}
return ucl;
}
|
UnifiedClassLoader4 internalGetParentClassLoader() {
UnifiedClassLoader4 ucl = null;
Iterator iter = parentRepository.getClassLoaders().iterator();
if( iter.hasNext() )
ucl = (UnifiedClassLoader4) iter.next();
else
{
ClassLoader loader = getClass().getClassLoader();
if( loader instanceof UnifiedClassLoader4 )
ucl = (UnifiedClassLoader4) loader;
else
ucl = new UnifiedClassLoader4(null, null, loader, this);
}
return ucl;
}
|
public Class loadClass(String name,
boolean resolve,
ClassLoader scl) throws ClassNotFoundException {
Class foundClass = null;
if( java2ParentDelegaton == true )
{
try
{
// Try the parent repository first
foundClass = parentRepository.loadClass(name, resolve, scl);
}
catch(ClassNotFoundException e)
{
// Next try our repository
if( foundClass == null )
foundClass = super.loadClass(name, resolve, scl);
}
}
else
{
try
{
// Try this repository first
foundClass = super.loadClass(name, resolve, scl);
}
catch(ClassNotFoundException e)
{
// Next try our parent repository
if( foundClass == null )
foundClass = parentRepository.loadClass(name, resolve, scl);
}
}
if( foundClass != null )
return foundClass;
/* If we reach here, all of the classloaders currently in the VM don't
know about the class
*/
throw new ClassNotFoundException(name);
}
Load a class using the repository class loaders. |
public Class loadClassFromCache(String name) {
Class foundClass = null;
if( java2ParentDelegaton == true )
{
// Try this repository
foundClass = parentRepository.loadClassFromCache(name);
// Next try our parent repository
if( foundClass == null )
foundClass = super.loadClassFromCache(name);
}
else
{
// Try this repository
foundClass = super.loadClassFromCache(name);
/* We do not try the parent repository cache as this does not allow
the child repository to override classes in the parent
*/
}
return foundClass;
}
Called by LoadMgr to locate a previously loaded class. This looks
first to this repository and then the parent repository. |
public UnifiedClassLoader newClassLoader(URL url,
boolean addToRepository) throws Exception {
UnifiedClassLoader4 ucl = null;
if( java2ParentDelegaton == false )
ucl = new UnifiedClassLoader4(url, null, new NoParentClassLoader(), this);
else
ucl = new UnifiedClassLoader4(url, null, this);
if( addToRepository )
{
this.registerClassLoader(ucl);
}
return ucl;
}
|
public UnifiedClassLoader newClassLoader(URL url,
URL origURL,
boolean addToRepository) throws Exception {
UnifiedClassLoader4 ucl = null;
if( java2ParentDelegaton == false )
ucl = new UnifiedClassLoader4(url, origURL, new NoParentClassLoader(), this);
else
ucl = new UnifiedClassLoader4(url, origURL, this);
if( addToRepository )
{
this.registerClassLoader(ucl);
}
return ucl;
}
|
public void setUseParentFirst(boolean flag) {
java2ParentDelegaton = flag;
}
Set the use parent first flag. This indicates whether the parent
repository is consulted first for resource and class loading or if the
HeirchicalLoaderRepository is consulted first. |