org.netbeans.bootstrap/1 2.52

org.netbeans
Class ProxyClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.netbeans.ProxyClassLoader
Direct Known Subclasses:
JarClassLoader

public class ProxyClassLoader
extends ClassLoader

A class loader that has multiple parents and uses them for loading classes and resources. It is optimized for working in the enviroment of a deeply nested classloader hierarchy. It uses shared knowledge about package population to route the loading request directly to the correct classloader. It doesn't load classes or resources itself, but allows subclasses to add such functionality.


Constructor Summary
ProxyClassLoader(ClassLoader[] parents, boolean transitive)
          Create a multi-parented classloader.
 
Method Summary
protected  void addCoveredPackages(Iterable<String> coveredPackages)
           
 void append(ClassLoader[] nueparents)
          Add new parents dynamically.
protected  Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
          This is here just for locking serialization purposes.
 void destroy()
          Called before releasing the classloader so it can itself unregister from the global ClassLoader pool
protected  Class doLoadClass(String pkg, String name)
          This ClassLoader can't load anything itself.
 URL findResource(String name)
          This ClassLoader can't load anything itself.
 Enumeration<URL> findResources(String name)
           
protected  Package getPackage(String name)
          Returns a Package that has been defined by this class loader or any of its parents.
protected  Package getPackageFast(String name, boolean recurse)
          Faster way to find a package.
protected  Package[] getPackages()
          Returns all of the Packages defined by this class loader and its parents.
 URL getResource(String name)
          Finds the resource with the given name.
 Enumeration<URL> getResources(String name)
           
protected  Class loadClass(String name, boolean resolve)
          Loads the class with the specified name.
protected  void setSystemClassLoader(ClassLoader s)
           
protected  boolean shouldDelegateResource(String pkg, ClassLoader parent)
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, findClass, findLibrary, findLoadedClass, findSystemClass, 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, toString, wait, wait, wait
 

Constructor Detail

ProxyClassLoader

public ProxyClassLoader(ClassLoader[] parents,
                        boolean transitive)
Create a multi-parented classloader.

Parameters:
parents - all direct parents of this classloader, except system one.
transitive - whether other PCLs depending on this one will automatically search through its parent list
Method Detail

addCoveredPackages

protected final void addCoveredPackages(Iterable<String> coveredPackages)

append

public void append(ClassLoader[] nueparents)
            throws IllegalArgumentException
Add new parents dynamically.

Parameters:
nueparents - the new parents to add (append to list)
Throws:
IllegalArgumentException - in case of a null or cyclic parent (duplicate OK)

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Loads the class with the specified name. The implementation of this method searches for classes in the following order:

  1. Looks for a known package and pass the loading to the ClassLoader for that package.
  2. For unknown packages passes the call directly already been loaded.

Overrides:
loadClass in class ClassLoader
Parameters:
name - the name of the class
resolve - if true then resolve the class
Returns:
the resulting Class object
Throws:
ClassNotFoundException - if the class could not be found

doLoadClass

protected Class doLoadClass(String pkg,
                            String name)
This ClassLoader can't load anything itself. Subclasses may override this method to do some class loading themselves. The implementation should not throw any exception, just return null if it can't load required class.

Parameters:
name - the name of the class
Returns:
the resulting Class object or null

getResource

public final URL getResource(String name)
Finds the resource with the given name.

Overrides:
getResource in class ClassLoader
Parameters:
name - a "/"-separated path name that identifies the resource.
Returns:
a URL for reading the resource, or null if the resource could not be found.
See Also:
findResource(String)

findResource

public URL findResource(String name)
This ClassLoader can't load anything itself. Subclasses may override this method to do some resource loading themselves.

Overrides:
findResource in class ClassLoader
Parameters:
name - the resource name
Returns:
a URL for reading the resource, or null if the resource could not be found.

getResources

public final Enumeration<URL> getResources(String name)
                                    throws IOException
Overrides:
getResources in class ClassLoader
Throws:
IOException

findResources

public Enumeration<URL> findResources(String name)
                               throws IOException
Overrides:
findResources in class ClassLoader
Throws:
IOException

getPackage

protected Package getPackage(String name)
Returns a Package that has been defined by this class loader or any of its parents.

Overrides:
getPackage in class ClassLoader
Parameters:
name - the package name
Returns:
the Package corresponding to the given name, or null if not found

getPackageFast

protected Package getPackageFast(String name,
                                 boolean recurse)
Faster way to find a package.

Parameters:
name - package name in org.netbeans.modules.foo format
sname - package name in org/netbeans/modules/foo/ format
recurse - whether to also ask parents
Returns:
located package, or null

definePackage

protected Package definePackage(String name,
                                String specTitle,
                                String specVersion,
                                String specVendor,
                                String implTitle,
                                String implVersion,
                                String implVendor,
                                URL sealBase)
                         throws IllegalArgumentException
This is here just for locking serialization purposes. Delegates to super.definePackage with proper locking. Also tracks the package in our private cache, since getPackageFast(...,...,false) will not call super.getPackage.

Overrides:
definePackage in class ClassLoader
Throws:
IllegalArgumentException

getPackages

protected Package[] getPackages()
Returns all of the Packages defined by this class loader and its parents.

Overrides:
getPackages in class ClassLoader
Returns:
the array of Package objects defined by this ClassLoader

setSystemClassLoader

protected final void setSystemClassLoader(ClassLoader s)

shouldDelegateResource

protected boolean shouldDelegateResource(String pkg,
                                         ClassLoader parent)

destroy

public void destroy()
Called before releasing the classloader so it can itself unregister from the global ClassLoader pool


org.netbeans.bootstrap/1 2.52

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.