| Method from org.apache.catalina.loader.WebappLoader Detail: |
public void addLifecycleListener(LifecycleListener listener) {
lifecycle.addLifecycleListener(listener);
}
Add a lifecycle event listener to this component. |
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}
Add a property change listener to this component. |
public void addRepository(String repository) {
if (log.isDebugEnabled())
log.debug(sm.getString("webappLoader.addRepository", repository));
for (int i = 0; i < repositories.length; i++) {
if (repository.equals(repositories[i]))
return;
}
String results[] = new String[repositories.length + 1];
for (int i = 0; i < repositories.length; i++)
results[i] = repositories[i];
results[repositories.length] = repository;
repositories = results;
if (started && (classLoader != null)) {
classLoader.addRepository(repository);
if( loaderRepositories != null ) loaderRepositories.add(repository);
setClassPath();
}
}
Add a new repository to the set of repositories for this class loader. |
public void backgroundProcess() {
if (reloadable && modified()) {
try {
Thread.currentThread().setContextClassLoader
(WebappLoader.class.getClassLoader());
if (container instanceof StandardContext) {
((StandardContext) container).reload();
}
} finally {
if (container.getLoader() != null) {
Thread.currentThread().setContextClassLoader
(container.getLoader().getClassLoader());
}
}
} else {
closeJARs(false);
}
}
Execute a periodic task, such as reloading, etc. This method will be
invoked inside the classloading context of this container. Unexpected
throwables will be caught and logged. |
public void closeJARs(boolean force) {
if (classLoader !=null){
classLoader.closeJARs(force);
}
}
Used to periodically signal to the classloader to release JAR resources. |
public void destroy() {
if( controller==oname ) {
// Self-registration, undo it
Registry.getRegistry(null, null).unregisterComponent(oname);
oname = null;
}
initialized = false;
}
|
public LifecycleListener[] findLifecycleListeners() {
return lifecycle.findLifecycleListeners();
}
Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned. |
public String[] findRepositories() {
return ((String[])repositories.clone());
}
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). |
public ClassLoader getClassLoader() {
return ((ClassLoader) classLoader);
}
Return the Java class loader to be used by this Container. |
public String getClasspath() {
return classpath;
}
Classpath, as set in org.apache.catalina.jsp_classpath context
property |
public Container getContainer() {
return (container);
}
Return the Container with which this Logger has been associated. |
public ObjectName getController() {
return controller;
}
|
public boolean getDelegate() {
return (this.delegate);
}
Return the "follow standard delegation model" flag used to configure
our ClassLoader. |
public String getInfo() {
return (info);
}
Return descriptive information about this Loader implementation and
the corresponding version number, in the format
<description>/<version>. |
public String getLoaderClass() {
return (this.loaderClass);
}
Return the ClassLoader class name. |
public String[] getLoaderRepositories() {
if( loaderRepositories==null ) return null;
String res[]=new String[ loaderRepositories.size()];
loaderRepositories.toArray(res);
return res;
}
|
public String getLoaderRepositoriesString() {
String repositories[]=getLoaderRepositories();
StringBuffer sb=new StringBuffer();
for( int i=0; i< repositories.length ; i++ ) {
sb.append( repositories[i]).append(":");
}
return sb.toString();
}
|
public boolean getReloadable() {
return (this.reloadable);
}
Return the reloadable flag for this Loader. |
public String[] getRepositories() {
return ((String[])repositories.clone());
}
|
public String getRepositoriesString() {
StringBuffer sb=new StringBuffer();
for( int i=0; i< repositories.length ; i++ ) {
sb.append( repositories[i]).append(":");
}
return sb.toString();
}
Extra repositories for this loader |
public void init() {
initialized=true;
if( oname==null ) {
// not registered yet - standalone or API
if( container instanceof StandardContext) {
// Register ourself. The container must be a webapp
try {
StandardContext ctx=(StandardContext)container;
Engine eng=(Engine)ctx.getParent().getParent();
String path = ctx.getPath();
if (path.equals("")) {
path = "/";
}
oname=new ObjectName(ctx.getEngineName() + ":type=Loader,path=" +
path + ",host=" + ctx.getParent().getName());
Registry.getRegistry(null, null).registerComponent(this, oname, null);
controller=oname;
} catch (Exception e) {
log.error("Error registering loader", e );
}
}
}
if( container == null ) {
// JMX created the loader
// TODO
}
}
|
public boolean modified() {
return (classLoader.modified());
}
Has the internal repository associated with this Loader been modified,
such that the loaded classes should be reloaded? |
public void postDeregister() {
}
|
public void postRegister(Boolean registrationDone) {
}
|
public void preDeregister() throws Exception {
}
|
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
oname=name;
mserver=server;
domain=name.getDomain();
return name;
}
|
public void propertyChange(PropertyChangeEvent event) {
// Validate the source of this event
if (!(event.getSource() instanceof Context))
return;
Context context = (Context) event.getSource();
// Process a relevant property change
if (event.getPropertyName().equals("reloadable")) {
try {
setReloadable
( ((Boolean) event.getNewValue()).booleanValue() );
} catch (NumberFormatException e) {
log.error(sm.getString("webappLoader.reloadable",
event.getNewValue().toString()));
}
}
}
Process property change events from our associated Context. |
public void removeLifecycleListener(LifecycleListener listener) {
lifecycle.removeLifecycleListener(listener);
}
Remove a lifecycle event listener from this component. |
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
Remove a property change listener from this component. |
public void setContainer(Container container) {
// Deregister from the old Container (if any)
if ((this.container != null) && (this.container instanceof Context))
((Context) this.container).removePropertyChangeListener(this);
// Process this property change
Container oldContainer = this.container;
this.container = container;
support.firePropertyChange("container", oldContainer, this.container);
// Register with the new Container (if any)
if ((this.container != null) && (this.container instanceof Context)) {
setReloadable( ((Context) this.container).getReloadable() );
((Context) this.container).addPropertyChangeListener(this);
}
}
Set the Container with which this Logger has been associated. |
public void setController(ObjectName controller) {
this.controller = controller;
}
|
public void setDelegate(boolean delegate) {
boolean oldDelegate = this.delegate;
this.delegate = delegate;
support.firePropertyChange("delegate", new Boolean(oldDelegate),
new Boolean(this.delegate));
}
Set the "follow standard delegation model" flag used to configure
our ClassLoader. |
public void setLoaderClass(String loaderClass) {
this.loaderClass = loaderClass;
}
Set the ClassLoader class name. |
public void setReloadable(boolean reloadable) {
// Process this property change
boolean oldReloadable = this.reloadable;
this.reloadable = reloadable;
support.firePropertyChange("reloadable",
new Boolean(oldReloadable),
new Boolean(this.reloadable));
}
Set the reloadable flag for this Loader. |
public void start() throws LifecycleException {
// Validate and update our current component state
if( ! initialized ) init();
if (started)
throw new LifecycleException
(sm.getString("webappLoader.alreadyStarted"));
if (log.isDebugEnabled())
log.debug(sm.getString("webappLoader.starting"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
if (container.getResources() == null) {
log.info("No resources for " + container);
return;
}
// Register a stream handler factory for the JNDI protocol
URLStreamHandlerFactory streamHandlerFactory =
new DirContextURLStreamHandlerFactory();
if (first) {
first = false;
try {
URL.setURLStreamHandlerFactory(streamHandlerFactory);
} catch (Exception e) {
// Log and continue anyway, this is not critical
log.error("Error registering jndi stream handler", e);
} catch (Throwable t) {
// This is likely a dual registration
log.info("Dual registration of jndi stream handler: "
+ t.getMessage());
}
}
// Construct a class loader based on our current repositories list
try {
classLoader = createClassLoader();
classLoader.setResources(container.getResources());
classLoader.setDelegate(this.delegate);
if (container instanceof StandardContext)
classLoader.setAntiJARLocking(((StandardContext) container).getAntiJARLocking());
for (int i = 0; i < repositories.length; i++) {
classLoader.addRepository(repositories[i]);
}
// Configure our repositories
setRepositories();
setClassPath();
setPermissions();
if (classLoader instanceof Lifecycle)
((Lifecycle) classLoader).start();
// Binding the Webapp class loader to the directory context
DirContextURLStreamHandler.bind
((ClassLoader) classLoader, this.container.getResources());
StandardContext ctx=(StandardContext)container;
Engine eng=(Engine)ctx.getParent().getParent();
String path = ctx.getPath();
if (path.equals("")) {
path = "/";
}
ObjectName cloname = new ObjectName
(ctx.getEngineName() + ":type=WebappClassLoader,path="
+ path + ",host=" + ctx.getParent().getName());
Registry.getRegistry(null, null)
.registerComponent(classLoader, cloname, null);
} catch (Throwable t) {
log.error( "LifecycleException ", t );
throw new LifecycleException("start: ", t);
}
}
Start this component, initializing our associated class loader. |
public void stop() throws LifecycleException {
// Validate and update our current component state
if (!started)
throw new LifecycleException
(sm.getString("webappLoader.notStarted"));
if (log.isDebugEnabled())
log.debug(sm.getString("webappLoader.stopping"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
// Remove context attributes as appropriate
if (container instanceof Context) {
ServletContext servletContext =
((Context) container).getServletContext();
servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
}
// Throw away our current class loader
if (classLoader instanceof Lifecycle)
((Lifecycle) classLoader).stop();
DirContextURLStreamHandler.unbind((ClassLoader) classLoader);
try {
StandardContext ctx=(StandardContext)container;
Engine eng=(Engine)ctx.getParent().getParent();
String path = ctx.getPath();
if (path.equals("")) {
path = "/";
}
ObjectName cloname = new ObjectName
(ctx.getEngineName() + ":type=WebappClassLoader,path="
+ path + ",host=" + ctx.getParent().getName());
Registry.getRegistry(null, null).unregisterComponent(cloname);
} catch (Throwable t) {
log.error( "LifecycleException ", t );
}
classLoader = null;
destroy();
}
Stop this component, finalizing our associated class loader. |
public String toString() {
StringBuffer sb = new StringBuffer("WebappLoader[");
if (container != null)
sb.append(container.getName());
sb.append("]");
return (sb.toString());
}
Return a String representation of this component. |