org.apache.catalina.loader
Class StandardClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--org.apache.catalina.loader.StandardClassLoader
All Implemented Interfaces:
Reloader

public class StandardClassLoader
extends java.net.URLClassLoader
implements Reloader

Subclass implementation of java.net.URLClassLoader that knows how to load classes from disk directories, as well as local and remote JAR files. It also implements the Reloader interface, to provide automatic reloading support to StandardLoader.

In all cases, URLs must conform to the contract specified by URLClassLoader - any URL that ends with a "/" character is assumed to represent a directory; all other URLs are assumed to be the address of a JAR file.

IMPLEMENTATION NOTE - Local repositories are searched in the order they are added via the initial constructor and/or any subsequent calls to addRepository().

IMPLEMENTATION NOTE - At present, there are no dependencies from this class to any other Catalina class, so that it could be used independently.

Version:
$Revision: 1.5 $ $Date: 2000/10/09 21:04:02 $
Author:
Craig R. McClanahan

Field Summary
protected  java.lang.String[] allowed
          The set of fully qualified class or resource names to which access will be allowed (if they exist) by this class loader, even if the class or resource name would normally be restricted.
protected  java.util.ArrayList available
          The set of optional packages (formerly standard extensions) that are available in the repositories associated with this class loader.
protected  java.util.HashMap classCache
          The cache of ClassCacheEntries for classes we have loaded locally, keyed by class name.
protected  int debug
          The debugging detail level of this component.
