com.caucho.util
Class DynamicClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.caucho.util.DynamicClassLoader
Direct Known Subclasses:
DirectoryClassLoader, SimpleClassLoader

public abstract class DynamicClassLoader
extends java.lang.ClassLoader

Class loader which checks for changes in class files and automatically picks up new jars.

DynamicClassLoaders can be chained creating one virtual class loader. From the perspective of the JDK, it's all one classloader. Internally, the class loader chain searches like a classpath.


Inner Class Summary
 class DynamicClassLoader.Entry
          Describes a cached loaded class entry.
 
Field Summary
protected  DynamicClassLoader top
           
 
Constructor Summary
protected DynamicClassLoader()
          Create a new class loader
protected DynamicClassLoader(java.lang.ClassLoader parent)
          Create a new class loader (jdk1.2)
 
Method Summary
 void addListener(ClassLoaderListener listener)
          Adds a listener to detect class loader changes.
protected  java.lang.Class findClass(java.lang.String name)
          Load a class using this class loader
 java.lang.String findLibrary(java.lang.String name)
          Returns the full library path for the name.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the named attributes
protected  DynamicClassLoader.Entry getClassEntry(java.lang.String name)
          Returns the class entry.
 java.lang.String getClassPath()
          Fill data for the class path.
protected  java.lang.String getClassPath(java.lang.String head)
          Default implementation of getting a classpath segment.
 java.lang.ClassLoader getParentLoader()
          Returns the parent class loader.
protected  Path getPath(java.lang.String name)
          Returns the path of the named resource
 java.net.URL getResource(java.lang.String name)
          Gets the named resource
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Opens a stream to a resource somewhere in the classpath
 java.lang.String getSourcePath()
          Returns the source path.
protected  java.lang.String getSourcePath(java.lang.String head)
          Default implementation of getting a sourcepath segment.
 DynamicClassLoader getTop()
          Returns the first classloader in the virtual chain.
 boolean isModified()
          Returns true if any of the classes have been modified.
protected  boolean isModifiedInt()
          True if any of the loaded classes have been modified.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load a class using this class loader
 void makeAll()
          Makes any changed classes for the virtual class loader.
protected  void makeAllInt()
          Makes any changed classes for this specific class loader.
 void setAttribute(java.lang.String name, java.lang.Object obj)
          Sets the named attributes
 void setNext(DynamicClassLoader next)
          Sets the next class loader in the virtual chain.
 void setParent(java.lang.ClassLoader parent)
          Sets the parent of the class loader.
 void unload()
          Unloads the classloader.
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

top

protected DynamicClassLoader top
Constructor Detail

DynamicClassLoader

protected DynamicClassLoader()
Create a new class loader

DynamicClassLoader

protected DynamicClassLoader(java.lang.ClassLoader parent)
Create a new class loader (jdk1.2)
Parameters:
parent - parent class loader
Method Detail

setParent

public void setParent(java.lang.ClassLoader parent)
Sets the parent of the class loader. The parent classloader has priority over the child classloader.
Parameters:
parent - the parent classloader

setNext

public void setNext(DynamicClassLoader next)
Sets the next class loader in the virtual chain.

getTop

public DynamicClassLoader getTop()
Returns the first classloader in the virtual chain.

getParentLoader

public java.lang.ClassLoader getParentLoader()
Returns the parent class loader. Only the classloader at the top matters.

getClassPath

public final java.lang.String getClassPath()
Fill data for the class path. fillClassPath() will add all .jar and .zip files in the directory list.

getSourcePath

public final java.lang.String getSourcePath()
Returns the source path. The source path is used for looking up resources.

getClassPath

protected java.lang.String getClassPath(java.lang.String head)
Default implementation of getting a classpath segment.

getSourcePath

protected java.lang.String getSourcePath(java.lang.String head)
Default implementation of getting a sourcepath segment.

isModified

public final boolean isModified()
Returns true if any of the classes have been modified.

isModifiedInt

protected boolean isModifiedInt()
True if any of the loaded classes have been modified. If true, the caller should drop the classpath and create a new one.

makeAll

public final void makeAll()
                   throws java.lang.Exception
Makes any changed classes for the virtual class loader.

makeAllInt

protected void makeAllInt()
                   throws java.lang.Exception
Makes any changed classes for this specific class loader.

addListener

public final void addListener(ClassLoaderListener listener)
Adds a listener to detect class loader changes.

unload

public void unload()
Unloads the classloader. This is just for cleanup to make the garbage collection more efficient.

loadClass

public final java.lang.Class loadClass(java.lang.String name,
                                       boolean resolve)
                                throws java.lang.ClassNotFoundException
Load a class using this class loader
Overrides:
loadClass in class java.lang.ClassLoader

findClass

protected final java.lang.Class findClass(java.lang.String name)
                                   throws java.lang.ClassNotFoundException
Load a class using this class loader
Overrides:
findClass in class java.lang.ClassLoader

getClassEntry

protected DynamicClassLoader.Entry getClassEntry(java.lang.String name)
                                          throws java.lang.ClassNotFoundException
Returns the class entry.
Parameters:
name - name of the class

getResource

public final java.net.URL getResource(java.lang.String name)
Gets the named resource
Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - name of the resource

getResourceAsStream

public final java.io.InputStream getResourceAsStream(java.lang.String name)
Opens a stream to a resource somewhere in the classpath
Overrides:
getResourceAsStream in class java.lang.ClassLoader

findLibrary

public java.lang.String findLibrary(java.lang.String name)
Returns the full library path for the name.
Overrides:
findLibrary in class java.lang.ClassLoader

getPath

protected Path getPath(java.lang.String name)
Returns the path of the named resource
Parameters:
name - the name of the resource.

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the named attributes

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object obj)
Sets the named attributes