gate.util
Class GateClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--gate.util.GateClassLoader

public class GateClassLoader
extends URLClassLoader

GATE's class loader, which allows loading of classes over the net. A list of URLs is searched, which should point at .jar files or to directories containing class file hierarchies. The class loader is unusual in supporting reloading of classes, which is useful for CREOLE developers who want to recompile modules without relaunching GATE. The loader is also used for creating JAPE RHS action classes.


Inner classes inherited from class java.lang.ClassLoader
ClassLoader.NativeLibrary
 
Field Summary
private static GateClassLoader cachedReloader
          A cache used by the reloadClass method to store the last new loader that we created.
private static boolean DEBUG
          Debug flag
 
Fields inherited from class java.net.URLClassLoader
acc, ucp
 
Fields inherited from class java.security.SecureClassLoader
debug, initialized, pdcache
 
Fields inherited from class java.lang.ClassLoader
bootstrapClassPath, classes, defaultDomain, defaultPermissions, domains, getClassLoaderPerm, loadedLibraryNames, nativeLibraries, nativeLibraryContext, nocerts, package2certs, packages, parent, scl, sclSet, sys_paths, systemNativeLibraries, usr_paths
 
Constructor Summary
GateClassLoader()
          Default construction - use an empty URL list.
GateClassLoader(ClassLoader parent)
          Chaining constructor.
GateClassLoader(URL[] urls)
          Default construction with URLs list.
GateClassLoader(URL[] urls, ClassLoader parent)
          Chaining constructor with URLs list.
 
Method Summary
 void addURL(URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
 Class defineGateClass(String name, byte[] bytes, int offset, int len)
          Forward a call to super.defineClass, which is protected and final in super.
 Class loadClass(String name, boolean resolve)
          Delegate loading to the super class (loadClass has protected access there).
 Class reloadClass(String name)
          Reload a class.
 void resolveGateClass(Class c)
          Forward a call to super.resolveClass, which is protected and final in super.
 
Methods inherited from class java.net.URLClassLoader
defineClass, definePackage, findClass, findResource, findResources, getPermissions, getURLs, isSealed, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
, check, defineClass, getProtectionDomain
 
Methods inherited from class java.lang.ClassLoader
addClass, checkCerts, checkPackageAccess, compareCerts, defineClass, defineClass, defineClass, defineClass0, definePackage, findBootstrapClass, findBootstrapClass0, findLibrary, findLoadedClass, findNative, findSystemClass, getBootstrapClassPath, getBootstrapResource, getBootstrapResources, getCallerClassLoader, getDefaultDomain, getGetClassLoaderPerm, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, initializePath, isAncestor, loadClass, loadClassInternal, loadLibrary, loadLibrary0, resolveClass, resolveClass0, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

cachedReloader

private static GateClassLoader cachedReloader
A cache used by the reloadClass method to store the last new loader that we created.
Constructor Detail

GateClassLoader

public GateClassLoader()
Default construction - use an empty URL list.

GateClassLoader

public GateClassLoader(ClassLoader parent)
Chaining constructor.

GateClassLoader

public GateClassLoader(URL[] urls)
Default construction with URLs list.

GateClassLoader

public GateClassLoader(URL[] urls,
                       ClassLoader parent)
Chaining constructor with URLs list.
Method Detail

addURL

public void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.
Overrides:
addURL in class URLClassLoader

loadClass

public Class loadClass(String name,
                       boolean resolve)
                throws ClassNotFoundException
Delegate loading to the super class (loadClass has protected access there).
Overrides:
loadClass in class ClassLoader

defineGateClass

public Class defineGateClass(String name,
                             byte[] bytes,
                             int offset,
                             int len)
Forward a call to super.defineClass, which is protected and final in super. This is used by JAPE and the Jdk compiler class.

resolveGateClass

public void resolveGateClass(Class c)
Forward a call to super.resolveClass, which is protected and final in super. This is used by JAPE and the Jdk compiler class

reloadClass

public Class reloadClass(String name)
                  throws ClassNotFoundException
Reload a class. This works on the assumption that all classes that we are asked to reload will have been loaded by a GateClassLoader and not the system class loader. If this is not the case, this method will simply return the previously loaded class (because of the delegation chaining model of class loaders in JDK1.2 and above).

The method works by avoiding the normal chaining behaviour of class loaders by creating a star-shaped group of parallel loaders. Each of these chains of the system class loader, but as long as the class that we wish to reload wan't loaded by the system loader, it will not be present in a new loader of this type.

An implication is that reloaded classes must always be instantiated via the class returned from this method.