abbot.script
Class AppClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by abbot.util.PathClassLoader
                  extended by abbot.util.NonDelegatingClassLoader
                      extended by abbot.script.AppClassLoader

public class AppClassLoader
extends NonDelegatingClassLoader

A custom class loader which installs itself as if it were the application class loader. A classpath of null is equivalent to the system property java.class.path.

The class loader may optionally load a class before the parent class loader gets a chance to look for the class (instead of the default behavior, which always delegates to the parent class loader first). This behavior enables the class to be reloaded simply by using a new instance of this class loader with each launch of the app.

This class mimics the behavior of sun.misc.Launcher$AppClassLoader as much as possible.

Bootstrap classes are always delegated to the bootstrap loader, with the exception of the sun.applet package, which should never be delegated, since it does not work properly unless it is reloaded.

The parent of this class loader will be the normal, default AppClassLoader (specifically, the class loader which loaded this class will be used).


Constructor Summary
AppClassLoader()
          Constructs an AppClassLoader using the current classpath (as found in java.class.path).
AppClassLoader(String classPath)
          Constructs a AppClassLoader with a custom classpath, indicating whether the class loader should delegate to its parent class loader prior to searching for a given resource.
 
Method Summary
 Class findClass(String name)
          Finds and loads the class with the specified name from the search path.
 void install()
          Ensure that everything else subsequently loaded on the same thread or any subsequently spawned threads uses the given class loader.
 boolean isEventDispatchThread()
           
 boolean isInstalled()
           
protected  boolean shouldDelegate(String name)
          Should the parent class loader try to load this class first?
 String toString()
           
 void uninstall()
          Reverse the effects of install.
 
Methods inherited from class abbot.util.NonDelegatingClassLoader
loadClass
 
Methods inherited from class abbot.util.PathClassLoader
convertPathToFilenames, convertPathToFiles, getClassPath
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, 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, wait, wait, wait
 

Constructor Detail

AppClassLoader

public AppClassLoader()
Constructs an AppClassLoader using the current classpath (as found in java.class.path).


AppClassLoader

public AppClassLoader(String classPath)
Constructs a AppClassLoader with a custom classpath, indicating whether the class loader should delegate to its parent class loader prior to searching for a given resource.

The class path argument may use either a colon or semicolon to separate its elements.

Method Detail

isEventDispatchThread

public boolean isEventDispatchThread()

shouldDelegate

protected boolean shouldDelegate(String name)
Should the parent class loader try to load this class first?

Overrides:
shouldDelegate in class NonDelegatingClassLoader

findClass

public Class findClass(String name)
                throws ClassNotFoundException
Finds and loads the class with the specified name from the search path. If the class is a bootstrap class and must be preloaded, use our own bootstrap loader. If it is an extension class, use our own extensions loader.

Overrides:
findClass in class NonDelegatingClassLoader
Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
ClassNotFoundException - if the class could not be found

install

public void install()
Ensure that everything else subsequently loaded on the same thread or any subsequently spawned threads uses the given class loader. Also ensure that classes loaded by the event dispatch thread and threads it spawns use the given class loader.


isInstalled

public boolean isInstalled()

uninstall

public void uninstall()
Reverse the effects of install. Has no effect if the class loader has not been installed on any thread.


toString

public String toString()
Overrides:
toString in class PathClassLoader


Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge