Specializes URLClassLoader with some utility and file mapping methods.
This loader defaults to the 2.3 servlet spec behavior where non
system classes are loaded from the classpath in preference to the
parent loader. Java2 compliant loading, where the parent loader
always has priority, can be selected with the
WebAppContext#setParentLoaderPriority(boolean)
method and influenced with WebAppContext#isServerClass(Class) and
WebAppContext#isSystemClass(Class).
If no parent class loader is provided, then the current thread context classloader will be used. If that is null then the classloader that loaded this class is used as the parent.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | WebAppClassLoader.Context
The Context in which the classloader operates. |
| Modifier and Type | Field and Description |
|---|---|
| private static final ThreadLocal | |
| private final WebAppClassLoader. | |
| private final Set | |
| private String | |
| private final ClassLoader | |
| private final ResourceFactory. | |
| private final List | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | |
| public | WebAppClassLoader(ClassLoader
the parent classloader parent, WebAppClassLoader.the context for this classloader contextConstructor. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | addClassPath(String
Comma or semicolon separated path of filenames or URLs
pointing to directories or jar files. Directories should end
with '/'. classPathList)
|
| public void | |
| public void | |
| public void | close()
Overrides java. Implements java. |
| protected Class | findClass(final String
the name of the class name)Overrides java. |
| protected Class | |
| public WebAppClassLoader. | |
| public String | Returns: the name of the classloaderOverrides java. |
| public PermissionCollection | getPermissions(CodeSource
the codesource cs)Overrides java. |
| public URL | getResource(String
The resource name name)Overrides java. |
| public Enumeration | getResources(String
The resource name name)Overrides java. |
| private boolean | |
| private boolean | |
| public boolean | isServerClass(Class<?>
The fully qualified name of the class. clazz)Implements org. |
| public boolean | isSystemClass(Class<?>
The fully qualified name of the class. clazz)Implements org. |
| protected Class | Returns: the loaded classthe name of the class to load name, boolean if true and the class isn't a system class we return it checkSystemResource)Look for the classname as a resource to avoid loading a class that is potentially a system resource. |
| protected Class | loadClass(String
The binary name of the class name, boolean If resolve)true then resolve the classOverrides java. |
| public boolean | |
| public static < The type returned by the action T> T | Returns: The return from the actionThe action to run action)Run an action with access to ServerClasses Run the passed |
| public void | |
| public String |
| __loadServerClasses | back to summary |
|---|---|
| private static final ThreadLocal<Boolean> __loadServerClasses | |
| _context | back to summary |
|---|---|
| private final WebAppClassLoader. | |
| _extensions | back to summary |
|---|---|
| private final Set<String> _extensions | |
| _name | back to summary |
|---|---|
| private String _name | |
| _parent | back to summary |
|---|---|
| private final ClassLoader _parent | |
| _resourceFactory | back to summary |
|---|---|
| private final ResourceFactory. | |
| _transformers | back to summary |
|---|---|
| private final List<ClassFileTransformer> _transformers | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| WebAppClassLoader | back to summary |
|---|---|
| public WebAppClassLoader(WebAppClassLoader. Constructor.
| |
| WebAppClassLoader | back to summary |
|---|---|
| public WebAppClassLoader(ClassLoader parent, WebAppClassLoader. Constructor.
| |
| addClassPath | back to summary |
|---|---|
public void addClassPath(Resource resource)
| |
| addClassPath | back to summary |
|---|---|
public void addClassPath(String classPathList) throws IOException
| |
| addJars | back to summary |
|---|---|
| public void addJars(Resource libs) Add elements to the class path for the context from the jar and zip files found in the specified resource.
| |
| addTransformer | back to summary |
|---|---|
| public void addTransformer(ClassFileTransformer transformer) | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this URLClassLoader, so that it can no longer be used to load new classes or resources that are defined by this loader. Classes and resources defined by any of this loader's parents in the delegation hierarchy are still accessible. Also, any classes or resources that are already loaded, are still accessible.
In the case of jar: and file: URLs, it also closes any files
that were opened by it. If another thread is loading a
class when the
The method makes a best effort attempt to close all opened files,
by catching
| |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.
| |
| foundClass | back to summary |
|---|---|
| protected Class | |
| getContext | back to summary |
|---|---|
| public WebAppClassLoader. | |
| getName | back to summary |
|---|---|
| public String getName() Overrides java. Get the name of the classloader.
| |
| getPermissions | back to summary |
|---|---|
| public PermissionCollection getPermissions(CodeSource cs) Overrides java. Doc from java. Returns the permissions for the given codesource object. The implementation of this method first calls super.getPermissions and then adds permissions based on the URL of the codesource. If the protocol of this URL is "jar", then the permission granted is based on the permission that is required by the URL of the Jar file. If the protocol is "file" and there is an authority component, then permission to connect to and accept connections from that authority may be granted. If the protocol is "file" and the path specifies a file, then permission to read that file is granted. If protocol is "file" and the path is a directory, permission is granted to read all files and (recursively) all files and subdirectories contained in that directory. If the protocol is not "file", then permission to connect to and accept connections from the URL's host is granted.
| |
| getResource | back to summary |
|---|---|
| public URL getResource(String name) Overrides java. Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present. This is non-standard and it is recommended to not rely on this behavior
| |
| getResources | back to summary |
|---|---|
| public Enumeration Overrides java. Doc from java. Finds all the resources 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 Resources in named modules are subject to the encapsulation rules
specified by
| |
| isFileSupported | back to summary |
|---|---|
private boolean isFileSupported(String file)
| |
| isFileSupported | back to summary |
|---|---|
| private boolean isFileSupported(Path path) | |
| isServerClass | back to summary |
|---|---|
| public boolean isServerClass(Class<?> clazz) Implements org. Doc from org. Is the class a Server Class. A Server class is a class that is part of the implementation of the server and is NIT visible to a webapplication. The web application may provide it's own implementation of the class, to be loaded from WEB-INF/lib or WEB-INF/classes | |
| isSystemClass | back to summary |
|---|---|
| public boolean isSystemClass(Class<?> clazz) Implements org. Doc from org. Is the class a System Class. A System class is a class that is visible to a webapplication, but that cannot be overridden by the contents of WEB-INF/lib or WEB-INF/classes | |
| loadAsResource | back to summary |
|---|---|
| protected Class Look for the classname as a resource to avoid loading a class that is potentially a system resource.
| |
| loadClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:
If the class was found using the above steps, and the
Subclasses of Unless overridden, this method synchronizes on the result of
| |
| removeTransformer | back to summary |
|---|---|
| public boolean removeTransformer(ClassFileTransformer transformer) | |
| runWithServerClassAccess | back to summary |
|---|---|
| public static <T> T runWithServerClassAccess(PrivilegedExceptionAction<T> action) throws Exception Run an action with access to ServerClasses Run the passed
| |
| setName | back to summary |
|---|---|
| public void setName(String name) Set the name of the classloader.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Method and Description |
|---|---|
| public List | |
| public PermissionCollection | |
| public boolean | Returns: True if the classloader should delegate first to the parent classloader (standard java behaviour) or false if the classloader should first try to load from WEB-INF/lib or WEB-INF/classes (servlet spec recommendation).
|
| public boolean | |
| public boolean | |
| public Resource | Returns: The Resource for the URL/pathThe URL or path to convert urlOrPath)Convert a URL or path to a Resource. |
| getExtraClasspath | back to summary |
|---|---|
| public List | |
| getPermissions | back to summary |
|---|---|
public PermissionCollection getPermissions()
| |
| isParentLoaderPriority | back to summary |
|---|---|
public boolean isParentLoaderPriority()
| |
| isServerResource | back to summary |
|---|---|
| public boolean isServerResource(String name, URL parentUrl) | |
| isSystemResource | back to summary |
|---|---|
| public boolean isSystemResource(String name, URL webappUrl) | |
| newResource | back to summary |
|---|---|
| public Resource newResource(String urlOrPath) throws IOException Convert a URL or path to a Resource.
The default implementation
is a wrapper for
| |