Expresso 5-6

com.jcorporate.expresso.core.misc
Class ConfigManager

java.lang.Object
  extended bycom.jcorporate.expresso.core.misc.ConfigManager

public final class ConfigManager
extends Object

ConfigManager is a static class that utilizes the Struts Digester utility to read an XML file of configuration parameters when Expresso starts up. These parameters are then available during the execution of the application.

Author:
Adam Rossi

Field Summary
static String EXPRESSO_DTD_COPY_LOCATION
          constant path for DTD file; we expect DTD to be placed here, probably by a ANT copy before running servlet engine searched relative to class dir
static String LOG_DIR_PARAM_NAME
          name of servlet param which controls logging directory
 
Constructor Summary
ConfigManager()
          Default Constructer
 
Method Summary
static void addSession(CurrentLogin newLogin)
          Adds to the 'we have X many logins' hashtable.
static void checkInitialized(HttpServletRequest req, ServletConfig c)
          Check if the configuration info needs to be read, and read it if so.
static void config(ServletConfig c)
          Called by the initial load servlet to initialize the entire system
static void dbInitialize()
          Initialize our database pool(s)
static void dbUninitialize()
          Remove our database pool(s)

Closes all connections so that Hypersonic can handle multiple test suites from multiple VM's thrown at it as long as each test suite calls dbUninitialize in the teardown method.

static void destroy()
          Call this to destroy all items that ConfigManager uses.
static String expandValue(String propValue)
          Method to "expand" some simple "macro" codes allowed in property file and Setup values.
static org.apache.struts.config.ForwardConfig findForwardConfig(org.apache.struts.config.ActionConfig oneConfig, String stateName)
          Find a forward config given an action config and a state name Does not return higher level forwards, just the one for the given state IF it exists
static org.apache.struts.config.ActionConfig getActionConfig(String controllerName, String stateName)
          Gets the action mapping associated with the controller and default root module.
static org.apache.struts.config.ActionConfig getActionConfig(String moduleName, String controllerName, String stateName)
          Gets the action mapping associated with the controller and the module name.
static List getActionConfigList(String controllerName)
          Gets all the action mappings associated with the controller and the default module.
static List getActionConfigList(String moduleName, String controllerName)
          Gets all the action mappings associated with the controller and the module name.
static Enumeration getAllConfigKeys()
          Return an enumeration of all of the valid configuration keys.
static Hashtable getAllJobHandlers()
          Gets all job handlers in the system
static String getClassHandler(String handlerName)
          Return the Class dealing with the named ClassHandler
static String getClassHandlerParameter(String handlerName, String parameter)
          Returns the given parameter for a class handler.
static ConfigExpresso getConfig()
          Return the top-level configuration object, an instance of the ConfigExpresso class.
