public class StandardClassLoader extends URLClassLoader implements Reloader
Reloader interface, to provide
automatic reloading support to the associated loader.
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.
| Modifier and Type | Field and Description |
|---|---|
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 URLStreamHandlerFactory |
factory
URL stream handler for additional protocols.
|
protected ArrayList<String> |
repositories
The list of local repositories, in the order they should be searched
for locally loaded classes or resources.
|
| Constructor and Description |
|---|
StandardClassLoader()
Construct a new ClassLoader with no defined repositories and no
parent ClassLoader.
|
StandardClassLoader(ClassLoader parent)
Construct a new ClassLoader with no defined repositories and the
specified parent ClassLoader.
|
StandardClassLoader(ClassLoader parent,
URLStreamHandlerFactory factory)
Construct a new ClassLoader with no defined repositories and the
specified parent ClassLoader.
|
StandardClassLoader(String[] repositories)
Construct a new ClassLoader with the specified repositories and
no parent ClassLoader.
|
StandardClassLoader(String[] repositories,
ClassLoader parent)
Construct a new ClassLoader with the specified repositories and
parent ClassLoader.
|
StandardClassLoader(URL[] repositories)
Construct a new ClassLoader with the specified repositories and
no parent ClassLoader.
|
StandardClassLoader(URL[] repositories,
ClassLoader parent)
Construct a new ClassLoader with the specified repositories and
parent ClassLoader.
|
StandardClassLoader(URLStreamHandlerFactory factory)
Construct a new ClassLoader with no defined repositories and no
parent ClassLoader, but with a stream handler factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRepository(String repository)
Add a new repository to the set of places this ClassLoader can look for
classes to be loaded.
|
protected void |
addRepositoryInternal(String repository)
Add a repository to our internal array only.
|
protected static URL[] |
convert(String[] input)
Convert an array of String to an array of URL and return it.
|
protected static URL[] |
convert(String[] input,
URLStreamHandlerFactory factory)
Convert an array of String to an array of URL and return it.
|
Class |
findClass(String name)
Find the specified class in our local repositories, if possible.
|
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.
|
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. |
Enumeration<URL> |
findResources(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.
|
protected PermissionCollection |
getPermissions(CodeSource codeSource)
Get the Permissions for a CodeSource.
|
URL |
getResource(String name)
Find the resource with the given name.
|
InputStream |
getResourceAsStream(String name)
Find the resource with the given name, and return an input stream
that can be used for reading it.
|
Class |
loadClass(String name)
Load the class with the specified name.
|
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.
|
boolean |
modified()
This class loader doesn't check for reloading.
|
protected static String |
parseProtocol(String spec)
Parse URL protocol.
|
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.
|
protected void |
setPermissions(String path)
If there is a Java SecurityManager create a read FilePermission
or JndiPermission for the file directory path.
|
protected void |
setPermissions(URL url)
If there is a Java SecurityManager add a read FilePermission
or JndiPermission for URL.
|
String |
toString()
Render a String representation of this object.
|
addURL, close, definePackage, getURLs, newInstance, newInstancedefineClass, defineClassclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersprotected 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 ArrayList<String> repositories
protected URLStreamHandlerFactory factory
public StandardClassLoader()
public StandardClassLoader(URLStreamHandlerFactory factory)
factory - the URLStreamHandlerFactory to use when creating URLspublic StandardClassLoader(ClassLoader parent)
parent - The parent ClassLoaderpublic StandardClassLoader(ClassLoader parent, URLStreamHandlerFactory factory)
parent - The parent ClassLoaderfactory - the URLStreamHandlerFactory to use when creating URLspublic StandardClassLoader(String[] repositories)
repositories - The initial set of repositoriespublic StandardClassLoader(String[] repositories, ClassLoader parent)
repositories - The initial set of repositoriesparent - The parent ClassLoaderpublic StandardClassLoader(URL[] repositories)
repositories - The initial set of repositoriespublic StandardClassLoader(URL[] repositories, ClassLoader parent)
repositories - The initial set of repositoriesparent - The parent ClassLoaderpublic 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" flagprotected void setPermissions(String path)
path - file directory pathprotected void setPermissions(URL url)
url - URL for a file or directory on local systempublic void addRepository(String repository)
addRepository in interface Reloaderrepository - Name of a source of classes to be loaded, such as a
directory pathname, a JAR file pathname, or a ZIP file pathnameIllegalArgumentException - if the specified repository is
invalid or does not existpublic boolean modified()
public String toString()
public Class findClass(String name) throws ClassNotFoundException
ClassNotFoundException.findClass in class URLClassLoadername - Name of the class to be loadedClassNotFoundException - if the class was not foundpublic URL findResource(String name)
URL refering to it, or null if this resource
cannot be found.findResource in class URLClassLoadername - Name of the resource to be foundpublic Enumeration<URL> findResources(String name) throws 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 URLClassLoadername - Name of the resources to be foundIOException - if an input/output error occurspublic URL getResource(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 ClassLoadername - Name of the resource to return a URL forpublic InputStream getResourceAsStream(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 URLClassLoadername - Name of the resource to return an input stream forpublic Class loadClass(String name) throws ClassNotFoundException
loadClass(String, boolean)
with false as the second argument.loadClass in class ClassLoadername - Name of the class to be loadedClassNotFoundException - if the class was not foundpublic Class loadClass(String name, boolean resolve) throws 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 ClassLoadername - Name of the class to be loadedresolve - If true then resolve the classClassNotFoundException - if the class was not foundprotected final PermissionCollection getPermissions(CodeSource codeSource)
getPermissions in class URLClassLoadercodeSource - where the code was loaded fromprotected static String parseProtocol(String spec)
protected void addRepositoryInternal(String repository)
repository - The new repositoryIllegalArgumentException - if the manifest of a JAR file
cannot be processed correctlyprotected static URL[] convert(String[] input)
input - The array of String to be convertedprotected static URL[] convert(String[] input, URLStreamHandlerFactory factory)
input - The array of String to be convertedfactory - Handler factory to use to generate the URLsprotected InputStream findLoadedResource(String name)
null.name - Name of the resource to returnCopyright © 2019. All rights reserved.