org.activemath.config
Class ServletContextConfigurator

java.lang.Object
  extended by org.activemath.config.ServletContextConfigurator
All Implemented Interfaces:
EventListener, ServletContextListener

public class ServletContextConfigurator
extends Object
implements ServletContextListener

Run-once class to adjust the directories of ActiveMath when deployed as web-application. The principle behind this class is that the whole web-application directory should be read-only for the web-application, so as to allow developers to unpack a new war or to upload a new directory distribution, hence have the data-directories (like the user-model storage, the user's database, the session-Manager freezer) be in separate directories. These separate directories are, as the only work-oriented directory provided by the servlet specifications, the so-called "temporary" directory. Installers are encouraged to provide properties to indicate another directory writable by the web-application and should be aware that some servlet-containers empty the working directory at each startup. (this is not the case of the Tomcat 4 servlet container).

The re-configuration will happen iff the system-property activemath.home is not defined and iff the manager is not already initted (as given by Manager.isInitted()).

This class is built with a ServletContext object whose properties are used to adjust the distribution of paths within ActiveMath. Invoke this class by creating a new instance then invoking it run() method.

The goal of these modifications is to be able to completely separate the web-archive from the data of the life of the servers, thereby allowing a new web-application to be dropped, and reloaded if made possible by the servlet-container, without loosing information for the users of ActiveMath.

The temporary directory as defined by servlets 2.3 is used as main storage place (hence is NOT ASSUMED TO BE TEMPORARY !) in this setting, unless a property directories.webapp.stateStorage is given which is then considered to be an absolute path or a path relative to the activemathHome.

This class also achieves two overridings. Among others, it converts:

These values can be overriden by the web.xml (as context-init-parameter) and the override can be cancelled by setting the value to empty. All the log-messages in this class use the servlet-context's log and not the log4j log !

Version:

Field Summary
protected static Logger thisLogCat
           
 
Constructor Summary
ServletContextConfigurator(ServletContext context)
           
 
Method Summary
 void contextDestroyed(ServletContextEvent sce)
           
 void contextInitialized(ServletContextEvent sce)
           
 void run()
          Performs the needed configurations, returning if it has already run, if the system property activemath.home exists or if the manager is already initted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisLogCat

protected static Logger thisLogCat
Constructor Detail

ServletContextConfigurator

public ServletContextConfigurator(ServletContext context)
Method Detail

contextDestroyed

public void contextDestroyed(ServletContextEvent sce)
Specified by:
contextDestroyed in interface ServletContextListener

contextInitialized

public void contextInitialized(ServletContextEvent sce)
Specified by:
contextInitialized in interface ServletContextListener

run

public void run()
         throws IOException
Performs the needed configurations, returning if it has already run, if the system property activemath.home exists or if the manager is already initted.

This methods considers it has run even if errors appear.

Throws:
BadConfigurationException - if the Manager can't init
IOException - if some files are wrong (this may happen, e.g., when the servlet is loaded from an unexpanded war file)