FileDocCategorySizeDatePackage
WebContainerListener.javaAPI DocGlassfish v2 API8345Fri May 04 22:36:20 BST 2007com.sun.web.server

WebContainerListener

public final class WebContainerListener extends Object implements ContainerListener
This class implements the Tomcat ContainerListener interface and handles Context and Session related events.
author
Tony Ng

Fields Summary
static Logger
_logger
private static HashSet
beforeEvents
private static HashSet
afterEvents
private InvocationManager
im
private InjectionManager
injectionMgr
Constructors Summary
public WebContainerListener()

        injectionMgr = Switch.getSwitch().getInjectionManager();
    
Methods Summary
public voidcontainerEvent(ContainerEvent event)

        if(_logger.isLoggable(Level.FINEST)) {
	    _logger.log(Level.FINEST,"ContainerEvent: " +
                        event.getType() + "," +
                        event.getContainer() + "," +
                        event.getData());
        }

        String type = event.getType();

        try {
            if (ContainerEvent.AFTER_LISTENER_INSTANTIATED.equals(type)
                    || ContainerEvent.BEFORE_FILTER_INITIALIZED.equals(type)) {
                preInvoke((Context) event.getContainer());
                injectInstance(event);
                postInvoke((Context) event.getContainer());
            }

            if (beforeEvents.contains(type)) {
                preInvoke((Context) event.getContainer());
            } else if (afterEvents.contains(type)) {
                postInvoke((Context) event.getContainer());
            }
        } catch (Exception ex) {
            String msg = _logger.getResourceBundle().getString(
                "web_server.excep_handle_event");
            msg = MessageFormat.format(msg, new Object[] { type });
            throw new RuntimeException(msg, ex);
        } finally {
            if (type.equals(ContainerEvent.AFTER_FILTER_DESTROYED)) {
                preDestroy(event);
            }
        } 
    
private voidinjectInstance(ContainerEvent event)


        JndiNameEnvironment desc = (JndiNameEnvironment) 
            Switch.getSwitch().getDescriptorFor(
                                    (Context) event.getContainer());
        if( desc != null ) {
            injectionMgr.injectInstance(event.getData(), desc);
        }
    
private voidpostInvoke(Context ctx)

        ComponentInvocation inv = new ComponentInvocation();
        inv.instance = null;
        inv.container = ctx;
        if (im == null) {
            im = Switch.getSwitch().getInvocationManager();
        }
        im.postInvoke(inv);
    
private voidpreDestroy(ContainerEvent event)
Invokes preDestroy on the instance embedded in the given ContainerEvent.

param
event The ContainerEvent to process

        try {
            JndiNameEnvironment desc = (JndiNameEnvironment) 
                Switch.getSwitch().getDescriptorFor(
                                    (Context) event.getContainer());
            if( desc != null ) {
                injectionMgr.invokeInstancePreDestroy(event.getData(), desc);
            }
        } catch (InjectionException ie) {
            _logger.log(Level.SEVERE,
                        "web_server.excep_handle_after_event",
                        ie);
        }
    
private voidpreInvoke(Context ctx)

        ComponentInvocation inv = new ComponentInvocation();
        inv.instance = null;
        inv.container = ctx;

        if (im == null) {
            im = Switch.getSwitch().getInvocationManager();
        }
        im.preInvoke(inv);