| java.net.URLClassLoader org.apache.catalina.loader.WebappClassLoader
WebappClassLoader | public class WebappClassLoader extends URLClassLoader implements Reloader,Lifecycle(Code) | | Specialized web application class loader.
This class loader is a full reimplementation of the
URLClassLoader from the JDK. It is desinged to be fully
compatible with a normal URLClassLoader , although its internal
behavior may be completely different.
IMPLEMENTATION NOTE - This class loader faithfully follows
the delegation model recommended in the specification. The system class
loader will be queried first, then the local repositories, and only then
delegation to the parent class loader will occur. This allows the web
application to override any shared class except the classes from J2SE.
Special handling is provided from the JAXP XML parser interfaces, the JNDI
interfaces, and the classes from the servlet API, which are never loaded
from the webapp repository.
IMPLEMENTATION NOTE - Due to limitations in Jasper
compilation technology, any repository which contains classes from
the servlet API will be ignored by the class loader.
IMPLEMENTATION NOTE - The class loader generates source
URLs which include the full JAR URL when a class is loaded from a JAR file,
which allows setting security permission at the class level, even when a
class is contained inside a JAR.
IMPLEMENTATION NOTE - Local repositories are searched in
the order they are added via the initial constructor and/or any subsequent
calls to addRepository() or addJar() .
IMPLEMENTATION NOTE - No check for sealing violations or
security is made unless a security manager is present.
author: Remy Maucherat author: Craig R. McClanahan version: $Revision: 1.45 $ $Date: 2002/08/09 10:01:48 $ |
Field Summary | |
protected ArrayList | available The set of optional packages (formerly standard extensions) that
are available in the repositories associated with this class loader. | 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 File[] | files Repositories translated as path in the work directory (for Jasper
originally), but which is used to generate fake URLs should getURLs be
called. | protected boolean | hasExternalRepositories Has external repositories. | protected JarFile[] | jarFiles The list of JARs, in the order they should be searched
for locally loaded classes or resources. | protected String[] | jarNames The list of JARs, in the order they should be searched
for locally loaded classes or resources. | protected String | jarPath The path which will be monitored for added Jar files. | protected File[] | jarRealFiles The list of JARs, in the order they should be searched
for locally loaded classes or resources. | protected long[] | lastModifiedDates The list of JARs last modified dates, in the order they should be
searched for locally loaded classes or resources. | protected HashMap | notFoundResources The list of not found resources. | protected String[] | paths The list of resources which should be checked when checking for
modifications. | protected String[] | repositories The list of local repositories, in the order they should be searched
for locally loaded classes or resources. | protected ArrayList | required The set of optional packages (formerly standard extensions) that
are required in the repositories associated with this class loader. | protected HashMap | resourceEntries The cache of ResourceEntry for classes and resources we have loaded,
keyed by resource name. | protected DirContext | resources Associated directory context giving access to the resources in this
webapp. | protected boolean | started |
Constructor Summary | |
public | WebappClassLoader() Construct a new ClassLoader with no defined repositories and no
parent ClassLoader. | public | WebappClassLoader(ClassLoader parent) Construct a new ClassLoader with no defined repositories and no
parent ClassLoader. |
Method Summary | |
synchronized void | addJar(String jar, JarFile jarFile, File file) | public void | addLifecycleListener(LifecycleListener listener) Add a lifecycle event listener to this component. | public void | addPermission(String path) If there is a Java SecurityManager create a read FilePermission
or JndiPermission for the file directory path. | public void | addPermission(URL url) If there is a Java SecurityManager create a read FilePermission
or JndiPermission for URL. | public void | addPermission(Permission permission) If there is a Java SecurityManager create a Permission. | public void | addRepository(String repository) Add a new repository to the set of places this ClassLoader can look for
classes to be loaded. | synchronized void | addRepository(String repository, File file) Add a new repository to the set of places this ClassLoader can look for
classes to be loaded. | protected boolean | filter(String name) Filter classes. | 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. | public Class | findClass(String name) Find the specified class in our local repositories, if possible. | protected Class | findClassInternal(String name) Find specified class in local repositories. | public LifecycleListener[] | findLifecycleListeners() Get the lifecycle listeners associated with this lifecycle. | protected Class | findLoadedClass0(String name) Finds the class with the given name if it has previously been
loaded and cached by this class loader, and return the Class object. | protected InputStream | findLoadedResource(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. | public String[] | findRepositories() Return a String array of the current repositories for this class
loader. | 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. | public URL | findResource(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. | protected ResourceEntry | findResourceInternal(String name, String path) Find specified resource in local repositories. | public Enumeration | findResources(String name) Return an enumeration of URLs representing all of the
resources with the given name. | public int | getDebug() Return the debugging detail level for this component. | public boolean | getDelegate() Return the "delegate first" flag for this class loader. | public String | getJarPath() Return the JAR path. | protected PermissionCollection | getPermissions(CodeSource codeSource) Get the Permissions for a CodeSource. | public URL | getResource(String name) Find the resource with the given name. | public InputStream | getResourceAsStream(String name) Find the resource with the given name, and return an input stream
that can be used for reading it. | public DirContext | getResources() Get associated resources. | protected URL | getURL(File file) Get URL. | public URL[] | getURLs() Returns the search path of URLs for loading classes and resources. | protected boolean | isPackageSealed(String name, Manifest man) Returns true if the specified package name is sealed according to the
given manifest. | public Class | loadClass(String name) Load the class with the specified name. | public Class | loadClass(String name, boolean resolve) Load the class with the specified name, searching using the following
algorithm until it finds and returns the class. | public boolean | modified() | protected void | refreshPolicy() Refresh the system policy file, to pick up eventual changes. | public void | removeLifecycleListener(LifecycleListener listener) Remove a lifecycle event listener from this component. | public void | setDebug(int debug) Set the debugging detail level for this component. | public void | setDelegate(boolean delegate) Set the "delegate first" flag for this class loader. | public void | setJarPath(String jarPath) Change the Jar path. | public void | setResources(DirContext resources) Set associated resources. | public void | start() Start the class loader. | public void | stop() Stop the class loader. | public String | toString() Render a String representation of this object. | protected boolean | validate(String name) Validate a classname. |
available | protected ArrayList available(Code) | | 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 .
|
debug | protected int debug(Code) | | The debugging detail level of this component.
|
delegate | protected boolean delegate(Code) | | 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.
|
files | protected File[] files(Code) | | Repositories translated as path in the work directory (for Jasper
originally), but which is used to generate fake URLs should getURLs be
called.
|
hasExternalRepositories | protected boolean hasExternalRepositories(Code) | | Has external repositories.
|
jarFiles | protected JarFile[] jarFiles(Code) | | The list of JARs, in the order they should be searched
for locally loaded classes or resources.
|
jarNames | protected String[] jarNames(Code) | | The list of JARs, in the order they should be searched
for locally loaded classes or resources.
|
jarPath | protected String jarPath(Code) | | The path which will be monitored for added Jar files.
|
jarRealFiles | protected File[] jarRealFiles(Code) | | The list of JARs, in the order they should be searched
for locally loaded classes or resources.
|
lastModifiedDates | protected long[] lastModifiedDates(Code) | | The list of JARs last modified dates, in the order they should be
searched for locally loaded classes or resources.
|
notFoundResources | protected HashMap notFoundResources(Code) | | The list of not found resources.
|
paths | protected String[] paths(Code) | | The list of resources which should be checked when checking for
modifications.
|
repositories | protected String[] repositories(Code) | | The list of local repositories, in the order they should be searched
for locally loaded classes or resources.
|
required | protected ArrayList required(Code) | | 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 .
|
resourceEntries | protected HashMap resourceEntries(Code) | | The cache of ResourceEntry for classes and resources we have loaded,
keyed by resource name.
|
resources | protected DirContext resources(Code) | | Associated directory context giving access to the resources in this
webapp.
|
started | protected boolean started(Code) | | Has this component been started?
|
WebappClassLoader | public WebappClassLoader()(Code) | | Construct a new ClassLoader with no defined repositories and no
parent ClassLoader.
|
WebappClassLoader | public WebappClassLoader(ClassLoader parent)(Code) | | Construct a new ClassLoader with no defined repositories and no
parent ClassLoader.
|
addLifecycleListener | public void addLifecycleListener(LifecycleListener listener)(Code) | | Add a lifecycle event listener to this component.
Parameters: listener - The listener to add |
addPermission | public void addPermission(String path)(Code) | | If there is a Java SecurityManager create a read FilePermission
or JndiPermission for the file directory path.
Parameters: path - file directory path |
addPermission | public void addPermission(URL url)(Code) | | If there is a Java SecurityManager create a read FilePermission
or JndiPermission for URL.
Parameters: url - URL for a file or directory on local system |
addPermission | public void addPermission(Permission permission)(Code) | | If there is a Java SecurityManager create a Permission.
Parameters: url - URL for a file or directory on local system |
addRepository | public void addRepository(String repository)(Code) | | Add a new repository to the set of places this ClassLoader can look for
classes to be loaded.
Parameters: repository - Name of a source of classes to be loaded, such as adirectory pathname, a JAR file pathname, or a ZIP file pathname exception: IllegalArgumentException - if the specified repository isinvalid or does not exist |
addRepository | synchronized void addRepository(String repository, File file)(Code) | | Add a new repository to the set of places this ClassLoader can look for
classes to be loaded.
Parameters: repository - Name of a source of classes to be loaded, such as adirectory pathname, a JAR file pathname, or a ZIP file pathname exception: IllegalArgumentException - if the specified repository isinvalid or does not exist |
filter | protected boolean filter(String name)(Code) | | Filter classes.
Parameters: name - class name true if the class should be filtered |
findAvailable | public Extension[] findAvailable()(Code) | | 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.
|
findLifecycleListeners | public LifecycleListener[] findLifecycleListeners()(Code) | | Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned.
|
findLoadedClass0 | protected Class findLoadedClass0(String name)(Code) | | Finds the class with the given name if it has previously been
loaded and cached by this class loader, and return the Class object.
If this class has not been cached, return null .
Parameters: name - Name of the resource to return |
findLoadedResource | protected InputStream findLoadedResource(String name)(Code) | | 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 |
findRepositories | public String[] findRepositories()(Code) | | Return a String array of the current repositories for this class
loader. If there are no repositories, a zero-length array is
returned.
|
findRequired | public Extension[] findRequired()(Code) | | 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.
|
findResource | public URL findResource(String name)(Code) | | Find the specified resource in our local repository, and return a
URL refering to it, or null if this resource
cannot be found.
Parameters: name - Name of the resource to be found |
findResourceInternal | protected ResourceEntry findResourceInternal(String name, String path)(Code) | | Find specified resource in local repositories.
the loaded resource, or null if the resource isn't found |
findResources | public Enumeration findResources(String name) throws IOException(Code) | | 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.
Parameters: name - Name of the resources to be found exception: IOException - if an input/output error occurs |
getDebug | public int getDebug()(Code) | | Return the debugging detail level for this component.
|
getDelegate | public boolean getDelegate()(Code) | | Return the "delegate first" flag for this class loader.
|
getJarPath | public String getJarPath()(Code) | | Return the JAR path.
|
getPermissions | protected PermissionCollection getPermissions(CodeSource codeSource)(Code) | | Get the Permissions for a CodeSource. If this instance
of WebappClassLoader is for a web application context,
add read FilePermission or JndiPermissions for the base
directory (if unpacked),
the context URL, and jar file resources.
Parameters: CodeSource - where the code was loaded from PermissionCollection for CodeSource |
getResource | public URL getResource(String name)(Code) | | 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 .
- If the
delegate property is set to true ,
call the getResource() method of the parent class
loader, if any.
- Call
findResource() to find this resource in our
locally defined repositories.
- Call the
getResource() method of the parent class
loader, if any.
Parameters: name - Name of the resource to return a URL for |
getResourceAsStream | public InputStream getResourceAsStream(String name)(Code) | | 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 .
Parameters: name - Name of the resource to return an input stream for |
getURLs | public URL[] getURLs()(Code) | | Returns the search path of URLs for loading classes and resources.
This includes the original list of URLs specified to the constructor,
along with any URLs subsequently appended by the addURL() method.
the search path of URLs for loading classes and resources. |
isPackageSealed | protected boolean isPackageSealed(String name, Manifest man)(Code) | | Returns true if the specified package name is sealed according to the
given manifest.
|
loadClass | public Class loadClass(String name) throws ClassNotFoundException(Code) | | 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.
Parameters: name - Name of the class to be loaded exception: ClassNotFoundException - if the class was not found |
loadClass | public Class loadClass(String name, boolean resolve) throws ClassNotFoundException(Code) | | 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 .
- Call
findLoadedClass(String) to check if the
class has already been loaded. If it has, the same
Class object is returned.
- If the
delegate property is set to true ,
call the loadClass() method of the parent class
loader, if any.
- Call
findClass() to find this class in our locally
defined repositories.
- Call the
loadClass() method of our parent
class loader, if any.
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.
Parameters: name - Name of the class to be loaded Parameters: resolve - If true then resolve the class exception: ClassNotFoundException - if the class was not found |
modified | public boolean modified()(Code) | | Have one or more classes or resources been modified so that a reload
is appropriate?
|
refreshPolicy | protected void refreshPolicy()(Code) | | Refresh the system policy file, to pick up eventual changes.
|
removeLifecycleListener | public void removeLifecycleListener(LifecycleListener listener)(Code) | | Remove a lifecycle event listener from this component.
Parameters: listener - The listener to remove |
setDebug | public void setDebug(int debug)(Code) | | Set the debugging detail level for this component.
Parameters: debug - The new debugging detail level |
setDelegate | public void setDelegate(boolean delegate)(Code) | | Set the "delegate first" flag for this class loader.
Parameters: delegate - The new "delegate first" flag |
setJarPath | public void setJarPath(String jarPath)(Code) | | Change the Jar path.
|
setResources | public void setResources(DirContext resources)(Code) | | Set associated resources.
|
toString | public String toString()(Code) | | Render a String representation of this object.
|
validate | protected boolean validate(String name)(Code) | | Validate a classname. As per SRV.9.7.2, we must restict loading of
classes from J2SE (java.*) and classes of the servlet API
(javax.servlet.*). That should enhance robustness and prevent a number
of user error (where an older version of servlet.jar would be present
in /WEB-INF/lib).
Parameters: name - class name true if the name is valid |
|
|