|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ClassLoader | +--java.security.SecureClassLoader | +--java.net.URLClassLoader | +--org.apache.catalina.loader.WebappClassLoader
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.
Nested Class Summary | |
protected class |
WebappClassLoader.PrivilegedFindResource
|
protected static class |
WebappClassLoader.ResourceEntry
Resource entry. |
Field Summary | |
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 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. the usual Java2 delegation model)? |
protected java.io.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 java.util.jar.JarFile[] |
jarFiles
The list of JARs, in the order they should be searched for locally loaded classes or resources. |
protected java.lang.String[] |
jarNames
The list of JARs, in the order they should be searched for locally loaded classes or resources. |
protected java.lang.String |
jarPath
The path which will be monitored for added Jar files. |
protected java.io.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 java.util.HashMap |
notFoundResources
The list of not found resources. |
protected java.lang.String[] |
paths
The list of resources which should be checked when checking for modifications. |
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.util.HashMap |
resourceEntries
The cache of ResourceEntry for classes and resources we have loaded, keyed by resource name. |
protected javax.naming.directory.DirContext |
resources
Associated directory context giving access to the resources in this webapp. |
protected boolean |
started
Has this component been started? |
Fields inherited from interface org.apache.catalina.Lifecycle |
START_EVENT, STOP_EVENT |
Constructor Summary | |
WebappClassLoader(java.lang.ClassLoader parent,
javax.naming.directory.DirContext resources)
Construct a new ClassLoader with no defined repositories and no parent ClassLoader. |
|
WebappClassLoader(javax.naming.directory.DirContext resources)
Construct a new ClassLoader with no defined repositories and no parent ClassLoader. |
Method Summary | |
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component. |
void |
addPermission(java.security.Permission permission)
If there is a Java SecurityManager create a Permission. |
void |
addPermission(java.lang.String path)
If there is a Java SecurityManager create a read FilePermission or JndiPermission for the file directory path. |
void |
addPermission(java.net.URL url)
If there is a Java SecurityManager create a read FilePermission or JndiPermission for URL. |
void |
addRepository(java.lang.String repository)
Add a new repository to the set of places this ClassLoader can look for classes to be loaded. |
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.lang.Class |
findClassInternal(java.lang.String name)
Find specified class in local repositories. |
LifecycleListener[] |
findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. |
protected java.lang.Class |
findLoadedClass0(java.lang.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 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. |
protected WebappClassLoader.ResourceEntry |
findResourceInternal(java.lang.String name,
java.lang.String path)
Find specified resource in local repositories. |
java.util.Enumeration |
findResources(java.lang.String name)
Return an enumeration of URLs representing all of the
resources with the given name. |
int |
getDebug()
Return the debugging detail level for this component. |
boolean |
getDelegate()
Return the "delegate first" flag for this class loader. |
java.lang.String |
getJarPath()
Return the JAR path. |
protected java.security.PermissionCollection |
getPermissions(java.security.CodeSource codeSource)
Get the Permissions for a CodeSource. |
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. |
protected java.net.URL |
getURL(java.io.File file)
Get URL. |
java.net.URL[] |
getURLs()
Returns the search path of URLs for loading classes and resources. |
protected boolean |
isPackageSealed(java.lang.String name,
java.util.jar.Manifest man)
Returns true if the specified package name is sealed according to the given manifest. |
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? |
protected void |
refreshPolicy()
Refresh the system policy file, to pick up eventual changes. |
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component. |
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. |
void |
setJarPath(java.lang.String jarPath)
Change the Jar path. |
void |
start()
Start the class loader. |
void |
stop()
Stop the class loader. |
java.lang.String |
toString()
Render a String representation of this object. |
protected boolean |
validate(java.lang.String name)
Validate a classname. |
Methods inherited from class java.net.URLClassLoader |
addURL, definePackage, newInstance, newInstance |
Methods inherited from class java.security.SecureClassLoader |
defineClass |
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected javax.naming.directory.DirContext resources
protected java.util.ArrayList available
org.apache.catalina.loader.Extension
.
protected java.util.HashMap resourceEntries
protected java.util.HashMap notFoundResources
protected int debug
protected boolean delegate
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.
protected java.lang.String[] repositories
protected java.io.File[] files
protected java.util.jar.JarFile[] jarFiles
protected java.io.File[] jarRealFiles
protected java.lang.String jarPath
protected java.lang.String[] jarNames
protected long[] lastModifiedDates
protected java.lang.String[] paths
protected java.util.ArrayList required
org.apache.catalina.loader.Extension
.
protected boolean started
protected boolean hasExternalRepositories
Constructor Detail |
public WebappClassLoader(javax.naming.directory.DirContext resources)
public WebappClassLoader(java.lang.ClassLoader parent, javax.naming.directory.DirContext resources)
Method Detail |
public int getDebug()
public void setDebug(int debug)
debug
- The new debugging detail levelpublic boolean getDelegate()
public void setDelegate(boolean delegate)
delegate
- The new "delegate first" flagpublic void addPermission(java.lang.String path)
path
- file directory pathpublic void addPermission(java.net.URL url)
url
- URL for a file or directory on local systempublic void addPermission(java.security.Permission permission)
public java.lang.String getJarPath()
public void setJarPath(java.lang.String jarPath)
public void addRepository(java.lang.String repository)
addRepository
in interface Reloader
repository
- Name of a source of classes to be loaded, such as a
directory pathname, a JAR file pathname, or a ZIP file pathname
java.lang.IllegalArgumentException
- if the specified repository is
invalid or does not existpublic Extension[] findAvailable()
public java.lang.String[] findRepositories()
findRepositories
in interface Reloader
public Extension[] findRequired()
public boolean modified()
modified
in interface Reloader
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
ClassNotFoundException
.
findClass
in class java.net.URLClassLoader
name
- Name of the class to be loaded
java.lang.ClassNotFoundException
- if the class was not foundpublic java.net.URL findResource(java.lang.String name)
URL
refering to it, or null
if this resource
cannot be found.
findResource
in class java.net.URLClassLoader
name
- Name of the resource to be foundpublic java.util.Enumeration findResources(java.lang.String name) throws java.io.IOException
URLs
representing all of the
resources with the given name. If no resources with this name are
found, return an empty enumeration.
findResources
in class java.net.URLClassLoader
name
- Name of the resources to be found
java.io.IOException
- if an input/output error occurspublic java.net.URL getResource(java.lang.String name)
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
.
delegate
property is set to true
,
call the getResource()
method of the parent class
loader, if any.findResource()
to find this resource in our
locally defined repositories.getResource()
method of the parent class
loader, if any.
getResource
in class java.lang.ClassLoader
name
- Name of the resource to return a URL forpublic java.io.InputStream getResourceAsStream(java.lang.String name)
getResource()
, after checking to see if the resource
data has been previously cached. If the resource cannot be found,
return null
.
getResourceAsStream
in class java.lang.ClassLoader
name
- Name of the resource to return an input stream forpublic java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
loadClass(String, boolean)
with false
as the second argument.
loadClass
in class java.lang.ClassLoader
name
- Name of the class to be loaded
java.lang.ClassNotFoundException
- if the class was not foundpublic java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
ClassNotFoundException
.
findLoadedClass(String)
to check if the
class has already been loaded. If it has, the same
Class
object is returned.delegate
property is set to true
,
call the loadClass()
method of the parent class
loader, if any.findClass()
to find this class in our locally
defined repositories.loadClass()
method of our parent
class loader, if any.resolve
flag is true
, this method will then
call resolveClass(Class)
on the resulting Class object.
loadClass
in class java.lang.ClassLoader
name
- Name of the class to be loadedresolve
- If true
then resolve the class
java.lang.ClassNotFoundException
- if the class was not foundprotected java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)
getPermissions
in class java.net.URLClassLoader
public java.net.URL[] getURLs()
getURLs
in class java.net.URLClassLoader
public void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic LifecycleListener[] findLifecycleListeners()
public void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in interface Lifecycle
listener
- The listener to removepublic void start() throws LifecycleException
start
in interface Lifecycle
LifecycleException
- if a lifecycle error occurspublic void stop() throws LifecycleException
stop
in interface Lifecycle
LifecycleException
- if a lifecycle error occursprotected java.lang.Class findClassInternal(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
protected WebappClassLoader.ResourceEntry findResourceInternal(java.lang.String name, java.lang.String path)
protected boolean isPackageSealed(java.lang.String name, java.util.jar.Manifest man)
protected java.io.InputStream findLoadedResource(java.lang.String name)
null
.
name
- Name of the resource to returnprotected java.lang.Class findLoadedClass0(java.lang.String name)
null
.
name
- Name of the resource to returnprotected void refreshPolicy()
protected boolean validate(java.lang.String name)
name
- class name
protected java.net.URL getURL(java.io.File file) throws java.net.MalformedURLException
java.net.MalformedURLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |