gate.util
Class ReloadingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by gate.util.ReloadingClassLoader

public class ReloadingClassLoader
extends ClassLoader


Nested Class Summary
protected  class ReloadingClassLoader.LocationClassLoader
          A ClassLoader that loads classes from a location specified by an URL.
 
Field Summary
protected  Map loaders
          Map that contains the ReloadingClassLoader.LocationClassLoader for each registered URL.
protected  ClassLoader parent
          The parent class loader.
 
Constructor Summary
ReloadingClassLoader()
          Constructs a ReloadingClassLoader using the System Class Loader as a parent.
ReloadingClassLoader(ClassLoader parent)
          Constructs a ReloadingClassLoader using a custom class loader as parent.
 
Method Summary
 void load(URL url)
          Registers an URL as a location where class files can be found.
protected  Class loadClass(String name, boolean resolve)
          Loads the class with the specified name.
 void unload(URL url)
          Removes a registered URL.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, 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, toString, wait, wait, wait
 

Field Detail

loaders

protected Map loaders
Map that contains the ReloadingClassLoader.LocationClassLoader for each registered URL.


parent

protected ClassLoader parent
The parent class loader.

Constructor Detail

ReloadingClassLoader

public ReloadingClassLoader(ClassLoader parent)
Constructs a ReloadingClassLoader using a custom class loader as parent.

Parameters:
parent - the parent class loader. The parent class loader should give access to the system classes at the least (in order to load a new class access to Object is required).

ReloadingClassLoader

public ReloadingClassLoader()
Constructs a ReloadingClassLoader using the System Class Loader as a parent.

Method Detail

load

public void load(URL url)
Registers an URL as a location where class files can be found. If the URL was already registered the the classes found at the location will be reloaded.

Parameters:
url - the URL pointing to a jar file or to a directory containing class files.

unload

public void unload(URL url)
Removes a registered URL.

Parameters:
url - the URl to be unloaded.

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Loads the class with the specified name. It searches for classes in the following order:
  1. the parent classloader
  2. all the locations registered with this class loader

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