org.picocontainer.web
Class PicoServletContainerListener

java.lang.Object
  extended by org.picocontainer.web.PicoServletContainerListener
All Implemented Interfaces:
Serializable, EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener
Direct Known Subclasses:
SystemPropertiesPicoServletContainerListener

public class PicoServletContainerListener
extends Object
implements javax.servlet.ServletContextListener, javax.servlet.http.HttpSessionListener, Serializable

Servlet listener class that hooks into the underlying servlet container and instantiates, assembles, starts, stores and disposes the appropriate pico containers when applications/sessions start/stop.

To use, simply add as a listener to the web.xml the listener-class

 <listener>
  <listener-class>org.picocontainer.web.PicoServletContainerListener</listener-class>
 </listener> 
 

The listener also requires a the class name of the WebappComposer as a context-param in web.xml:

  <context-param>
   <param-name>webapp-composer-class</param-name>
   <param-value>com.company.MyWebappComposer</param-value>
  </context-param>
 
The composer will be used to compose the components for the different webapp scopes after the context has been initialised.

Author:
Joe Walnes, Aslak Hellesøy, Philipp Meier, Paul Hammant, Mauro Talevi, Konstantin Pribluda
See Also:
Serialized Form

Nested Class Summary
static class PicoServletContainerListener.ScopedContainers
           
 
Field Summary
static String WEBAPP_COMPOSER_CLASS
           
 
Constructor Summary
PicoServletContainerListener()
          Default constructor used in webapp containers
PicoServletContainerListener(org.picocontainer.DefaultPicoContainer applicationContainer, org.picocontainer.DefaultPicoContainer sessionContainer, org.picocontainer.DefaultPicoContainer requestContainer, org.picocontainer.behaviors.Storing sessionStoring, org.picocontainer.behaviors.Storing requestStoring)
          Creates a PicoServletContainerListener with dependencies injected
 
Method Summary
protected  void compose(WebappComposer composer)
           
 void contextDestroyed(javax.servlet.ServletContextEvent event)
           
 void contextInitialized(javax.servlet.ServletContextEvent event)
           
protected  WebappComposer loadComposer(javax.servlet.ServletContext context)
          Get the class to do compostition with - from a "webapp-composer-class" config param from web.xml : webapp-composer-class com.yourcompany.YourWebappComposer
protected  org.picocontainer.PicoContainer makeParentContainer()
           
protected  PicoServletContainerListener.ScopedContainers makeScopedContainers()
          Overide this method if you need a more specialized container tree.
 void sessionCreated(javax.servlet.http.HttpSessionEvent event)
           
 void sessionDestroyed(javax.servlet.http.HttpSessionEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEBAPP_COMPOSER_CLASS

public static final String WEBAPP_COMPOSER_CLASS
See Also:
Constant Field Values
Constructor Detail

PicoServletContainerListener

public PicoServletContainerListener()
Default constructor used in webapp containers


PicoServletContainerListener

public PicoServletContainerListener(org.picocontainer.DefaultPicoContainer applicationContainer,
                                    org.picocontainer.DefaultPicoContainer sessionContainer,
                                    org.picocontainer.DefaultPicoContainer requestContainer,
                                    org.picocontainer.behaviors.Storing sessionStoring,
                                    org.picocontainer.behaviors.Storing requestStoring)
Creates a PicoServletContainerListener with dependencies injected

Parameters:
applicationContainer - the application-scoped container
sessionContainer - the session-scoped container
requestContainer - the request-scoped container
sessionStoring - the session storing behaviour
requestStoring - the request storing behaviour
Method Detail

makeParentContainer

protected org.picocontainer.PicoContainer makeParentContainer()

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

makeScopedContainers

protected PicoServletContainerListener.ScopedContainers makeScopedContainers()
Overide this method if you need a more specialized container tree. Here is the default block of code for this - DefaultPicoContainer appCtnr = new DefaultPicoContainer(new Caching(), makeParentContainer()); Storing sessStoring = new Storing(); DefaultPicoContainer sessCtnr = new DefaultPicoContainer(sessStoring, appCtnr); Storing reqStoring = new Storing(); DefaultPicoContainer reqCtnr = new DefaultPicoContainer(reqStoring, sessCtnr); return new ScopedContainers(appCtnr,sessCtnr,reqCtnr,sessStoring,reqStoring);

Returns:
an instance of ScopedContainers

loadComposer

protected WebappComposer loadComposer(javax.servlet.ServletContext context)
Get the class to do compostition with - from a "webapp-composer-class" config param from web.xml : webapp-composer-class com.yourcompany.YourWebappComposer

Parameters:
context -
Returns:

compose

protected void compose(WebappComposer composer)

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent event)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

sessionCreated

public void sessionCreated(javax.servlet.http.HttpSessionEvent event)
Specified by:
sessionCreated in interface javax.servlet.http.HttpSessionListener

sessionDestroyed

public void sessionDestroyed(javax.servlet.http.HttpSessionEvent event)
Specified by:
sessionDestroyed in interface javax.servlet.http.HttpSessionListener


Copyright © 2008. All Rights Reserved.