FileDocCategorySizeDatePackage
ContextListener.javaAPI DocGlassfish v2 API5347Fri May 04 22:34:14 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: 1.3 $ $Date: 2007/05/05 05:34:13 $

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);

    
private voidlog(java.lang.String message, java.lang.Throwable throwable)
Log a message and associated exception to the servlet context application log.

param
message Message to be logged
param
throwable Exception to be logged


	if (context != null)
	    context.log("ContextListener: " + message, throwable);
	else {
	    System.out.println("ContextListener: " + message);
	    throwable.printStackTrace(System.out);
	}