static String getConfigDir()
          Return the pathname of the configuration directory (specified as "configDir"
static HashMap getConfigInputSources(String filterDocType)
          Returns a hashmap keyed by filename, and data ='s a series of input streams corresponding to xml files of the desired doctype.
static Throwable getConfigurationFailureException()
           
static ConfigContext getContext(String contextName)
          Return the context configuration object for the named context.
static String getContextPath()
          Get the web-app context path for this web application
static ControllerFactory getControllerFactory()
          Returns the controller factory object.
static Hashtable getCurrentLogins()
          Returns a hashtable of the current login objects
static ConfigManager getInstance()
          Return the reference instance of the config manager Use this in preference to the singleton APIs.
static ConfigJdbc getJdbc(String contextName)
          Get the Jdbc configuration (if any) for the named context
static ConfigJdbc getJdbcRequired(String contextName)
          Get a Jdbc configuration object, throwing an exception if there is not one for the specified context
static JobHandler getJobHandler(String contextName)
          Returns a specific job handler.
static org.apache.struts.action.ActionMapping getMapping(String controllerName, String stateName)
          Deprecated. this method is now deprecated and does no anything since Struts 1.1 getActionConfig(String moduleName, String controllerName, String stateName )
static String getOtherDbLocation(String dbName, String objectName)
          Get the cached "other db" location for a specific object Creation date: (1/5/01 6:57:06 PM) author: Adam Rossi, PlatinumSolutions
static Hashtable getOtherDBLocations()
          Return a cloned Hashtable containing all of the DBOtherMap entries author Adam Rossi, PlatinumSolutions
static String getServletAPIVersion()
          Queries the current servletAPI defined in the configuration system
static String getWebAppDir()
          Get the actual filesystem directory that is the root of this web-app
static void initializeAllDBObjects()
          Iterate through all schemas and instantiate a DBObject.
protected static void initializeOneSchema(String className)
           
static boolean isInitialized()
          Is the ConfigManager initialized yet?
static boolean isParameterReservedWord(String testWord)
          Checks to see if a controller parameter may be a reserved word.
static boolean isReservedWord(String testWord)
          Checks to see if any given field or tablename fed to this qualifies as a known reserved word for various databases.
static void load(String theConfigDir)
          "Second stage" configuration.
static void mapOtherDBs()
          Map otherdb locations into a hashtable stored in memory.
static void reInitialize(HttpServletRequest req, ServletConfig c)
          Re-read all properties and other values, re-initialize everything
static void removeSession(String sessionId)
          Removes a stored session.
static void setConfigurationFailureException(Throwable ee)
           
static void setContextPath(String newContextPath)
          Set the "context path" - this is used for translating the %context% 'macro' that can be used in property and setup values
static void setControllerFactory(ControllerFactory cf)
          set the controller factory to use.
protected  void setDigesterRules(ConfigExpresso myConfig, org.apache.commons.digester.Digester digester)
          Set up the rules for the digester
static void setRequest(HttpServletRequest req)
          This function is used by webservers to set global variables such as server prefix, or context path.
protected  void setSAXParser()
           
static void setWebAppDir(String newDir)
          Set the "Web application directory" - this is used for translating the %web-app% 'macro' that can be used in property and setup values
static void startJobHandler()
          Start job handlers The job handler for each DB context is started if the appropriate configuration entry is found for that context
protected  void stopJobHandler()
          Stops all job handlers
static void storeModuleActionConfig(org.apache.struts.config.ModuleConfig moduleConfig)
          Store the action mappings per module to allow fast reverse based lookup based on the controller name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPRESSO_DTD_COPY_LOCATION

public static final String EXPRESSO_DTD_COPY_LOCATION
constant path for DTD file; we expect DTD to be placed here, probably by a ANT copy before running servlet engine searched relative to class dir

See Also:
Constant Field Values

LOG_DIR_PARAM_NAME

public static final String LOG_DIR_PARAM_NAME
name of servlet param which controls logging directory

See Also:
Constant Field Values
Constructor Detail

ConfigManager

public ConfigManager()
Default Constructer

Method Detail

addSession

public static void addSession(CurrentLogin newLogin)
Adds to the 'we have X many logins' hashtable.

Parameters:
newLogin - the new login

setConfigurationFailureException

public static void setConfigurationFailureException(Throwable ee)

getConfigurationFailureException

public static Throwable getConfigurationFailureException()

removeSession

public static void removeSession(String sessionId)
Removes a stored session. Used for tracking the number of people currently logged in.

Parameters:
sessionId - the session id that we are receiving the signal for

getCurrentLogins

public static Hashtable getCurrentLogins()
Returns a hashtable of the current login objects

Returns:
a Hashtable containing everybody logged in.

getJobHandler

public static JobHandler getJobHandler(String contextName)
Returns a specific job handler.

Parameters:
contextName - The dbcontext to get the jobhandler from. ex: default
Returns:
the JobHandler for that specific context

getAllJobHandlers

public static Hashtable getAllJobHandlers()
Gets all job handlers in the system

Returns:
a hashtable of all Job Handlers

getServletAPIVersion

public static String getServletAPIVersion()
Queries the current servletAPI defined in the configuration system

Returns:
A string listing the current servletAPIVersion being used

dbUninitialize

public static void dbUninitialize()
                           throws DBException
Remove our database pool(s)

Closes all connections so that Hypersonic can handle multiple test suites from multiple VM's thrown at it as long as each test suite calls dbUninitialize in the teardown method.

Throws:
DBException

destroy

public static void destroy()
Call this to destroy all items that ConfigManager uses. Initially not everythiny is implemented. Must be tested If there is an error the system prints a stack trace to System.err instead of the log since logging may have shut down by now.


dbInitialize

public static void dbInitialize()
                         throws ConfigurationException
Initialize our database pool(s)

Throws:
ConfigurationException - if there is an error getting the config values from the config beans.

initializeAllDBObjects

public static void initializeAllDBObjects()
Iterate through all schemas and instantiate a DBObject. Yes, this by and large may get thrown away later, but constructing blank objects allows various objects to set up listener relations with other classes. This is especially important for UserListener information.


initializeOneSchema

protected static void initializeOneSchema(String className)

getAllConfigKeys

public static Enumeration getAllConfigKeys()
Return an enumeration of all of the valid configuration keys. There is one key for each property file read.

Returns:
java.util.Enumeration

getInstance

public static ConfigManager getInstance()
Return the reference instance of the config manager Use this in preference to the singleton APIs. So now you have: ConfigManager.getInstace().getLogDirectory() for instance. instead of ConfigManager.getLogDirectory();

Returns:
an instance of ConfigManager

isInitialized

public static boolean isInitialized()
Is the ConfigManager initialized yet?

Returns:
true if the xml configuration parsed correctly

getConfig

public static ConfigExpresso getConfig()
Return the top-level configuration object, an instance of the ConfigExpresso class. This class contains all the setup options common to all contexts

Returns:
a ConfigExpresso bean

getConfigInputSources

public static HashMap getConfigInputSources(String filterDocType)
                                     throws ConfigurationException
Returns a hashmap keyed by filename, and data ='s a series of input streams corresponding to xml files of the desired doctype. All files are located in the Expresso configuration directory

Parameters:
filterDocType - - The doctype that you need for configuration files
Returns:
HashMap of InputSources of xml files of the appropriate types.
Throws:
ConfigurationException - if an error occurs while checking xml file types

getContext

public static ConfigContext getContext(String contextName)
                                throws ConfigurationException
Return the context configuration object for the named context. This object contains all of the configuration info for a specific context/database

Parameters:
contextName - the data context to retrieve the configuration information for
Returns:
the ConfigContextBean for the data context specified
Throws:
ConfigurationException - if there's an error retrieving the ConfigContext bean for the specified context

getClassHandler

public static String getClassHandler(String handlerName)
Return the Class dealing with the named ClassHandler

Parameters:
handlerName - the 'service name' of the classhandler to retrieve
Returns:
the name of the class to use for this 'category'

getClassHandlerParameter

public static String getClassHandlerParameter(String handlerName,
                                              String parameter)
Returns the given parameter for a class handler.

Parameters:
handlerName - the 'service name' of the classhandler to retrieve
parameter - The name of the parameter to get
Returns:
the value of the parameter for this class handler

getJdbc

public static ConfigJdbc getJdbc(String contextName)
                          throws ConfigurationException
Get the Jdbc configuration (if any) for the named context

Parameters:
contextName - the data context to get the JDBC configuration bean for
Returns:
a ConfigJdbc Configuration Bean
Throws:
ConfigurationException - if there is an error retrieving the context

getJdbcRequired

public static ConfigJdbc getJdbcRequired(String contextName)
                                  throws ConfigurationException
Get a Jdbc configuration object, throwing an exception if there is not one for the specified context

Parameters:
contextName - the data context to get the JDBC configuration bean for
Returns:
a ConfigJdbc Configuration Bean
Throws:
ConfigurationException - if there is an error retrieving the context

getWebAppDir

public static String getWebAppDir()
Get the actual filesystem directory that is the root of this web-app

Returns:
The filesystem directory that is the root of this webapp.

isReservedWord

public static boolean isReservedWord(String testWord)
Checks to see if any given field or tablename fed to this qualifies as a known reserved word for various databases.

Parameters:
testWord - The word to check against the list of known reserved words.
Returns:
true if the test word is a reserved word.

isParameterReservedWord

public static boolean isParameterReservedWord(String testWord)
Checks to see if a controller parameter may be a reserved word. This helps prevent any weird behavior when posting objects.

Parameters:
testWord - The word to check against the list of known reserved words.
Returns:
true if the test word is a reserved word.

startJobHandler

public static void startJobHandler()
                            throws ConfigurationException
Start job handlers The job handler for each DB context is started if the appropriate configuration entry is found for that context

Throws:
ConfigurationException - if there's a config error reading job values or getting job values for a particular context.

stopJobHandler

protected void stopJobHandler()
                       throws ConfigurationException
Stops all job handlers

Throws:
ConfigurationException - if there's an error getting the config information beans.

setWebAppDir

public static void setWebAppDir(String newDir)
Set the "Web application directory" - this is used for translating the %web-app% 'macro' that can be used in property and setup values

Parameters:
newDir - the new directory for the webAppDirectory 'environment variable'

setContextPath

public static void setContextPath(String newContextPath)
Set the "context path" - this is used for translating the %context% 'macro' that can be used in property and setup values

Parameters:
newContextPath - the new contextPath value to use

setControllerFactory

public static void setControllerFactory(ControllerFactory cf)
set the controller factory to use.

Parameters:
cf - the new Controller Factory to use for the running system.
See Also:
for an example use of this.

getContextPath

public static String getContextPath()
Get the web-app context path for this web application

Returns:
the context path string.

config

public static void config(ServletConfig c)
                   throws ServletException
Called by the initial load servlet to initialize the entire system

Parameters:
c - The servlet engine configuration
Throws:
ServletException - Servlet exception if an error occurs initializing the configuration system.

load

public static void load(String theConfigDir)
                 throws DBException,
                        ConfigurationException
"Second stage" configuration. Programs not running in the servlet environment can call this method with a configuration directory directly in order to set up Expresso. In a servlet environment, load gets called from "config" above.

Parameters:
theConfigDir - The directory to load all config files from.
Throws:
DBException
ConfigurationException

expandValue

public static String expandValue(String propValue)
Method to "expand" some simple "macro" codes allowed in property file and Setup values.

Parameters:
propValue - The 'property value' to expand.
Returns:
The 'expanded' value of the property value

getConfigDir

public static String getConfigDir()
Return the pathname of the configuration directory (specified as "configDir"

Returns:
The configuration directory that is used by expresso

getControllerFactory

public static ControllerFactory getControllerFactory()
Returns the controller factory object. Instantiates the default controller factory if one doesn't exist.

Returns:
a ControllerFactory object to use for instantiating controllers

getOtherDbLocation

public static String getOtherDbLocation(String dbName,
                                        String objectName)
Get the cached "other db" location for a specific object Creation date: (1/5/01 6:57:06 PM) author: Adam Rossi, PlatinumSolutions

Parameters:
dbName - java.lang.String
objectName - the name to located
Returns:
A String giving the data context for the other location

getOtherDBLocations

public static Hashtable getOtherDBLocations()
Return a cloned Hashtable containing all of the DBOtherMap entries author Adam Rossi, PlatinumSolutions

Returns:
java.util.Hashtable

mapOtherDBs

public static void mapOtherDBs()
                        throws ConfigurationException
Map otherdb locations into a hashtable stored in memory.

Creation date: (1/5/01 6:48:11 PM) author: Adam Rossi, PlatinumSolutions

Throws:
ConfigurationException - if there is an error mapping these other databases.

reInitialize

public static void reInitialize(HttpServletRequest req,
                                ServletConfig c)
                         throws ServletException
Re-read all properties and other values, re-initialize everything

Parameters:
req - The servlet request to use
c - The servlet config handed to us in the init() method.
Throws:
ServletException

checkInitialized

public static void checkInitialized(HttpServletRequest req,
                                    ServletConfig c)
                             throws ServletException
Check if the configuration info needs to be read, and read it if so.
Immediately returns if the config manager has already been initialized successfully.
Any servlet can check this to make sure Expresso has been started up successfully - if not, it calls load as needed to perform/re-perform the startup.

Parameters:
req - The servlet request given by the servlet container
c - The servlet configuration
Throws:
ServletException

setRequest

public static void setRequest(HttpServletRequest req)
This function is used by webservers to set global variables such as server prefix, or context path. This is usually set by checkLogin(), or any other first pages that are reached.

Parameters:
req - a HttpServletRequest

storeModuleActionConfig

public static void storeModuleActionConfig(org.apache.struts.config.ModuleConfig moduleConfig)
Store the action mappings per module to allow fast reverse based lookup based on the controller name.

It is possible that the same controller is used across action mappings and also across module (sub applications). So this data structure takes account of the multiple mappings to module names and save a list of possible action mappings related to a controller class name.

PLEASE NOTE from Struts 1.1 the old org.apache.struts.action.ActionMapping is deprecated and has been replaced with org.apache.struts.config.ActionConfig which is part of org.apache.struts.config.ModuleConfig


getActionConfig

public static org.apache.struts.config.ActionConfig getActionConfig(String controllerName,
                                                                    String stateName)
Gets the action mapping associated with the controller and default root module. Perform a 'reverse-mapping', that is, locate a Struts action mapping by looking for the given controller name (and optional state name)

Parameters:
controllerName - the classname of the controller to look up.
stateName - the name of the state to lookup within that controller
Returns:
the ActionConfig associated with the parameters specified
See Also:
getActionConfig( String,String,String )

getActionConfig

public static org.apache.struts.config.ActionConfig getActionConfig(String moduleName,
                                                                    String controllerName,
                                                                    String stateName)
Gets the action mapping associated with the controller and the module name. Perform a 'reverse-mapping', that is, locate a Struts action mapping by looking for the given controller name (and optional state name). If the stateName is null this method will attempt to dynamically load the controller class, instantiate an object instance and retrieve the controller class's initial state.

The action mapping is determined by looking at ActionConfig records in Struts configuration, retrieving all the local action forward and comparing its name to the state forward. This means that in your Struts XML configuration you must define a local action forward with the same name as the state Method.

If no action mapping can be determined by�looking for a particular matching local action forward, then the first action mapping is returned if exists. Please note the first action mapping is not necessarily the first action mapping declared in the XML configuration. This cannot be guaranteed, because the implementation may changed in the future.

  <action path="/Register"
 		type="com.jcorporate.expresso.services.controller.SimpleRegistration"
 		name="default" scope="request" validate="false" >
          <forward name="showDBMenu"
 			path="/expresso/jsp/register/dbmenu.jsp" />
          <forward name="promptAddRecord"
 			path="/expresso/jsp/register/regAdd.jsp" />
          <forward name="promptUpdateRecord"
 			path="/expresso/jsp/register/regAdd.jsp" />
 		...
 </action>
 
 

In order for the above action mapping "/Register" to be returned then you need to declare a unique local action forward name, if you use the same controller class for multiple actions. For example "showDBMenu" could be the unique local forward.

Parameters:
moduleName - the Struts module name
controllerName - the classname of the controller to look up.
stateName - the name of the state to lookup within that controller
Returns:
the ActionConfig associated with the parameters specified
See Also:
storeModuleActionConfig( ModuleConfig moduleConfig)

findForwardConfig

public static final org.apache.struts.config.ForwardConfig findForwardConfig(org.apache.struts.config.ActionConfig oneConfig,
                                                                             String stateName)
Find a forward config given an action config and a state name Does not return higher level forwards, just the one for the given state IF it exists

Parameters:
oneConfig - the ActionConfig for the controller
stateName - the state name for the controller
Returns:
ForwardConfig instance for that parameter combination

getActionConfigList

public static List getActionConfigList(String controllerName)
Gets all the action mappings associated with the controller and the default module. Perform a 'reverse-mapping', that is, locate a Struts action mappings by looking for the given controller name.

Parameters:
controllerName - the classname of the controller to look up.
Returns:
the ActionConfig associated with the parameters specified
See Also:
getActionConfigList( String,String )

getActionConfigList

public static List getActionConfigList(String moduleName,
                                       String controllerName)
Gets all the action mappings associated with the controller and the module name. Perform a 'reverse-mapping', that is, locate a Struts action mapping by looking for the given controller name.

Parameters:
moduleName - the Struts module name
controllerName - the classname of the controller to look up.
Returns:
the ActionConfig list associated with the parameters specified
See Also:
storeModuleActionConfig( ModuleConfig moduleConfig)

getMapping

public static org.apache.struts.action.ActionMapping getMapping(String controllerName,
                                                                String stateName)
Deprecated. this method is now deprecated and does no anything since Struts 1.1 getActionConfig(String moduleName, String controllerName, String stateName )

Perform a 'reverse-mapping', that is, locate a Struts action mapping by looking for the given controller name (and optional state name)

Parameters:
controllerName - the classname of the controller to look up.
stateName - the name of the state to lookup within that controller
Returns:
the ActionMapping associated with the parameters specified

setDigesterRules

protected void setDigesterRules(ConfigExpresso myConfig,
                                org.apache.commons.digester.Digester digester)
Set up the rules for the digester

Parameters:
myConfig - The root of the bean accepting the digester input
digester - an instantiated Digester ready to accept the rules.

setSAXParser

protected void setSAXParser()

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.