Package org.apache.catalina.loader
Class WebappLoader
- java.lang.Object
-
- org.apache.catalina.loader.WebappLoader
-
- All Implemented Interfaces:
PropertyChangeListener,EventListener,Lifecycle,Loader
public class WebappLoader extends Object implements Lifecycle, Loader, PropertyChangeListener
Classloader implementation which is specialized for handling web applications in the most efficient way, while being Catalina aware (all accesses to resources are made through the DirContext interface). This class loader supports detection of modified Java classes, which can be used to implement auto-reload support.This class loader is configured by adding the pathnames of directories, JAR files, and ZIP files with the
addRepository()method, prior to callingstart(). When a new class is required, these repositories will be consulted first to locate the class. If it is not present, the system class loader will be used instead.- Version:
- $Revision: 1.10 $ $Date: 2007/05/05 05:32:09 $
- Author:
- Craig R. McClanahan, Remy Maucherat
-
-
Field Summary
Fields Modifier and Type Field Description protected LifecycleSupportlifecycleThe lifecycle event support for this component.protected static StringManagersmThe string manager for this package.protected PropertyChangeSupportsupportThe property change support for this component.-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description WebappLoader()Construct a new WebappLoader with no defined parent class loader (so that the actual parent will be the system class loader).WebappLoader(ClassLoader parent)Construct a new WebappLoader with the specified class loader to be defined as the parent of the ClassLoader we ultimately create.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLifecycleListener(LifecycleListener listener)Add a lifecycle event listener to this component.voidaddOverridablePackage(String packageName)Adds the given package name to the list of packages that may always be overriden, regardless of whether they belong to a protected namespacevoidaddPropertyChangeListener(PropertyChangeListener listener)Add a property change listener to this component.voidaddRepository(String repository)Add a new repository to the set of repositories for this class loader.voidcloseJARs(boolean force)Used to periodically signal to the classloader to release JAR resources.protected ClassLoadercreateClassLoader()Create associated classLoader.voiddestroy()List<LifecycleListener>findLifecycleListeners()Gets the (possibly empty) list of lifecycle listeners associated with this WebappLoader.String[]findRepositories()Return the set of repositories defined for this class loader.ClassLoadergetClassLoader()Return the Java class loader to be used by this Container.StringgetClasspath()Classpath, as set in org.apache.catalina.jsp_classpath context propertyContainergetContainer()Return the Container with which this Logger has been associated.ObjectNamegetController()intgetDebug()Return the debugging detail level for this component.booleangetDelegate()Return the "follow standard delegation model" flag used to configure our ClassLoader.StringgetInfo()Return descriptive information about this Loader implementation and the corresponding version number, in the format<description>/<version>.StringgetLoaderClass()Return the ClassLoader class name.booleangetReloadable()Return the reloadable flag for this Loader.String[]getRepositories()voidinit()booleanmodified()Has the internal repository associated with this Loader been modified, such that the loaded classes should be reloaded?voidpropertyChange(PropertyChangeEvent event)Process property change events from our associated Context.voidremoveLifecycleListener(LifecycleListener listener)Remove a lifecycle event listener from this component.voidremovePropertyChangeListener(PropertyChangeListener listener)Remove a property change listener from this component.voidsetContainer(Container container)Set the Container with which this Logger has been associated.voidsetController(ObjectName controller)voidsetDebug(int debug)Set the debugging detail level for this component.voidsetDelegate(boolean delegate)Set the "follow standard delegation model" flag used to configure our ClassLoader.voidsetIgnoreHiddenJarFiles(boolean ignoreHiddenJarFiles)voidsetLoaderClass(String loaderClass)Set the ClassLoader class name.voidsetReloadable(boolean reloadable)Set the reloadable flag for this Loader.voidsetUseMyFaces(boolean useMyFaces)voidstart()Start this component, initializing our associated class loader.voidstop()Stop this component, finalizing our associated class loader.voidstopNestedClassLoader()Stops the nested classloaderStringtoString()Return a String representation of this component.
-
-
-
Field Detail
-
lifecycle
protected LifecycleSupport lifecycle
The lifecycle event support for this component.
-
sm
protected static final StringManager sm
The string manager for this package.
-
support
protected PropertyChangeSupport support
The property change support for this component.
-
-
Constructor Detail
-
WebappLoader
public WebappLoader()
Construct a new WebappLoader with no defined parent class loader (so that the actual parent will be the system class loader).
-
WebappLoader
public WebappLoader(ClassLoader parent)
Construct a new WebappLoader with the specified class loader to be defined as the parent of the ClassLoader we ultimately create.- Parameters:
parent- The parent class loader
-
-
Method Detail
-
getClassLoader
public ClassLoader getClassLoader()
Return the Java class loader to be used by this Container.- Specified by:
getClassLoaderin interfaceLoader
-
getContainer
public Container getContainer()
Return the Container with which this Logger has been associated.- Specified by:
getContainerin interfaceLoader
-
setContainer
public void setContainer(Container container)
Set the Container with which this Logger has been associated.- Specified by:
setContainerin interfaceLoader- Parameters:
container- The associated Container
-
getDebug
public int getDebug()
Return the debugging detail level for this component.
-
setDebug
public void setDebug(int debug)
Set the debugging detail level for this component.- Parameters:
debug- The new debugging detail level
-
getDelegate
public boolean getDelegate()
Return the "follow standard delegation model" flag used to configure our ClassLoader.- Specified by:
getDelegatein interfaceLoader
-
setDelegate
public void setDelegate(boolean delegate)
Set the "follow standard delegation model" flag used to configure our ClassLoader.- Specified by:
setDelegatein interfaceLoader- Parameters:
delegate- The new flag
-
getInfo
public String getInfo()
Return descriptive information about this Loader implementation and the corresponding version number, in the format<description>/<version>.
-
getLoaderClass
public String getLoaderClass()
Return the ClassLoader class name.
-
setLoaderClass
public void setLoaderClass(String loaderClass)
Set the ClassLoader class name.- Parameters:
loaderClass- The new ClassLoader class name
-
getReloadable
public boolean getReloadable()
Return the reloadable flag for this Loader.- Specified by:
getReloadablein interfaceLoader
-
setReloadable
public void setReloadable(boolean reloadable)
Set the reloadable flag for this Loader.- Specified by:
setReloadablein interfaceLoader- Parameters:
reloadable- The new reloadable flag
-
setUseMyFaces
public void setUseMyFaces(boolean useMyFaces)
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.- Specified by:
addPropertyChangeListenerin interfaceLoader- Parameters:
listener- The listener to add
-
addRepository
public void addRepository(String repository)
Add a new repository to the set of repositories for this class loader.- Specified by:
addRepositoryin interfaceLoader- Parameters:
repository- Repository to be added
-
findRepositories
public String[] findRepositories()
Return the set of repositories defined for this class loader. If none are defined, a zero-length array is returned. For security reason, returns a clone of the Array (since String are immutable).- Specified by:
findRepositoriesin interfaceLoader
-
getRepositories
public String[] getRepositories()
-
getClasspath
public String getClasspath()
Classpath, as set in org.apache.catalina.jsp_classpath context property- Returns:
- The classpath
-
modified
public boolean modified()
Has the internal repository associated with this Loader been modified, such that the loaded classes should be reloaded?
-
closeJARs
public void closeJARs(boolean force)
Used to periodically signal to the classloader to release JAR resources.
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.- Specified by:
removePropertyChangeListenerin interfaceLoader- Parameters:
listener- The listener to remove
-
toString
public String toString()
Return a String representation of this component.
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.- Specified by:
addLifecycleListenerin interfaceLifecycle- Parameters:
listener- The listener to add
-
findLifecycleListeners
public List<LifecycleListener> findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated with this WebappLoader.- Specified by:
findLifecycleListenersin interfaceLifecycle
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.- Specified by:
removeLifecycleListenerin interfaceLifecycle- Parameters:
listener- The listener to remove
-
init
public void init()
-
destroy
public void destroy()
-
start
public void start() throws LifecycleExceptionStart this component, initializing our associated class loader.- Specified by:
startin interfaceLifecycle- Throws:
LifecycleException- if a lifecycle error occurs
-
stop
public void stop() throws LifecycleExceptionStop this component, finalizing our associated class loader.- Specified by:
stopin interfaceLifecycle- Throws:
LifecycleException- if a lifecycle error occurs
-
stopNestedClassLoader
public void stopNestedClassLoader() throws LifecycleExceptionStops the nested classloader- Throws:
LifecycleException
-
propertyChange
public void propertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.- Specified by:
propertyChangein interfacePropertyChangeListener- Parameters:
event- The property change event that has occurred
-
createClassLoader
protected ClassLoader createClassLoader() throws Exception
Create associated classLoader.- Throws:
Exception
-
getController
public ObjectName getController()
-
setController
public void setController(ObjectName controller)
-
addOverridablePackage
public void addOverridablePackage(String packageName)
Adds the given package name to the list of packages that may always be overriden, regardless of whether they belong to a protected namespace- Specified by:
addOverridablePackagein interfaceLoader
-
setIgnoreHiddenJarFiles
public void setIgnoreHiddenJarFiles(boolean ignoreHiddenJarFiles)
- Specified by:
setIgnoreHiddenJarFilesin interfaceLoader
-
-