org.qi4j.library.servlet.lifecycle
Class AbstractQi4jServletBootstrap

java.lang.Object
  extended by org.qi4j.library.servlet.lifecycle.AbstractQi4jServletBootstrap
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener, ApplicationAssembler

public abstract class AbstractQi4jServletBootstrap
extends Object
implements javax.servlet.ServletContextListener, ApplicationAssembler

Abstract ServletContextListener implementing ApplicationAssembler. Extends this class to easily bind a Qi4j Application activation/passivation to your webapp lifecycle. The Application is set as a ServletContext attribute named using a constant. In your servlets, filters, whatever has access to the ServletContext use the following code to get a handle on the Application:

  org.qi4j.api.structure.Application application;

  application = ( Application ) servletContext.getAttribute( Qi4jServletSupport.APP_IN_CTX );

  // Or, shorter:
 
  application = Qi4jServletSupport.application( servletContext );

 
Rembember that the servlet specification states: In cases where the container is distributed over many virtual machines, a Web application will have an instance of the ServletContext for each JVM. Context attributes are local to the JVM in which they were created. This prevents ServletContext attributes from being a shared memory store in a distributed container. When information needs to be shared between servlets running in a distributed environment, the information should be placed into a session, stored in a database, or set in an Enterprise JavaBeans component.


Field Summary
protected  Qi4j api
           
protected  ApplicationSPI application
           
protected  ApplicationModelSPI applicationModel
           
protected  Energy4Java qi4j
           
protected  Qi4jSPI spi
           
 
Constructor Summary
AbstractQi4jServletBootstrap()
           
 
Method Summary
protected  void afterApplicationActivation(Application app)
           
protected  void beforeApplicationActivation(Application app)
           
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
           
 void contextInitialized(javax.servlet.ServletContextEvent sce)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.qi4j.bootstrap.ApplicationAssembler
assemble
 

Field Detail

api

protected Qi4j api

spi

protected Qi4jSPI spi

qi4j

protected Energy4Java qi4j

applicationModel

protected ApplicationModelSPI applicationModel

application

protected ApplicationSPI application
Constructor Detail

AbstractQi4jServletBootstrap

public AbstractQi4jServletBootstrap()
Method Detail

contextInitialized

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

beforeApplicationActivation

protected void beforeApplicationActivation(Application app)

afterApplicationActivation

protected void afterApplicationActivation(Application app)

contextDestroyed

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