com.sas.framework.expojo.servlet
Class ExpojoServletContextListener

java.lang.Object
  extended by com.sas.framework.expojo.servlet.ExpojoServletContextListener

public abstract class ExpojoServletContextListener
extends java.lang.Object

Implements the ServletContextListener interface to initialize the exPOJO framework. It is designed to be extended by an application specific class. Only two methods in the application specific class require overriding: createPersistenceProviderFactory and addComponents. You may also like to optionally override establishGenesisObjects.

See Also:
createPersistenceProviderFactory(ServletContextEvent), addComponents(com.sas.framework.expojo.ModelExposer), establishGenesisObjects()

Field Summary
static ExpojoServletContextListener me
          Returns this singleton.
protected  PersistenceProviderFactory persistenceProviderFactory
           
 
Constructor Summary
ExpojoServletContextListener()
          Sets 'me' to this.
 
Method Summary
abstract  void addComponents(ModelExposer modelExposer)
          Adds service and repository components to the ModelExposer.
 void contextDestroyed(ServletContextEvent event)
          Called when the application context is being destroyed.
 void contextInitialized(ServletContextEvent event)
          Performs application initialisation and establishment of the PersistenceProviderFactory.
 ModelExposer createModelExposer()
          Creates a ModelExposer.
abstract  PersistenceProviderFactory createPersistenceProviderFactory(ServletContextEvent event)
          Overridden in a derived class to create the PersistenceProviderFactory.
 void destroyApplication()
          Called by the framework to allow application specific destruction behaviour.
 void establishGenesisObjects()
          Genesis objects are the essential, persistent, system objects that must be created right at the beginning of the life of a new system and from which all other objects will go forth and multiply.
static ExpojoServletContextListener get()
          Returns this singleton object.
 PersistenceProviderFactory getPersistenceProviderFactory()
          Returns persistenceProviderFactory.
 void initApplication()
          Overridden in derived classes to perform any applicaiton specific initialization, if required, after the framework initialization has taken place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

me

public static transient ExpojoServletContextListener me
Returns this singleton.


persistenceProviderFactory

protected PersistenceProviderFactory persistenceProviderFactory
Constructor Detail

ExpojoServletContextListener

public ExpojoServletContextListener()
Sets 'me' to this.

Method Detail

contextDestroyed

public void contextDestroyed(ServletContextEvent event)
Called when the application context is being destroyed. Typically an application will not override this method but override destroyApplication if application specific destruction is required.


destroyApplication

public void destroyApplication()
Called by the framework to allow application specific destruction behaviour. Override if required.


initApplication

public void initApplication()
Overridden in derived classes to perform any applicaiton specific initialization, if required, after the framework initialization has taken place.


addComponents

public abstract void addComponents(ModelExposer modelExposer)
Adds service and repository components to the ModelExposer. This method is called whenever the ExpojoSerletFilter is establishing a new session, and thus a new ModelExposer. This method adds the services and repositories to the ModelExposer. Within the scope of an individual HTTP request the ModelExposer, and hence its services and repositories, are made available to the application via dependency injection.


createModelExposer

public ModelExposer createModelExposer()
Creates a ModelExposer. Application developers should rarely need to call this. This is called implicitly by the ExpojoServletFilter to establish a ModelExposer object for each new session that is started.


establishGenesisObjects

public void establishGenesisObjects()
Genesis objects are the essential, persistent, system objects that must be created right at the beginning of the life of a new system and from which all other objects will go forth and multiply. This method creates them if they are not already created. If you're a creationist then this method represents the time in which a supernatural force called god, built the earth and everything around it. If you're an evolutionist then this method represents the big bang. Take your pick. This method is wrapped by code that has created a ModelExposer object and attached it to this thread. NOTE: This method is called each time the servlet context starts up so it is important to check if a well known 'key' genesis object already exists (via a query method in an appropriate repository) and only proceed to create the genesis objects if this key object can not be found. This method can also be used to perform model migration - ie., if the domain model has changed in some way and you need to rearrange certain relationships of objects - do it here in this method.


contextInitialized

public void contextInitialized(ServletContextEvent event)
Performs application initialisation and establishment of the PersistenceProviderFactory. It is not necessary to override this method but if it is then be sure to call this method first in the overridden method. Typically any application specific initialization is done by overriding initApplication which this method calls.


get

public static ExpojoServletContextListener get()
Returns this singleton object.


getPersistenceProviderFactory

public PersistenceProviderFactory getPersistenceProviderFactory()
Returns persistenceProviderFactory. Called by ExpojoServletFilter when constructing the ModelExposer.


createPersistenceProviderFactory

public abstract PersistenceProviderFactory createPersistenceProviderFactory(ServletContextEvent event)
Overridden in a derived class to create the PersistenceProviderFactory.