Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.objectstyle.cayenne.conf
Class WebApplicationListener  view WebApplicationListener download WebApplicationListener.java

java.lang.Object
  extended byorg.objectstyle.cayenne.conf.WebApplicationListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener

public class WebApplicationListener
extends java.lang.Object
implements javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener

WebApplicationListener utilizes Servlet specification 2.3 features to react on webapplication container events inializing Cayenne.

It performs the following tasks:

CayenneWebappListener must be configured in web.xml deployment descriptor as a listener of context and session events:

<listener>
     <listener-class>org.objectstyle.cayenne.conf.WebApplicationListener</listener-class>
</listener>

Note that to set WebApplicationListener as a listener of web application events, you must use servlet containers compatible with Servlet Specification 2.3 (such as Tomcat 4.0). Listeners were only added to servlet specification in 2.3. If you are using an older container, you will need to configure Cayenne in your code.


Constructor Summary
WebApplicationListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
          Currently does nothing.
 void contextInitialized(javax.servlet.ServletContextEvent sce)
          Establishes a Cayenne shared Configuration object that can later be obtained by calling Configuration.getSharedConfiguration().
protected  Configuration getConfiguration()
          Returns the current configuration.
protected  Configuration newConfiguration(javax.servlet.ServletContext sc)
          Return an instance of Configuration that will be initialized as the shared configuration.
 void sessionCreated(javax.servlet.http.HttpSessionEvent se)
          Creates and assigns a new data context based on default domain to the session object associated with this event.
 void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
          Does nothing.
protected  void setConfiguration(Configuration configuration)
          Initializes the configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebApplicationListener

public WebApplicationListener()
Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Establishes a Cayenne shared Configuration object that can later be obtained by calling Configuration.getSharedConfiguration(). This method is a part of ServletContextListener interface and is called on application startup.

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Currently does nothing. In the future it should close down any database connections if they wheren't obtained via JNDI. This method is a part of ServletContextListener interface and is called on application shutdown.

Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

sessionCreated

public void sessionCreated(javax.servlet.http.HttpSessionEvent se)
Creates and assigns a new data context based on default domain to the session object associated with this event. This method is a part of HttpSessionListener interface and is called every time when a new session is created.

Specified by:
sessionCreated in interface javax.servlet.http.HttpSessionListener

sessionDestroyed

public void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
Does nothing. This method is a part of HttpSessionListener interface and is called every time when a session is destroyed.

Specified by:
sessionDestroyed in interface javax.servlet.http.HttpSessionListener

newConfiguration

protected Configuration newConfiguration(javax.servlet.ServletContext sc)
Return an instance of Configuration that will be initialized as the shared configuration. Provides an extension point for the developer to provide their own custom configuration.


setConfiguration

protected void setConfiguration(Configuration configuration)
Initializes the configuration.


getConfiguration

protected Configuration getConfiguration()
Returns the current configuration.