ASURLClassLoaderpublic class ASURLClassLoader extends URLClassLoader ASURLClassLoader represents a individual component
in the ASClassLoaderChain .
Since it is a subclass of URLClassLoader it can contain a
search path of one or more URLs |
Fields Summary |
---|
private URL[] | classLoaderListList of URLs that this classloader checks for a class | private String | nameOfCLName of this classloader - primarily used in the string
representation of the classloader - for debugging | private ClassLoader | parentChainThe classloader chain this classloader is a component of | private String | parentToStringtoString() representation of parent - to prevent recursion | private Set | notFoundClasses | private Hashtable | loadedClasses |
Constructors Summary |
---|
public ASURLClassLoader(URL[] urls, ClassLoader parent)
/*
public ASURLClassLoader(URL[] urls) {
super(urls); //Parent: System ClassLoader.
this.classLoaderList = urls;
}
*/
//The parent of the classloader chain component
//is either the SystemClassLoader (if shared chain is null!)
//or the Shared Chain.
//super(urls, PELaunch.getSharedChain());
super(urls, PELaunch.getSharedChain()!=null ?PELaunch.getSharedChain()
: ClassLoader.getSystemClassLoader());
this.parentChain = parent;
if(this.parentChain instanceof ClassLoaderChain) {
//Computed earlier to prevent recursion in toString of this
//class
this.parentToString =
((ClassLoaderChain)this.parentChain).getName();
} else {
this.parentToString = this.parentChain.toString();
}
this.classLoaderList = urls;
|
Methods Summary |
---|
public java.lang.String | getName()
return this.nameOfCL;
| public java.lang.Class | loadClass(java.lang.String name, boolean resolve)The loading strategy is:
- check self first and
- then delegate to parent chain if one exists. This is done to prevent recursion
while referring to the chain. One issue with this approach is that when class load
requests come via this component classloader, it might override a duplicate class in
a peer present earlier in the chain.
try {
//perf optimization
//check notFoundClasses cache first
if (notFoundClasses.contains(name)) {
throw new ClassNotFoundException(name);
}
Class cls = null;
//perf optimization
//check loadedClasses cache first
cls = loadedClasses.get(name);
if (cls != null) {
return cls;
}
//Hands over to URLClassLoader.loadClass. First attempt to delegate
//to parent and then check for the class in the
//<code>classLoaderList</code>.
cls = super.loadClass(name, resolve);
if (cls != null) {
loadedClasses.put(name, cls);
return cls;
}
//Class not in this chain component.
throw new ClassNotFoundException(name);
} catch(ClassNotFoundException e) {
//If the parent is a ClassLoaderChain, check in the ClassLoaderChain
//ignoring this classloader component instance. Failure to do this
//would result in an infinte recursive call.
if ((parentChain != null) &&
(parentChain instanceof ClassLoaderChain)) {
ClassLoaderChain chain = (ClassLoaderChain)parentChain;
//Ask parent chain to load class, skipping self
Class c = chain.loadClass(name,this);
//Resolve if required.
if (c != null) {
if(resolve) {
resolveClass(c);
}
loadedClasses.put(name, c);
return c;
}
}
//perf optimization
if (!(notFoundClasses.contains(name))) {
notFoundClasses.add(name);
}
throw e;
}
| public void | setName(java.lang.String n)
this.nameOfCL = n;
| public java.lang.String | toString()
String s = this.nameOfCL + " parentCL :: " +
this.parentToString + " URLs :: \n";
for(URL u:classLoaderList){
s += ", " + u;
}
s +="\n";
return s;
|
|