fc.web.servlet
Class WebApp

java.lang.Object
  extended by fc.web.servlet.WebApp
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public class WebApp
extends java.lang.Object
implements javax.servlet.ServletContextListener

Application level global object running within a servlet web application (i.e., a servlet context). Global webapp data can be stored/retrieved via the put/get methods.

Initializes and stores various variables useful for all servlets/pages running in our JVM. Implements ServletContextListener and initializes itself at context initialization.

It's optional to use this class. If it is used, it's configured by adding the following to the appropriate sections of WEB-INF/web.xml:

<context-param>
        <param-name>configfile</param-name>
        <param-value>app.conf</param-value>
</context-param>

<listener>
        <listener-class>fc.web.servlet.WebApp</listener-class>
</listener>

If initialization is not successful, it tries to shut down the servlet JVM by calling System.exit. (The idea being it's better to fail early and safely then continue beyond this point).

If used, this class requires the following context configuration parameter:

This class can also be subclassed to initialize/contain website specific data and background/helper processing threads. Alternatively, along with this class as-is, additional independent site-specific ServletContextListener classes can be created and used as necessary.


Field Summary
static java.util.Map allServletsMap
          A (initially empty) Map that servlets can use to store a reference to themselves.
static SystemLog appLog
          A SystemLog object.
static java.util.Map appMap
           
static java.util.Map connectionManagers
           
static long default_dbcache_time
           
static ThreadLocalCalendar default_tlcal
           
static ThreadLocalDateFormat default_tldf
           
static ThreadLocalNumberFormat default_tlnf
           
static ConnectionMgr defaultConnectionManager
           
static PropertyMgr propertyMgr
           
static java.util.Map tlcalMap
           
static java.util.Map tldfMap
           
static java.util.Map tlnfMap
           
 
Constructor Summary
WebApp()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
          Basic implementation of the web application cleanup upon context destruction.
 void contextInitialized(javax.servlet.ServletContextEvent sce)
          Basic implementation of the web application cleanup upon context creation.
static java.lang.Object get(java.lang.Object key)
          Returns the specified object from the global application map or null if the object was not found.
static SystemLog getAppLog()
           
static java.sql.Connection getConnection()
           
static java.sql.Connection getConnection(java.lang.String databasename)
           
static ConnectionMgr getConnectionMgr()
          Returns the connection manager corresponding to the default database name.
static ConnectionMgr getConnectionMgr(java.lang.String databasename)
          Returns the connection manager corresponding to the database name.
static Cache getDBCache()
          Convenience method to get the pre-created application cache.
static Form getForm(java.lang.String name)
          Convenience method to return a form stored previously via the putForm method.
static ThreadLocalCalendar getThreadLocalCalendar()
          Returns the default ThreadLocalCalendar object (a new ThreadLocalCalendar is created if it does not exist).
static ThreadLocalCalendar getThreadLocalCalendar(java.lang.String name)
          Returns the ThreadLocalCalendar object corresponding to the specified name (a new ThreadLocalCalendar is created if it does not exist).
static ThreadLocalDateFormat getThreadLocalDateFormat()
          Returns the default threadLocalDateFormat object (a new ThreadLocalDateFormat is created if it does not exist).
static ThreadLocalDateFormat getThreadLocalDateFormat(java.lang.String name)
          Returns the ThreadLocalDateFormat object corresponding to the specified name (a new ThreadLocalDateFormat is created if it does not exist).
static ThreadLocalNumberFormat getThreadLocalNumberFormat()
          Returns the default ThreadLocalNumberFormat object (a new ThreadLocalNumberFormat is created if it does not exist).
static ThreadLocalNumberFormat getThreadLocalNumberFormat(java.lang.String name)
          Returns the ThreadLocalNumberFormat object corresponding to the specified name (a new ThreadLocalNumberFormat is created if it does not exist).
static void put(java.lang.Object key, java.lang.Object val)
          Puts the specified key/object into the global application map.
static void putForm(Form f)
           
static void removeForm(java.lang.String name)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

connectionManagers

public static java.util.Map connectionManagers

defaultConnectionManager

public static ConnectionMgr defaultConnectionManager

default_dbcache_time

public static long default_dbcache_time

default_tlcal

public static ThreadLocalCalendar default_tlcal

default_tldf

public static ThreadLocalDateFormat default_tldf

default_tlnf

public static ThreadLocalNumberFormat default_tlnf

appMap

public static java.util.Map appMap

tlcalMap

public static java.util.Map tlcalMap

tldfMap

public static java.util.Map tldfMap

tlnfMap

public static java.util.Map tlnfMap

appLog

public static SystemLog appLog
A SystemLog object. Servlets typically create their own loggers (with servlet specific logging levels) but can alternatively use this default appLog. This appLog is used by non-servlet classes such as this class itself, various listeners etc.


propertyMgr

public static PropertyMgr propertyMgr

allServletsMap

public static java.util.Map allServletsMap
A (initially empty) Map that servlets can use to store a reference to themselves. This is required because the servlet API has deprecated a similar API call (the servlet API authors are brain damaged 'tards).

Constructor Detail

WebApp

public WebApp()
Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Basic implementation of the web application cleanup upon context creation. If this method is subclassed, the subclassed method must also invoke this method via super.contextInitialized. This call should typically be at the beginning of the subclassed method, which allows this implementation to create connections, logs etc, which can then be used by the subclass to finish it's further initialization as needed.

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Basic implementation of the web application cleanup upon context destruction. If this method is subclassed, the subclassed method must also invoke this method via super.contextInitialized. This invokation should typically be at the end of the subclassed method (which allows the subclass to use connections etc., before they are closed by this superclass method).

Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

getConnectionMgr

public static ConnectionMgr getConnectionMgr(java.lang.String databasename)
Returns the connection manager corresponding to the database name. (specified in the dblist property of app.conf).

Throws:
java.lang.IllegalArgumentException - if the specified database is not found

getConnectionMgr

public static ConnectionMgr getConnectionMgr()
Returns the connection manager corresponding to the default database name. (specified in the dbdefault property of app.conf). Returns null if no default database has been initialized.


getConnection

public static java.sql.Connection getConnection(java.lang.String databasename)
                                         throws java.sql.SQLException
Throws:
java.sql.SQLException

getConnection

public static java.sql.Connection getConnection()
                                         throws java.sql.SQLException
Throws:
java.sql.SQLException

getAppLog

public static SystemLog getAppLog()

getForm

public static Form getForm(java.lang.String name)
Convenience method to return a form stored previously via the putForm method. Returns null if no form with the specified name was found.


putForm

public static void putForm(Form f)

removeForm

public static void removeForm(java.lang.String name)

getDBCache

public static Cache getDBCache()
Convenience method to get the pre-created application cache. This can be used for caching database results as necessary. Each entry in the cache can be stored for entry-specific time-to-live (see {@link Cache) but if no entry-specific-time-to-live is specified, then entries are cached for a default time of 5 minutes. Of course, cached entries should always be invalidated sooner whenever the database is modified.


getThreadLocalDateFormat

public static ThreadLocalDateFormat getThreadLocalDateFormat(java.lang.String name)
Returns the ThreadLocalDateFormat object corresponding to the specified name (a new ThreadLocalDateFormat is created if it does not exist).


getThreadLocalDateFormat

public static ThreadLocalDateFormat getThreadLocalDateFormat()
Returns the default threadLocalDateFormat object (a new ThreadLocalDateFormat is created if it does not exist).


getThreadLocalNumberFormat

public static ThreadLocalNumberFormat getThreadLocalNumberFormat(java.lang.String name)
Returns the ThreadLocalNumberFormat object corresponding to the specified name (a new ThreadLocalNumberFormat is created if it does not exist).


getThreadLocalNumberFormat

public static ThreadLocalNumberFormat getThreadLocalNumberFormat()
Returns the default ThreadLocalNumberFormat object (a new ThreadLocalNumberFormat is created if it does not exist).


getThreadLocalCalendar

public static ThreadLocalCalendar getThreadLocalCalendar(java.lang.String name)
Returns the ThreadLocalCalendar object corresponding to the specified name (a new ThreadLocalCalendar is created if it does not exist).


getThreadLocalCalendar

public static ThreadLocalCalendar getThreadLocalCalendar()
Returns the default ThreadLocalCalendar object (a new ThreadLocalCalendar is created if it does not exist).


get

public static java.lang.Object get(java.lang.Object key)
Returns the specified object from the global application map or null if the object was not found.


put

public static void put(java.lang.Object key,
                       java.lang.Object val)
Puts the specified key/object into the global application map.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object