com.caucho.util
Class DynamicClassLoader

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

public class DynamicClassLoader
extends java.security.SecureClassLoader

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
DynamicClassLoader(java.lang.ClassLoader parent)
          Create a new class loader (jdk1.2)
 
Method Summary
protected  void addCodeBasePath(java.lang.String path)
           
 void addListener(ClassLoaderListener listener)
          Adds a listener to detect class loader changes.
 void addParentPriorityPackage(java.lang.String pkg)
          Add to the list of packages that don't use the hack.
 void addPermission(java.security.Permission permission)
           
 void addPermission(java.lang.String path, java.lang.String actions)
           
 void addPermissions(java.util.ArrayList perms)
           
 void destroy()
           
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.
protected  Path getCodePath()
           
 java.lang.Object getLevelAttribute(java.lang.String name)
          Returns the named attributes
 java.lang.ClassLoader getParentLoader()
          Returns the parent class loader.
protected  Path getPath(java.lang.String name)
          Returns the path of the named resource
 java.util.ArrayList getPermissions()
           
protected  java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)
           
 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.
protected  java.lang.Class loadClass(DynamicClassLoader.Entry entry)
          Loads the class from the loader.
 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 setServletHack(boolean servletHack)
          Set true if the loader should use the servlet spec's hack.
 void unload()
          Unloads the classloader.
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
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

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

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.

addPermission

public void addPermission(java.lang.String path,
                          java.lang.String actions)

addPermission

public void addPermission(java.security.Permission permission)

getPermissions

public java.util.ArrayList getPermissions()

addPermissions

public void addPermissions(java.util.ArrayList perms)

setServletHack

public void setServletHack(boolean servletHack)
Set true if the loader should use the servlet spec's hack.

addParentPriorityPackage

public void addParentPriorityPackage(java.lang.String pkg)
Add to the list of packages that don't use the hack.

getPermissions

protected java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)
Overrides:
getPermissions in class java.security.SecureClassLoader

addCodeBasePath

protected void addCodeBasePath(java.lang.String path)

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.io.IOException,
                          java.lang.ClassNotFoundException
Makes any changed classes for the virtual class loader.

makeAllInt

protected void makeAllInt()
                   throws java.io.IOException,
                          java.lang.ClassNotFoundException
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
Parameters:
name - the classname using either '/' or '.'
Returns:
the loaded class

loadClass

protected java.lang.Class loadClass(DynamicClassLoader.Entry entry)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Loads the class from the loader. The loadClass must be in the top classLoader because the defineClass must be owned by the top.

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

getCodePath

protected Path getCodePath()

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

getLevelAttribute

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

setAttribute

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

destroy

public void destroy()