FileDocCategorySizeDatePackage
ASURLClassLoader.javaAPI DocGlassfish v2 API7396Fri May 04 22:32:54 BST 2007com.sun.appserv.server.util

ASURLClassLoader

public 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
author
Harsha RA, Sivakumar Thyagarajan

Fields Summary
private URL[]
classLoaderList
List of URLs that this classloader checks for a class
private String
nameOfCL
Name of this classloader - primarily used in the string representation of the classloader - for debugging
private ClassLoader
parentChain
The classloader chain this classloader is a component of
private String
parentToString
toString() 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.StringgetName()

        return this.nameOfCL;
    
public java.lang.ClassloadClass(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 voidsetName(java.lang.String n)

        this.nameOfCL = n;
    
public java.lang.StringtoString()

        String s = this.nameOfCL + " parentCL :: " + 
                             this.parentToString + " URLs :: \n";
        for(URL u:classLoaderList){
            s += ", " + u;
        }
        s +="\n";
        return s;