public abstract class WebappClassLoaderBase extends java.net.URLClassLoader implements Lifecycle, InstrumentableClassLoader, WebappProperties, PermissionCheck
This class loader is a full reimplementation of the URLClassLoader from the JDK. It is designed to be
fully compatible with a normal URLClassLoader, although its internal behavior may be completely
different.
IMPLEMENTATION NOTE - By default, this class loader follows the delegation model required by the
specification. The bootstrap 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 repositories. The delegate property
allows an application to modify this behavior to move the parent class loader ahead of the local repositories.
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.
IMPLEMENTATION NOTE - No check for sealing violations or security is made unless a security manager is present.
IMPLEMENTATION NOTE - As of 8.0, this class loader implements InstrumentableClassLoader,
permitting web application classes to instrument other classes in the same web application. It does not permit
instrumentation of system or container classes or classes in other web apps.
| Modifier and Type | Class and Description |
|---|---|
protected class |
WebappClassLoaderBase.PrivilegedFindClassByName |
protected static class |
WebappClassLoaderBase.PrivilegedGetClassLoader |
protected class |
WebappClassLoaderBase.PrivilegedJavaseGetResource |
Lifecycle.SingleUse| Modifier and Type | Field and Description |
|---|---|
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.util.HashMap<java.lang.String,java.security.PermissionCollection> |
loaderPC
The PermissionCollection for each CodeSource for a web application context.
|
protected java.lang.ClassLoader |
parent
The parent class loader.
|
protected java.util.ArrayList<java.security.Permission> |
permissionList
A list of read File Permission's required if this loader is for a web application context.
|
protected java.util.Map<java.lang.String,ResourceEntry> |
resourceEntries
The cache of ResourceEntry for classes and resources we have loaded, keyed by resource path, not binary name.
|
protected WebResourceRoot |
resources
Associated web resources for this webapp.
|
protected java.lang.SecurityManager |
securityManager
Instance of the SecurityManager installed.
|
protected static StringManager |
sm
The string manager for this package.
|
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT| Modifier | Constructor and Description |
|---|---|
protected |
WebappClassLoaderBase()
Construct a new ClassLoader with no defined repositories and no parent ClassLoader.
|
protected |
WebappClassLoaderBase(java.lang.ClassLoader parent)
Construct a new ClassLoader with no defined repositories and the given parent ClassLoader.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
|
void |
addTransformer(java.lang.instrument.ClassFileTransformer transformer)
Adds the specified class file transformer to this class loader.
|
protected void |
addURL(java.net.URL url) |
boolean |
check(java.security.Permission permission)
Does this component have the given permission?
|
protected void |
checkStateForClassLoading(java.lang.String className) |
protected void |
checkStateForResourceLoading(java.lang.String resource) |
protected void |
clearReferences()
Clear references.
|
protected void |
copyStateWithoutTransformers(WebappClassLoaderBase base) |
void |
destroy()
Prepare to discard the object.
|
protected java.lang.Class<?> |
doDefineClass(java.lang.String name,
byte[] b,
int off,
int len,
java.security.ProtectionDomain protectionDomain) |
protected boolean |
filter(java.lang.String name,
boolean isClassName)
Filter classes.
|
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.
|
java.net.URL |
findResource(java.lang.String name)
Find the specified resource in our local repository, and return a
URL referring to it, or
null if this resource cannot be found. |
java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name)
Return an enumeration of
URLs representing all of the resources with the given name. |
boolean |
getClearReferencesHttpClientKeepAliveThread() |
boolean |
getClearReferencesLogFactoryRelease() |
boolean |
getClearReferencesObjectStreamClassCaches() |
boolean |
getClearReferencesRmiTargets() |
boolean |
getClearReferencesStopThreads() |
boolean |
getClearReferencesStopTimerThreads() |
boolean |
getClearReferencesThreadLocals() |
java.lang.String |
getContextName() |
boolean |
getDelegate()
Return the "delegate first" flag for this class loader.
|
java.lang.String |
getHostName()
Returns a name for the logging system to use for the Host where the web application, if any, associated with the
class loader is deployed.
|
protected java.lang.ClassLoader |
getJavaseClassLoader() |
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.
|
WebResourceRoot |
getResources()
Deprecated.
This will be removed in Tomcat 10.1.x onwards
|
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name) |
java.lang.String |
getServiceName()
Returns a name for the logging system to use for the Service where the Host, if any, associated with the class
loader is deployed.
|
boolean |
getSkipMemoryLeakChecksOnJvmShutdown() |
LifecycleState |
getState()
Obtain the current state of the source component.
|
java.lang.String |
getStateName()
Obtain a textual representation of the current component state.
|
java.net.URL[] |
getURLs()
Note that list of URLs returned by this method may not be complete.
|
java.lang.String |
getWebappName()
Returns a name for the logging system to use for the web application, if any, associated with the class loader.
|
boolean |
hasLoggingConfig()
Enables JULI to determine if the web application includes a local configuration without JULI having to look for
the file which it may not have permission to do when running under a SecurityManager.
|
void |
init()
Prepare the component for starting.
|
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 |
removeTransformer(java.lang.instrument.ClassFileTransformer transformer)
Removes the specified class file transformer from this class loader.
|
void |
setClearReferencesHttpClientKeepAliveThread(boolean clearReferencesHttpClientKeepAliveThread)
Set the clearReferencesHttpClientKeepAliveThread feature for this Context.
|
void |
setClearReferencesLogFactoryRelease(boolean clearReferencesLogFactoryRelease)
Set the clearReferencesLogFactoryRelease feature for this Context.
|
void |
setClearReferencesObjectStreamClassCaches(boolean clearReferencesObjectStreamClassCaches) |
void |
setClearReferencesRmiTargets(boolean clearReferencesRmiTargets) |
void |
setClearReferencesStopThreads(boolean clearReferencesStopThreads)
Set the clearReferencesStopThreads feature for this Context.
|
void |
setClearReferencesStopTimerThreads(boolean clearReferencesStopTimerThreads)
Set the clearReferencesStopTimerThreads feature for this Context.
|
void |
setClearReferencesThreadLocals(boolean clearReferencesThreadLocals) |
void |
setDelegate(boolean delegate)
Set the "delegate first" flag for this class loader.
|
protected void |
setJavaseClassLoader(java.lang.ClassLoader classLoader) |
void |
setResources(WebResourceRoot resources)
Set associated resources.
|
void |
setSkipMemoryLeakChecksOnJvmShutdown(boolean skipMemoryLeakChecksOnJvmShutdown) |
void |
start()
Start the class loader.
|
void |
stop()
Stop the class loader.
|
java.lang.String |
toString() |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcopyWithoutTransformersprotected static final StringManager sm
protected WebResourceRoot resources
protected final java.util.Map<java.lang.String,ResourceEntry> resourceEntries
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. Note
that the default, false, is the behavior called for by the servlet specification.protected final java.util.ArrayList<java.security.Permission> permissionList
protected final java.util.HashMap<java.lang.String,java.security.PermissionCollection> loaderPC
protected final java.lang.SecurityManager securityManager
protected final java.lang.ClassLoader parent
protected WebappClassLoaderBase()
protected WebappClassLoaderBase(java.lang.ClassLoader parent)
Method is used via reflection - see WebappLoader.createClassLoader()
parent - Our parent class loader@Deprecated public WebResourceRoot getResources()
null.public void setResources(WebResourceRoot resources)
resources - the resources from which the classloader will load the classespublic java.lang.String getContextName()
public boolean getDelegate()
true if the class lookup will delegate to the parent first. The default in Tomcat is
false.public void setDelegate(boolean delegate)
false (the default), this class loader will search its own
repositories first, and delegate to the parent only if the class or resource is not found locally, as per the
servlet specification.delegate - The new "delegate first" flagpublic boolean getClearReferencesRmiTargets()
public void setClearReferencesRmiTargets(boolean clearReferencesRmiTargets)
public boolean getClearReferencesStopThreads()
public void setClearReferencesStopThreads(boolean clearReferencesStopThreads)
clearReferencesStopThreads - The new flag valuepublic boolean getClearReferencesStopTimerThreads()
public void setClearReferencesStopTimerThreads(boolean clearReferencesStopTimerThreads)
clearReferencesStopTimerThreads - The new flag valuepublic boolean getClearReferencesLogFactoryRelease()
public void setClearReferencesLogFactoryRelease(boolean clearReferencesLogFactoryRelease)
clearReferencesLogFactoryRelease - The new flag valuepublic boolean getClearReferencesHttpClientKeepAliveThread()
public void setClearReferencesHttpClientKeepAliveThread(boolean clearReferencesHttpClientKeepAliveThread)
clearReferencesHttpClientKeepAliveThread - The new flag valuepublic boolean getClearReferencesObjectStreamClassCaches()
public void setClearReferencesObjectStreamClassCaches(boolean clearReferencesObjectStreamClassCaches)
public boolean getClearReferencesThreadLocals()
public void setClearReferencesThreadLocals(boolean clearReferencesThreadLocals)
public boolean getSkipMemoryLeakChecksOnJvmShutdown()
public void setSkipMemoryLeakChecksOnJvmShutdown(boolean skipMemoryLeakChecksOnJvmShutdown)
public void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
addTransformer in interface InstrumentableClassLoadertransformer - The transformer to add to the class loaderpublic void removeTransformer(java.lang.instrument.ClassFileTransformer transformer)
removeTransformer in interface InstrumentableClassLoadertransformer - The transformer to removeprotected void copyStateWithoutTransformers(WebappClassLoaderBase base)
public boolean modified()
true if there's been a modificationpublic java.lang.String toString()
toString in class java.lang.Objectprotected final java.lang.Class<?> doDefineClass(java.lang.String name,
byte[] b,
int off,
int len,
java.security.ProtectionDomain protectionDomain)
public java.lang.Class<?> findClass(java.lang.String name)
throws java.lang.ClassNotFoundException
ClassNotFoundException.findClass in class java.net.URLClassLoadername - The binary name of the class to be loadedjava.lang.ClassNotFoundException - if the class was not foundpublic java.net.URL findResource(java.lang.String name)
URL referring to it, or
null if this resource cannot be found.findResource in class java.net.URLClassLoadername - Name of the resource to be foundpublic java.util.Enumeration<java.net.URL> 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.URLClassLoadername - Name of the resources to be foundjava.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.ClassLoadername - Name of the resource to return a URL forpublic java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
throws java.io.IOException
getResources in class java.lang.ClassLoaderjava.io.IOExceptionpublic 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.net.URLClassLoadername - 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.ClassLoadername - The binary name of the class to be loadedjava.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.ClassLoadername - The binary name of the class to be loadedresolve - If true then resolve the classjava.lang.ClassNotFoundException - if the class was not foundprotected void checkStateForClassLoading(java.lang.String className)
throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundExceptionprotected void checkStateForResourceLoading(java.lang.String resource)
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionprotected java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)
getPermissions in class java.net.URLClassLoadercodeSource - where the code was loaded frompublic boolean check(java.security.Permission permission)
PermissionCheckcheck in interface PermissionCheckpermission - The permission to testfalse if a SecurityManager is enabled and the component
does not have the given permission, otherwise truepublic java.net.URL[] getURLs()
Note that list of URLs returned by this method may not be complete. The web application class loader accesses
class loader resources via the WebResourceRoot which supports the arbitrary mapping of additional files,
directories and contents of JAR files under WEB-INF/classes. Any such resources will not be included in the URLs
returned here.
getURLs in class java.net.URLClassLoaderpublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener in interface Lifecyclelistener - The listener to addpublic LifecycleListener[] findLifecycleListeners()
findLifecycleListeners in interface Lifecyclepublic void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener in interface Lifecyclelistener - The listener to removepublic LifecycleState getState()
public java.lang.String getStateName()
LifecycleLifecycle.getState().getStateName in interface Lifecyclepublic void init()
LifecycleLifecycleEvents will be fired in the following order:
public void start()
throws LifecycleException
start in interface LifecycleLifecycleException - if a lifecycle error occurspublic void stop()
throws LifecycleException
stop in interface LifecycleLifecycleException - if a lifecycle error occurspublic void destroy()
LifecycleLifecycleEvents will
be fired in the following order:
protected java.lang.ClassLoader getJavaseClassLoader()
protected void setJavaseClassLoader(java.lang.ClassLoader classLoader)
protected void clearReferences()
protected java.lang.Class<?> findClassInternal(java.lang.String name)
name - The binary name of the class to be loadedprotected boolean isPackageSealed(java.lang.String name,
java.util.jar.Manifest man)
name - Path name to checkman - Associated manifesttrue if the manifest associated says it is sealedprotected java.lang.Class<?> findLoadedClass0(java.lang.String name)
null.name - The binary name of the resource to returnprotected void refreshPolicy()
protected boolean filter(java.lang.String name,
boolean isClassName)
name - class nameisClassName - true if name is a class name, false if name is a resource nametrue if the class should be filteredprotected void addURL(java.net.URL url)
addURL in class java.net.URLClassLoaderpublic java.lang.String getWebappName()
WebappPropertiesgetWebappName in interface WebappPropertiespublic java.lang.String getHostName()
WebappPropertiesgetHostName in interface WebappPropertiespublic java.lang.String getServiceName()
WebappPropertiesgetServiceName in interface WebappPropertiespublic boolean hasLoggingConfig()
WebappPropertieshasLoggingConfig in interface WebappPropertiestrue if the web application includes a logging configuration at the standard location of
/WEB-INF/classes/logging.properties.Copyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.