|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ClassLoader | +--org.apache.catalina.loader.FileClassLoader
Implementation of java.lang.ClassLoader that knows how to load
classes from disk directories and JAR files. It also implements
the Reloader
interface, to provide automatic reloading
support to StandardLoader
.
This code was partially based on the AdaptiveClassLoader
module originally copied from Apache JServ, and used in Tomcat 3.x.
However, it does class loading in a different order (webapp first then
system classes), and allows the set of associated repositories to be
modified at runtime.
Besides the usual functions of loading and caching the bytecodes for
requested classes, this class loader also supports optional in-memory
caching of resources acquired via getResourceAsStream()
.
Because most applications probably read their resource files only once
(during initialization), this is disabled by default, but it can be
enabled by setting the maxCount
, maxSize
,
and minSize
properties.
Constructor Summary | |
FileClassLoader()
Construct a new ClassLoader instance with no defined repositories and no parent ClassLoader. |
|
FileClassLoader(java.lang.ClassLoader parent)
Construct a new ClassLoader instance with no defined repositories and the specified parent ClassLoader. |
|
FileClassLoader(java.lang.ClassLoader parent,
java.lang.String[] respositories)
Construct a new ClassLoader instance with the specified repositories and parent ClassLoader. |
|
FileClassLoader(java.lang.String[] repositories)
Construct a new ClassLoader instance with the specified repositories and no parent ClassLoader. |
Method Summary | |
void |
addAllowed(java.lang.String name)
Add a new fully qualified class or resource name to which access will be allowed, even if the class or resource name would otherwise match one of the restricted patterns. |
void |
addRepository(java.lang.String repository)
Add a new repository to the set of places this ClassLoader can look for classes to be loaded. |
void |
addRestricted(java.lang.String prefix)
Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to fail (unless the complete name is on the allowed list). |
void |
addSystem(java.lang.String prefix)
Add a fully qualified class or resource name prefix that, if it matches the name of a requested class or resource, will cause access to that class or resource to be attempted in the system class loader only (bypassing the repositories defined in this class loader). |
java.lang.String[] |
findAllowed()
Return a String array of the allowed class or resource name list for this class loader. |
java.lang.String[] |
findRepositories()
Return a String array of the current repositories for this class loader. |
java.lang.String[] |
findRestricted()
Return a String array of the restricted class or resource name prefixes for this class loader. |
java.lang.String[] |
findSystem()
Return a Striong array of the sytsem class or resource name prefixes for this class loader. |
int |
getDebug()
Return the debugging detail level of this component. |
int |
getMaxCount()
Return the maximum count of resources to be cached. |
long |
getMaxSize()
Return the maximum size of resources to be cached. |
long |
getMinSize()
Return the minimum size of resources to be cached. |
java.net.URL |
getResource(java.lang.String name)
Find a resource with a given name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Get an InputStream on a given resource. |
java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Requests the class loader to load and resolve a class with the specified name. |
boolean |
modified()
Have one or more classes or resources been modified so that a reload is appropriate? |
void |
removeAllowed(java.lang.String name)
Remove a fully qualified class or resource name from the allowed list. |
void |
removeRestricted(java.lang.String prefix)
Remove a class or resource name prefix from the restricted list. |
void |
removeSystem(java.lang.String prefix)
Remove a class or resource name prefix from the system list. |
void |
setDebug(int debug)
Set the debugging detail level of this component. |
void |
setMaxCount(int maxCount)
Set the maximum count of resources to be cached. |
void |
setMaxSize(long maxSize)
Set the maximum size of resources to be cached. |
void |
setMinSize(long minSize)
Set the minimum size of resources to be cached. |
java.lang.String |
toString()
Return a String representation of this class. |
Methods inherited from class java.lang.ClassLoader |
defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public FileClassLoader()
public FileClassLoader(java.lang.ClassLoader parent)
parent
- The parent ClassLoaderpublic FileClassLoader(java.lang.String[] repositories)
repositories
- Initial list of repositoriespublic FileClassLoader(java.lang.ClassLoader parent, java.lang.String[] respositories)
parent
- The parent ClassLoaderrepositories
- Initial list of repositoriesMethod Detail |
public int getDebug()
public void setDebug(int debug)
debug
- The new debugging detail levelpublic int getMaxCount()
public void setMaxCount(int maxCount)
maxCount
- The new maximum countpublic long getMaxSize()
public void setMaxSize(long maxSize)
public long getMinSize()
public void setMinSize(long minSize)
public void addAllowed(java.lang.String name)
addAllowed
in interface Reloader
name
- Class or resource name to allow access forpublic 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 pathnamejava.lang.IllegalArgumentException
- if the specified repository is
invalid or does not existpublic void addRestricted(java.lang.String prefix)
addRestricted
in interface Reloader
prefix
- The restricted prefixpublic void addSystem(java.lang.String prefix)
java.
prefix is defined as a system prefix.addSystem
in interface Reloader
prefix
- The system prefixpublic java.lang.String[] findAllowed()
findAllowed
in interface Reloader
public java.lang.String[] findRepositories()
findRepositories
in interface Reloader
public java.lang.String[] findRestricted()
findRestricted
in interface Reloader
public java.lang.String[] findSystem()
findSystem
in interface Reloader
public boolean modified()
modified
in interface Reloader
public void removeAllowed(java.lang.String name)
name
- The name to removepublic void removeRestricted(java.lang.String prefix)
prefix
- Prefix to be removedpublic void removeSystem(java.lang.String prefix)
prefix
- Prefix to be removedpublic java.net.URL getResource(java.lang.String name)
getContent()
on the URL may return an Image, an
AudioClip, or an InputStream.getResource
in class java.lang.ClassLoader
name
- The name of the resource, to be used as ispublic java.io.InputStream getResourceAsStream(java.lang.String name)
null
if no resource with this name is found.getResourceAsStream
in class java.lang.ClassLoader
name
- The name of the resourcepublic java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
method is called by the
Java Virtual Machine when a class loaded by a class loader first
references another class. Every subclass of ClassLoader
must define this method.loadClass
in class java.lang.ClassLoader
name
- Name of the desired Classresolve
- true
if this Class needs to be resolved.null
if it was not foundjava.lang.ClassNotFoundException
- if the class loader cannot find
a definition for this classpublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |