org.activemath.config
Class Manager

java.lang.Object
  extended by org.activemath.config.Manager

public class Manager
extends Object

A class to read configuration information from the configuration files and optionally offer the anchoring to factory methods that provide the implementation for standard interfaces of the abstractcontent package.

This class is filled with static calls and is meant to be called anywhere where the context is needed. In principle, loading this class should only initialize the load of the properties, any other service will be loaded on demand. As such, loading this class should only load standard classes and classes of the abstractcontent package.

In the current implementation, this reads the properties first from the classpath, the file

Manager.properties
aside of this compiled class, then, if
activemath.home
system property is set, from the file
conf/ActiveMath.properties
, then from the file
conf/ActiveMath-managed.properties
, then from the file
conf/ActiveMath-individual.properties
and finally from system preferences for one-time shell-based modification.

Information from this class is then used in almost every part of the ActiveMath servlet world and serves as a programmatic common-ground to access configuration.

Version:
0.8

Field Summary
protected static Matriculations matriculations
          The loaded matriculations table.
protected static Hashtable servlets
          The table of registred servlets
 
Constructor Summary
Manager()
           
 
Method Summary
static void clearChangedPropNames()
           
static String convertSlashesToSysDependent(String slashedPath)
          Converts the given path, separated with slashes to the system-dependent path.
static Object createConfiguredObject(String prefix)
          Constructs an object of class given by the value of the property of key prefixName+".class" expecting a constructor with one Map which is guaranteed to have keys and values as string, the result of getPropertySubtree(java.lang.String) on the given prefix.
static Object createConfiguredObject(Subconfiguration config)
           
static void createMathWebBrokerWrapper()
          Creates and stores a reference to the MathWebBrokerWrapper object as defined by the properties.
static void createMatriculations()
          Ininitalizes the Matriculations table from the class of name given by the property matriculations.class .
static void createMBaseRef()
          Creates and stores the reference to an MBaseRef implementing object as defined by the properties.
static void dumpProperties()
          Dumps the properties, ordered, to the Standard console
static void dumpProperties(String prefix)
          Dumps the properties with given prefix, ordered, to the standard-console.
static void dumpProperties(Writer wout, String prefix)
          Dumps the properties, ordered, to the indicated print-stream.
static void ensureProperties()
          Makes sure the props member-variable is not null otherwise invokes the init() method.
static File getActiveMathHome()
          Gets the activemath-home property, inits the manager if needed.
static String getAdvertizedLocalhostName()
          Computes the name of the localhost or takes it from the advertizedLocalhost property.
static URL getAdvertizedURL()
          User getAdvertizedLocalhostName() to compute the root URL of the webapp, supposed to be at host:8080/ActiveMath2/.
static Collection getChangedPropNames()
           
static OJSAXBuilder getDefaultJdomSaxBuilder()
          Returns a default SAXBuilder usable by anyone so that no uselss construction is made.
static MathWebBrokerWrapper getMathWebBroker()
          Returns the initialized MathWebBrokerWrapper, initializes it if needed.
static Matriculations getMatriculations()
          Gets the matriculations attribute of the Manager class
static MBaseRef getOfficialMBase()
          Returns the MBaseRef implementing class defined by the properties or null if none was defined.
static Collection getPackagesWithPrefix(String prefix)
          Returns the list of all second package name for a given prefix.
static File getPath(String key)
          Reads a path given as a property.
static String getProperty(String key)
          This uses the properties loaded from the Manager.properties file and many others (see loadProps() to respond a property in exchange of a string.
static String getProperty(String key, String dflt)
          Return a property with getProperty(java.lang.String) or the supplied default value if not set.
static Enumeration getPropertyNames()
          Missing description of the gets the propertyNames attribute of the Manager class
static Enumeration getPropertyNamesStartingWith(String prefix)
          Returns enumeration of the properties that start with the given prefix.
static Properties getPropertySubtree(String prefix)
          Gets the propertySubtree attribute of the Manager class
static String getRealPath(String path)
          Obtains the file-path given the servlet-path
static String getRealPath(String path, String defaultAnswer)
          Obtains the file-path given the servlet-path
static InputStream getResourceInputStream(String directoryName, String resourceName)
          This scans the directories properties and provides an InputStream for the given resource.
static Reader getResourceReader(String directoryName, String resourceName, String encodingName)
          The equivalent of the getResourceInputStream but using the standard encoding (if encodingName is null) or the given one.
static Object getService(String serviceInterfaceClassName)
          Returns one of the predefined services or one configured as in SubconfImpl.PropertiesConfig.
protected static Hashtable getServlets()
          Obtain the servlets table.
static Stylesheets getStylesheetProcessor()
          returns the reference to a stylesheet processor
static File getTempDir()
          Returns the temporary "work" directory.
static URL getURL(String key)
          Reads one URI from the property files.
static File getWebAppDir()
          Missing description of the gets the webAppDir attribute of the Manager class
static void init()
          This inits the configurations reading properties from the three properties files (Manager.properties in the jar, ActiveMath.properties in conf, and ActiveMath-individual.properties in conf.
static void initLog4J()
          This erases the previously set log4j configurations and then reads the file conf/log4j.properties to feed it to the org.log4j.PropertyConfigurator.
static boolean isInitted()
          Checks wether the init() method has already run.
static String[] listResources(String directoryName)
          This lists the resources in the directory.
static void loadProps()
           
static void main(String[] args)
          This method is for testing the configuration, it can be be given the argument of the initialization to perform and will try to perform it, providing an output targetted to detect the possible misconfigurations.
static Hashtable pathMap()
          Creates the pathMap used by the FileServlet which serves raw files, picked according to the recognized languages.
static void registerServlet(String sn)
          Registers the servlet in the list of initted servlet.
static Collection reloadProps()
           
static void reportFatalError(Throwable t, String message)
           
static void setActiveMathHome(File indicatedHome)
          Defines the variable activemathHome, used in many other places.
static void unregisterServlet(String sn)
          Removeds the servlet from the initted servlet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

servlets

protected static Hashtable servlets
The table of registred servlets


matriculations

protected static Matriculations matriculations
The loaded matriculations table.

Constructor Detail

Manager

public Manager()
Method Detail

setActiveMathHome

public static void setActiveMathHome(File indicatedHome)
Defines the variable activemathHome, used in many other places. A call to this method has to happen before any other method of this class is called as otherwise a fatal-error may appear for lack of ActiveMath-Home (e.g. resulting in an impossibility to access the session-storage or the the configuration files). Alternatively to call this method, the system-property activemath.home can be defined.

Parameters:
indicatedHome - the path (supposed absolute) to the directory ActiveMath-Home
Throws:
IllegalStateException - if the variable ActiveMath-Home is already defined.

isInitted

public static boolean isInitted()
Checks wether the init() method has already run.

Returns:
true if it has

getActiveMathHome

public static File getActiveMathHome()
Gets the activemath-home property, inits the manager if needed.

Returns:
The (possibly computed) activeMathHome property

getProperty

public static String getProperty(String key)
This uses the properties loaded from the Manager.properties file and many others (see loadProps() to respond a property in exchange of a string.

Parameters:
key - Missing description of Parameter
Returns:
the String of the property's content or null if there is no such property

getProperty

public static String getProperty(String key,
                                 String dflt)
Return a property with getProperty(java.lang.String) or the supplied default value if not set.

Parameters:
key - property key
dflt - default value if not set
Returns:
the String of the property's content or dflt if there is no such property

getPropertyNames

public static Enumeration getPropertyNames()
Missing description of the gets the propertyNames attribute of the Manager class

Returns:
Missing description of return The propertyNames value

getPropertyNamesStartingWith

public static Enumeration getPropertyNamesStartingWith(String prefix)
Returns enumeration of the properties that start with the given prefix. Stores its results in a Vector, so is inappropriate for very large properties file. To get the value of the property resulting of this enumeration, just use getProperty(java.lang.String)

Parameters:
prefix - the prefix for the properties
Returns:
an enumeration of names, including the prefix

getPackagesWithPrefix

public static Collection getPackagesWithPrefix(String prefix)
Returns the list of all second package name for a given prefix. That is to say, given properties with keys: a.b.x, a.b.z, a.b.y, a.c.y, a.c.z, it will return the collection b,c if queried for the prefix a.

This is used to enumerate all the groupings keys as well as the recbooks keys.

Parameters:
prefix - the prefix wished
Returns:
The list of possible add-ons after the prefix

getPropertySubtree

public static Properties getPropertySubtree(String prefix)
Gets the propertySubtree attribute of the Manager class

Parameters:
prefix - the prefix
Returns:
a new properties object containing the extracted properties

getRealPath

public static String getRealPath(String path)
Obtains the file-path given the servlet-path

Parameters:
path - the servlet-path
Returns:
the file-path corresponding to it

getRealPath

public static String getRealPath(String path,
                                 String defaultAnswer)
Obtains the file-path given the servlet-path

Parameters:
path - the servlet-path
defaultAnswer - the default path expected
Returns:
the file-path computed.

getOfficialMBase

public static MBaseRef getOfficialMBase()
Returns the MBaseRef implementing class defined by the properties or null if none was defined. Attempts to create it if necessary. The object is then null or the previous value if the initialization failed.

Returns:
The officialMBase value

getMathWebBroker

public static MathWebBrokerWrapper getMathWebBroker()
Returns the initialized MathWebBrokerWrapper, initializes it if needed.

Returns:
The mathWebBroker value

getDefaultJdomSaxBuilder

public static OJSAXBuilder getDefaultJdomSaxBuilder()
Returns a default SAXBuilder usable by anyone so that no uselss construction is made.

Returns:
The defaultJdomSaxBuilder value

getStylesheetProcessor

public static Stylesheets getStylesheetProcessor()
returns the reference to a stylesheet processor

Returns:
The stylesheetProcessor value

getTempDir

public static File getTempDir()
Returns the temporary "work" directory. This directory is defined by the property "directories.tempDir" which is obtained using getPath(java.lang.String). The existence (and writability) of this directory is ensured the first time this method is run.

Returns:
the temporary directory
Throws:
BadConfigurationError - if it is not possible to create a file in the given directory

getWebAppDir

public static File getWebAppDir()
Missing description of the gets the webAppDir attribute of the Manager class

Returns:
Missing description of return The webAppDir value

getURL

public static URL getURL(String key)
                  throws MalformedURLException
Reads one URI from the property files. If the property of this name starts with a "/" then file:/$activemath.home is appended to it..

Parameters:
key - The property key
Returns:
The URI value
Throws:
MalformedURLException - Missing description of Exception

getPath

public static File getPath(String key)
Reads a path given as a property. The difference with getProperty(String) is that the property is checked for a given leading slash, in which case it is appended the activemathHome variable's content, unless a property key + ".refType" is defined to be "absolute" or "inTemp" (the default being "inActiveMathHome").

If the refType is "absolute" the path is considered absolute, it is up to the configuration author to make sure that such a path can be read from or written to.

If the refType is "inTemp", the property "directories.tempDir" is used, presumably absolute but refTypes also apply, a path is made of it, then this property's path is appended to this one.

No security check is done, yet, about the possible ".." araising here.

Parameters:
key - the property key
Returns:
The path value, as an absolute path

getResourceInputStream

public static InputStream getResourceInputStream(String directoryName,
                                                 String resourceName)
                                          throws IOException,
                                                 MalformedURLException,
                                                 ClassNotFoundException
This scans the directories properties and provides an InputStream for the given resource. Directories can be

Parameters:
directoryName - the directory name
resourceName - the resource-name
Returns:
the input-stream of the given path
Throws:
IOException - if the inputStream cannot be opened or if the directory-name cannot be found from the properties.
MalformedURLException - if the URL was poor
ClassNotFoundException - when a class resource-identifier was used but is not found.

getResourceReader

public static Reader getResourceReader(String directoryName,
                                       String resourceName,
                                       String encodingName)
                                throws IOException,
                                       MalformedURLException,
                                       ClassNotFoundException
The equivalent of the getResourceInputStream but using the standard encoding (if encodingName is null) or the given one. There is currently no-support for in-stream or http-based encoding detection.

Parameters:
directoryName - the directory name
resourceName - the resource-name
encodingName - the encoding to use
Returns:
the input-stream of the given path
Throws:
IOException - if the inputStream cannot be opened or if the directory-name cannot be found from the properties.
MalformedURLException - if the URL was poor
ClassNotFoundException - when a class resource-identifier was used but is not found.

getMatriculations

public static Matriculations getMatriculations()
Gets the matriculations attribute of the Manager class

Returns:
The matriculations value

getService

public static Object getService(String serviceInterfaceClassName)
Returns one of the predefined services or one configured as in SubconfImpl.PropertiesConfig.


convertSlashesToSysDependent

public static String convertSlashesToSysDependent(String slashedPath)
Converts the given path, separated with slashes to the system-dependent path.

Parameters:
slashedPath - Missing description of Parameter
Returns:
the system-dependent path

listResources

public static String[] listResources(String directoryName)
This lists the resources in the directory. Only file-based directories can automatically listed, others (class and http ones) will have the properties read to get directories.list.directoryName out of which a white-space separated list is expected.

Parameters:
directoryName - the directory key-postfix
Returns:
the list of files in this directory

main

public static void main(String[] args)
This method is for testing the configuration, it can be be given the argument of the initialization to perform and will try to perform it, providing an output targetted to detect the possible misconfigurations.

It accepts the following arguments, the test(s) to invoke:

Parameters:
args - The command line arguments

init

public static void init()
This inits the configurations reading properties from the three properties files (Manager.properties in the jar, ActiveMath.properties in conf, and ActiveMath-individual.properties in conf. For it to work properly (hence for anything in ActiveMath to work properly), the ActiveMath-Home property has to be known.

If a system property "activemath.home" exists, it is used as an absolute path to the named directory. Otherwise it is expected that some other calls (for example, a servlet's init call) set this variable which can only be done once in the life of the class.


initLog4J

public static void initLog4J()
This erases the previously set log4j configurations and then reads the file
conf/log4j.properties
to feed it to the org.log4j.PropertyConfigurator. Note that this step is useless if the
conf
directory is already in the classpath which is highly recommended as otherwise some logging will appear before this method is called and the log4j package will complain that it was not configured, setting every priority to Priority.DEBUG, the most, much too much, verbose one.


dumpProperties

public static void dumpProperties()
Dumps the properties, ordered, to the Standard console


dumpProperties

public static void dumpProperties(String prefix)
Dumps the properties with given prefix, ordered, to the standard-console.

Parameters:
prefix - the prefix wished.

dumpProperties

public static void dumpProperties(Writer wout,
                                  String prefix)
Dumps the properties, ordered, to the indicated print-stream.

Parameters:
wout - the wished stream
prefix - the possible prefix (set to empty-string if not desired)

ensureProperties

public static void ensureProperties()
Makes sure the props member-variable is not null otherwise invokes the init() method.


getAdvertizedLocalhostName

public static String getAdvertizedLocalhostName()
Computes the name of the localhost or takes it from the advertizedLocalhost property.

Returns:
the host-name to be used to talk to us

getAdvertizedURL

public static URL getAdvertizedURL()
User getAdvertizedLocalhostName() to compute the root URL of the webapp, supposed to be at host:8080/ActiveMath2/. Override with property advertizedURL.

Returns:
URL the computed URL

createConfiguredObject

public static Object createConfiguredObject(Subconfiguration config)
                                     throws Exception
Throws:
Exception

createConfiguredObject

public static Object createConfiguredObject(String prefix)
                                     throws Exception
Constructs an object of class given by the value of the property of key prefixName+".class" expecting a constructor with one Map which is guaranteed to have keys and values as string, the result of getPropertySubtree(java.lang.String) on the given prefix.

This method is expected to be the standard way to construct objects that are of services. The argument-type of the constructor is expected to be of type Map instead of Properties so as to be able, later, to build prefix-wrappers that avoid storing the properties in memory again.

This method will be enriched with a support for shut-down able objects later.

Parameters:
prefix - the prefix to obtain a property subtree of
Returns:
the constructed object
Throws:
Exception - any exception in particular the ones returned by Class.forName(java.lang.String) and Constructor.newInstance(java.lang.Object...)
Since:
April 10th 2002

pathMap

public static Hashtable pathMap()
Creates the pathMap used by the FileServlet which serves raw files, picked according to the recognized languages.

Returns:
returns the table of maps

createMBaseRef

public static void createMBaseRef()
Creates and stores the reference to an MBaseRef implementing object as defined by the properties. Call getOfficialMBase() to get the actual object created here.

Calling this method after initialization of the Manager has occured will redirect all NEW calls to getOfficialMBase() to give the redirected one. The values to adjust for this purpose are in the system properties with the same names as the ActiveMath properties.


createMathWebBrokerWrapper

public static void createMathWebBrokerWrapper()
Creates and stores a reference to the MathWebBrokerWrapper object as defined by the properties. Call getMathWebBroker() to get the actual object. If this initialization fails, typically if the server does not respond, future attempts of calling getMathWebBroker will return null or the previous value.


registerServlet

public static void registerServlet(String sn)
Registers the servlet in the list of initted servlet.

Parameters:
sn - the name of the servlet

unregisterServlet

public static void unregisterServlet(String sn)
Removeds the servlet from the initted servlet.

Parameters:
sn - the name of the servlet

createMatriculations

public static void createMatriculations()
                                 throws Exception
Ininitalizes the Matriculations table from the class of name given by the property matriculations.class .

Throws:
Exception - Description of Exception

getServlets

protected static Hashtable getServlets()
Obtain the servlets table.

Returns:
the table, possibly initialized if needed

reportFatalError

public static void reportFatalError(Throwable t,
                                    String message)

getChangedPropNames

public static Collection getChangedPropNames()

clearChangedPropNames

public static void clearChangedPropNames()

reloadProps

public static Collection reloadProps()

loadProps

public static void loadProps()