FileDocCategorySizeDatePackage
ContextListener.javaAPI DocApache Tomcat 6.0.143833Fri Jul 20 04:20:32 BST 2007listeners

ContextListener

public final class ContextListener extends Object implements ServletContextAttributeListener, ServletContextListener
Example listener for context-related application events, which were introduced in the 2.3 version of the Servlet API. This listener merely documents the occurrence of such events in the application log associated with our servlet context.
author
Craig R. McClanahan
version
$Revision: 500674 $ $Date: 2007-01-28 00:15:00 +0100 (dim., 28 janv. 2007) $

Fields Summary
private ServletContext
context
The servlet context with which we are associated.
Constructors Summary
Methods Summary
public voidattributeAdded(javax.servlet.ServletContextAttributeEvent event)
Record the fact that a servlet context attribute was added.

param
event The servlet context attribute event



    // --------------------------------------------------------- Public Methods


                          
        

	log("attributeAdded('" + event.getName() + "', '" +
	    event.getValue() + "')");

    
public voidattributeRemoved(javax.servlet.ServletContextAttributeEvent event)
Record the fact that a servlet context attribute was removed.

param
event The servlet context attribute event


	log("attributeRemoved('" + event.getName() + "', '" +
	    event.getValue() + "')");

    
public voidattributeReplaced(javax.servlet.ServletContextAttributeEvent event)
Record the fact that a servlet context attribute was replaced.

param
event The servlet context attribute event


	log("attributeReplaced('" + event.getName() + "', '" +
	    event.getValue() + "')");

    
public voidcontextDestroyed(javax.servlet.ServletContextEvent event)
Record the fact that this web application has been destroyed.

param
event The servlet context event


	log("contextDestroyed()");
	this.context = null;

    
public voidcontextInitialized(javax.servlet.ServletContextEvent event)
Record the fact that this web application has been initialized.

param
event The servlet context event


	this.context = event.getServletContext();
	log("contextInitialized()");

    
private voidlog(java.lang.String message)
Log a message to the servlet context application log.

param
message Message to be logged


	if (context != null)
	    context.log("ContextListener: " + message);
	else
	    System.out.println("ContextListener: " + message);