protected  boolean delegate
          Should this class loader delegate to the parent class loader before searching its own repositories (i.e.
protected  java.lang.String[] repositories
          The list of local repositories, in the order they should be searched for locally loaded classes or resources.
protected  java.util.ArrayList required
          The set of optional packages (formerly standard extensions) that are required in the repositories associated with this class loader.
protected  java.lang.String[] restricted
          The set of class name prefixes to which access should be restricted.
protected  java.lang.String[] systems
          The set of class and resource name prefixes that should be allowed, but only from the underlying system class loader.
 
Constructor Summary
StandardClassLoader()
          Construct a new ClassLoader with no defined repositories and no parent ClassLoader.
StandardClassLoader(java.lang.ClassLoader parent)
          Construct a new ClassLoader with no defined repositories and the specified parent ClassLoader.
StandardClassLoader(java.lang.String[] repositories)
          Construct a new ClassLoader with the specified repositories and no parent ClassLoader.
StandardClassLoader(java.lang.String[] repositories, java.lang.ClassLoader parent)
          Construct a new ClassLoader with the specified repositories and parent ClassLoader.
StandardClassLoader(java.net.URL[] repositories, java.lang.ClassLoader parent)
          Construct a new ClassLoader with the specified repositories and parent ClassLoader.
 
Method Summary
 void addAllowed(java.lang.String name)
          Add a new fully qualified class or resource name to which access will be allowed, even if the class or resource name would otherwise match one of the restricted patterns.
 void addRepository(java.lang.String repository)
          Add a new repository to the set of places this ClassLoader can look for classes to be loaded.
protected  void addRepositoryInternal(java.lang.String repository)
          Add a repository to our internal array only.
 void addRestricted(java.lang.String prefix)
          Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to fail (unless the complete name is on the allowed list).
 void addSystem(java.lang.String prefix)
          Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to be attempted in the system class loader only (bypassing the repositories defined in this class loader).
protected static java.net.URL[] convert(java.lang.String[] input)
          Convert an array of String to an array of URL and return it.
 java.lang.String[] findAllowed()
          Return a String array of the allowed class or resource name list for this class loader.
 Extension[] findAvailable()
          Return a list of "optional packages" (formerly "standard extensions") that have been declared to be available in the repositories associated with this class loader, plus any parent class loader implemented with the same class.
 java.lang.Class findClass(java.lang.String name)
          Find the specified class in our local repositories, if possible.
protected  java.io.InputStream findLoadedResource(java.lang.String name)
          Finds the resource with the given name if it has previously been loaded and cached by this class loader, and return an input stream to the resource data.
 java.lang.String[] findRepositories()
          Return a String array of the current repositories for this class loader.
 Extension[] findRequired()
          Return a list of "optional packages" (formerly "standard extensions") that have been declared to be required in the repositories associated with this class loader, plus any parent class loader implemented with the same class.
 java.net.URL findResource(java.lang.String name)
          Find the specified resource in our local repository, and return a URL refering to it, or null if this resource cannot be found.
 java.util.Enumeration findResources(java.lang.String name)
          Return an enumeration of URLs representing all of the resources with the given name.
 java.lang.String[] findRestricted()
          Return a String array of the restricted class or resource name prefixes for this class loader.
 java.lang.String[] findSystem()
          Return a Striong array of the sytsem class or resource name prefixes for this class loader.
 int getDebug()
          Return the debugging detail level for this component.
 boolean getDelegate()
          Return the "delegate first" flag for this class loader.
 java.net.URL getResource(java.lang.String name)
          Find the resource with the given name.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Find the resource with the given name, and return an input stream that can be used for reading it.
 java.lang.Class loadClass(java.lang.String name)
          Load the class with the specified name.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load the class with the specified name, searching using the following algorithm until it finds and returns the class.
 boolean modified()
          Have one or more classes or resources been modified so that a reload is appropriate?
 void setDebug(int debug)
          Set the debugging detail level for this component.
 void setDelegate(boolean delegate)
          Set the "delegate first" flag for this class loader.
 java.lang.String toString()
          Render a String representation of this object.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

allowed

protected java.lang.String[] allowed
The set of fully qualified class or resource names to which access will be allowed (if they exist) by this class loader, even if the class or resource name would normally be restricted.

available

protected java.util.ArrayList available
The set of optional packages (formerly standard extensions) that are available in the repositories associated with this class loader. Each object in this list is of type org.apache.catalina.loader.Extension.

classCache

protected java.util.HashMap classCache
The cache of ClassCacheEntries for classes we have loaded locally, keyed by class name.

debug

protected int debug
The debugging detail level of this component.

delegate

protected boolean delegate
Should this class loader delegate to the parent class loader before searching its own repositories (i.e. the usual Java2 delegation model)? If set to false, this class loader will search its own repositories first, and delegate to the parent only if the class or resource is not found locally.

repositories

protected java.lang.String[] repositories
The list of local repositories, in the order they should be searched for locally loaded classes or resources.

required

protected java.util.ArrayList required
The set of optional packages (formerly standard extensions) that are required in the repositories associated with this class loader. Each object in this list is of type org.apache.catalina.loader.Extension.

restricted

protected java.lang.String[] restricted
The set of class name prefixes to which access should be restricted. A request for a class or resource that starts with this prefix will fail with an appropriate exception or null return value, unless that specific class or resource name is on the allowed list.

systems

protected java.lang.String[] systems
The set of class and resource name prefixes that should be allowed, but only from the underlying system class loader.
Constructor Detail

StandardClassLoader

public StandardClassLoader()
Construct a new ClassLoader with no defined repositories and no parent ClassLoader.

StandardClassLoader

public StandardClassLoader(java.lang.ClassLoader parent)
Construct a new ClassLoader with no defined repositories and the specified parent ClassLoader.
Parameters:
parent - The parent ClassLoader

StandardClassLoader

public StandardClassLoader(java.lang.String[] repositories)
Construct a new ClassLoader with the specified repositories and no parent ClassLoader.
Parameters:
repositories - The initial set of repositories

StandardClassLoader

public StandardClassLoader(java.lang.String[] repositories,
                           java.lang.ClassLoader parent)
Construct a new ClassLoader with the specified repositories and parent ClassLoader.
Parameters:
repositories - The initial set of repositories
parent - The parent ClassLoader

StandardClassLoader

public StandardClassLoader(java.net.URL[] repositories,
                           java.lang.ClassLoader parent)
Construct a new ClassLoader with the specified repositories and parent ClassLoader.
Parameters:
repositories - The initial set of repositories
parent - The parent ClassLoader
Method Detail

getDebug

public int getDebug()
Return the debugging detail level for this component.

setDebug

public void setDebug(int debug)
Set the debugging detail level for this component.
Parameters:
debug - The new debugging detail level

getDelegate

public boolean getDelegate()
Return the "delegate first" flag for this class loader.

setDelegate

public void setDelegate(boolean delegate)
Set the "delegate first" flag for this class loader.
Parameters:
delegate - The new "delegate first" flag

addAllowed

public void addAllowed(java.lang.String name)
Add a new fully qualified class or resource name to which access will be allowed, even if the class or resource name would otherwise match one of the restricted patterns.
Specified by:
addAllowed in interface Reloader
Parameters:
name - Class or resource name to allow access for

addRepository

public void addRepository(java.lang.String repository)
Add a new repository to the set of places this ClassLoader can look for classes to be loaded.
Specified by:
addRepository in interface Reloader
Parameters:
repository - Name of a source of classes to be loaded, such as a directory pathname, a JAR file pathname, or a ZIP file pathname
Throws:
java.lang.IllegalArgumentException - if the specified repository is invalid or does not exist

addRestricted

public void addRestricted(java.lang.String prefix)
Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to fail (unless the complete name is on the allowed list).
Specified by:
addRestricted in interface Reloader
Parameters:
prefix - The restricted prefix

addSystem

public void addSystem(java.lang.String prefix)
Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to be attempted in the system class loader only (bypassing the repositories defined in this class loader). By default, the java. prefix is defined as a system prefix.
Specified by:
addSystem in interface Reloader
Parameters:
prefix - The system prefix

findAllowed

public java.lang.String[] findAllowed()
Return a String array of the allowed class or resource name list for this class loader. If there are none, a zero-length array is returned.
Specified by:
findAllowed in interface Reloader

findAvailable

public Extension[] findAvailable()
Return a list of "optional packages" (formerly "standard extensions") that have been declared to be available in the repositories associated with this class loader, plus any parent class loader implemented with the same class.

findRepositories

public java.lang.String[] findRepositories()
Return a String array of the current repositories for this class loader. If there are no repositories, a zero-length array is returned.
Specified by:
findRepositories in interface Reloader

findRequired

public Extension[] findRequired()
Return a list of "optional packages" (formerly "standard extensions") that have been declared to be required in the repositories associated with this class loader, plus any parent class loader implemented with the same class.

findRestricted

public java.lang.String[] findRestricted()
Return a String array of the restricted class or resource name prefixes for this class loader. If there are none, a zero-length array is returned.
Specified by:
findRestricted in interface Reloader

findSystem

public java.lang.String[] findSystem()
Return a Striong array of the sytsem class or resource name prefixes for this class loader. If there are none, a zero-length array is returned.
Specified by:
findSystem in interface Reloader

modified

public boolean modified()
Have one or more classes or resources been modified so that a reload is appropriate?

IMPLEMENTATION NOTE - We assume that anything loaded from a JAR file will never need to be reloaded unless the JAR file itself has been updated. Unpacked classes or resources loaded from a directory are checked individually.

Specified by:
modified in interface Reloader

toString

public java.lang.String toString()
Render a String representation of this object.
Overrides:
toString in class java.lang.Object

findClass

public java.lang.Class findClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Find the specified class in our local repositories, if possible. If not found, throw ClassNotFoundException.
Overrides:
findClass in class java.net.URLClassLoader
Parameters:
name - Name of the class to be loaded
Throws:
java.lang.ClassNotFoundException - if the class was not found

findResource

public java.net.URL findResource(java.lang.String name)
Find the specified resource in our local repository, and return a URL refering to it, or null if this resource cannot be found.
Overrides:
findResource in class java.net.URLClassLoader
Parameters:
name - Name of the resource to be found

findResources

public java.util.Enumeration findResources(java.lang.String name)
                                    throws java.io.IOException
Return an enumeration of URLs representing all of the resources with the given name. If no resources with this name are found, return an empty enumeration.
Overrides:
findResources in class java.net.URLClassLoader
Parameters:
name - Name of the resources to be found
Throws:
java.io.IOException - if an input/output error occurs

getResource

public java.net.URL getResource(java.lang.String name)
Find the resource with the given name. A resource is some data (images, audio, text, etc.) that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a "/"-separated path name that identifies the resource. If the resource cannot be found, return null.

This method searches according to the following algorithm, returning as soon as it finds the appropriate URL. If the resource cannot be found, returns null.

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - Name of the resource to return a URL for

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Find the resource with the given name, and return an input stream that can be used for reading it. The search order is as described for getResource(), after checking to see if the resource data has been previously cached. If the resource cannot be found, return null.
Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
name - Name of the resource to return an input stream for

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Load the class with the specified name. This method searches for classes in the same manner as loadClass(String, boolean) with false as the second argument.
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - Name of the class to be loaded
Throws:
java.lang.ClassNotFoundException - if the class was not found

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Load the class with the specified name, searching using the following algorithm until it finds and returns the class. If the class cannot be found, returns ClassNotFoundException. If the class was found using the above steps, and the resolve flag is true, this method will then call resolveClass(Class) on the resulting Class object.
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - Name of the class to be loaded
resolve - If true then resolve the class
Throws:
java.lang.ClassNotFoundException - if the class was not found

addRepositoryInternal

protected void addRepositoryInternal(java.lang.String repository)
Add a repository to our internal array only.
Parameters:
repository - The new repository
Throws:
java.lang.IllegalArgumentException - if the manifest of a JAR file cannot be processed correctly

convert

protected static java.net.URL[] convert(java.lang.String[] input)
Convert an array of String to an array of URL and return it.
Parameters:
input - The array of String to be converted

findLoadedResource

protected java.io.InputStream findLoadedResource(java.lang.String name)
Finds the resource with the given name if it has previously been loaded and cached by this class loader, and return an input stream to the resource data. If this resource has not been cached, return null.
Parameters:
name - Name of the resource to return


Copyright © 2000 Apache Software Foundation. All Rights Reserved.