com.ail.core.configure
Class ConfigurationHandler

java.lang.Object
  extended by com.ail.core.configure.ConfigurationHandler

public class ConfigurationHandler
extends java.lang.Object

Version:
$Revision: 1.19 $

Method Summary
 java.util.Collection<java.lang.String> getConfigurationNamespaceParent(ConfigurationOwner owner, CoreUser user, Core core)
          Return the namespace(s) of the configuration(s) which are the parent, grandparent, etc of this namespae As configurations optionally have "parent" configuration that they inherit from, this method returns a collection of namespaces with one element for each configuration in the hierarchy.
 java.util.Collection<java.lang.String> getConfigurationSources(ConfigurationOwner owner, CoreUser user, Core core)
          Return the source of the configuration being used by this instance of core.
 Group getGroup(java.lang.String name, ConfigurationOwner owner, CoreUser user, Core core)
          Fetch the named group the from current configuration.
static ConfigurationHandler getInstance()
          Get a reference to the instance of the handler.
 java.util.Collection<java.lang.String> getNamespaces()
          Fetch a list of all the namespaces that have configurations associated with them.
 java.util.Collection<ConfigurationSummary> getNamespacesHistorySummary(java.lang.String namespace)
          Fetch the details of all the elements in a namespaces history.
 java.util.Collection<ConfigurationSummary> getNamespacesSummary()
          Fetch the details of all the namespaces that have configurations associated with them.
 Parameter getParameter(java.lang.String paramName, ConfigurationOwner owner, CoreUser user, Core core)
          Fetch the named parameter from the current configuration.
 java.util.Properties getParametersAsProperties(java.lang.String name, ConfigurationOwner owner, CoreUser user, Core core)
          Fetch all the Parameters in a group and return them as a java.util.Properties.
 java.lang.String getParameterValue(java.lang.String paramName, ConfigurationOwner owner, CoreUser user, Core core)
          Get the value of a parameter by name.
 java.lang.String getParameterValue(java.lang.String paramName, java.lang.String defaultValue, ConfigurationOwner owner, CoreUser user, Core core)
          Return the value of a parameter or a default value if the parameter is undefined.
 XMLMapping getXMLMapping(ConfigurationOwner owner, CoreUser user, Core core)
          Locate and return the XMLMapping associated with a configuration.
 Configuration loadConfiguration(ConfigurationOwner owner, CoreUser user, Core core)
          Load (fetch and return) the configuration associated with the current namespace and versionEffectiveDate.
 Configuration loadConfiguration(java.lang.String namespace, CoreUser user, Core core)
          Load (fetch and return) the configuration associated with the current namespace and versionEffectiveDate.
static void reset()
          This method resets the ConfigurationHandlers internal cache.
static void reset(java.lang.String namespace)
          This method removes a specific namespace from the ConfigurationHandlers's internal cache.
 void saveConfiguration(ConfigurationOwner owner, Configuration config, Core core)
          Save (update/create) the configuration associated with the current namespace.
 void saveConfiguration(java.lang.String namespace, Configuration config, Core core)
          Save (update/create) the configuration associated with the current namespace.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConfigurationHandler getInstance()
Get a reference to the instance of the handler.


reset

public static void reset()
This method resets the ConfigurationHandlers internal cache. There really isn't really much benefit in clearing the cache, unless the system has undergone many many configuration changes to the point where the cache is holding too much memory hostage.

Aside from a performance hit, as configuration records are loaded 'on demand' over time, resetting the cache will have no harmful side effects.


reset

public static void reset(java.lang.String namespace)
This method removes a specific namespace from the ConfigurationHandlers's internal cache. This may be useful especially when dealing with undefined namespaces: If the configuration handler is asked to load a namespace but cannot find it, it caches the fact that the namespace is unknown - this prevents it from hitting the database every time the namespace is requested only to find it sill isn't there. However, there are times when when the caller needs to force a reload - for example when a namespace is first create.

Removing a namespace from the cache only has a very small performance hit.

Parameters:
namespace - The namespace to remove from the cache.

saveConfiguration

public void saveConfiguration(java.lang.String namespace,
                              Configuration config,
                              Core core)
Save (update/create) the configuration associated with the current namespace.

Parameters:
namespace - The configuration namespace to save this config under.
config - The configuration to save.
core - The instance of core making the request.

saveConfiguration

public void saveConfiguration(ConfigurationOwner owner,
                              Configuration config,
                              Core core)
Save (update/create) the configuration associated with the current namespace.

Parameters:
owner - The configuration owner.
config - The configuration to save.
core - The instance of core making the request.

loadConfiguration

public Configuration loadConfiguration(ConfigurationOwner owner,
                                       CoreUser user,
                                       Core core)
Load (fetch and return) the configuration associated with the current namespace and versionEffectiveDate.

Parameters:
owner - The Configuration owner.
user - The configuration user we're loading the config for.
core - The instance of Core making the request.

loadConfiguration

public Configuration loadConfiguration(java.lang.String namespace,
                                       CoreUser user,
                                       Core core)
Load (fetch and return) the configuration associated with the current namespace and versionEffectiveDate.

Parameters:
namespace - Namespace to load the configuration of.
owner - The Configuration owner.
core - The instance of Core making the request.

getNamespaces

public java.util.Collection<java.lang.String> getNamespaces()
Fetch a list of all the namespaces that have configurations associated with them.

Returns:
A Collection of String objects

getNamespacesSummary

public java.util.Collection<ConfigurationSummary> getNamespacesSummary()
Fetch the details of all the namespaces that have configurations associated with them.

Returns:
A collection of ConfigurationSummary objects.

getNamespacesHistorySummary

public java.util.Collection<ConfigurationSummary> getNamespacesHistorySummary(java.lang.String namespace)
Fetch the details of all the elements in a namespaces history.

Returns:
A collection of ConfigurationSummary objects.

getParameter

public Parameter getParameter(java.lang.String paramName,
                              ConfigurationOwner owner,
                              CoreUser user,
                              Core core)
Fetch the named parameter from the current configuration. The "current configuration" is defined by the namespace (from owner), and the version effective date taken from core. The parameter name may be dot separated indicating that the parameter is nested within one or more groups.

The core's own configuration is used as a back-stop. If the group being searched for is not in the namespace defined by the configuration owner, then the core's configuration is checked.

Parameters:
paramName - The name of the parameter to retrieve.
owner - The configuration owner
core - The instance of Core making the call.

getParameterValue

public java.lang.String getParameterValue(java.lang.String paramName,
                                          ConfigurationOwner owner,
                                          CoreUser user,
                                          Core core)
Get the value of a parameter by name. The name may be dot separated to drill down through nested groups. The following two bits of code are exactly equivalent with the exception that the second will not fail with a NullPointerException is "parameterName" is undefined:
String x=getParameter("parameterName").getValue();
String x=getParameterValue("parameterName");

Parameters:
paramName - Name of the parameter to fetch the value for
owner - The owning configuration
user - The user making the request
core - The core being used by the requester.
Returns:
Value of the parameter, or null if it is undefined.

getParameterValue

public java.lang.String getParameterValue(java.lang.String paramName,
                                          java.lang.String defaultValue,
                                          ConfigurationOwner owner,
                                          CoreUser user,
                                          Core core)
Return the value of a parameter or a default value if the parameter is undefined.

Parameters:
paramName - Name of the parameter to return the value of.
defaultValue - If the parameter is undefined return this instead
owner - The owning configuration
user - The user making the request
core - The core being used by the requester.
Returns:
The value of the parameter, of default if it is undefined.

getGroup

public Group getGroup(java.lang.String name,
                      ConfigurationOwner owner,
                      CoreUser user,
                      Core core)
Fetch the named group the from current configuration. The "current configuration" is defined by the namespace (taken from owner), and the versionEffectiveDate (taken from core). The group's name may be dot separated indicating that the group is nested within other groups.

The core's own configuration is used as a back-stop. If the group being searched for is not in the namespace defined by the configuration owner, then the core's configuration is checked.

Parameters:
owner - The configuration owner.
core - The instance of Core making the call.

getParametersAsProperties

public java.util.Properties getParametersAsProperties(java.lang.String name,
                                                      ConfigurationOwner owner,
                                                      CoreUser user,
                                                      Core core)
Fetch all the Parameters in a group and return them as a java.util.Properties. This is a utility method which returns the parameters in a named group and creates a Properties object with them. Each Parameter's name and value properties are mapped into a property in the Properties object.

If the group specified does not exist, null is returned. If the group does exist but contains no Parameters, an empty Properties object is returned.

Parameters:
name - The name of the group whose parameters will be used.
owner - The Configuration owner.
core - The instance of Core making the call.
Returns:
The parameters as properties, or null.

getConfigurationSources

public java.util.Collection<java.lang.String> getConfigurationSources(ConfigurationOwner owner,
                                                                      CoreUser user,
                                                                      Core core)
Return the source of the configuration being used by this instance of core. As configurations optionally have a "parent" configuration that they inherit from, this method returns a collection of sources with one element for each configuration in the hierarchy.

Parameters:
owner - The configuration's owner
user - The user asking for the source
core - The core being used - and who's source will be returned
Returns:
The sources from which the configuration was loaded.

getConfigurationNamespaceParent

public java.util.Collection<java.lang.String> getConfigurationNamespaceParent(ConfigurationOwner owner,
                                                                              CoreUser user,
                                                                              Core core)
Return the namespace(s) of the configuration(s) which are the parent, grandparent, etc of this namespae As configurations optionally have "parent" configuration that they inherit from, this method returns a collection of namespaces with one element for each configuration in the hierarchy.

Parameters:
owner - The configuration's owner
user - The user asking for the source
core - The core being used - and who's source will be returned
Returns:
The sources from which the configuration was loaded.

getXMLMapping

public XMLMapping getXMLMapping(ConfigurationOwner owner,
                                CoreUser user,
                                Core core)
Locate and return the XMLMapping associated with a configuration.

Parameters:
owner - The class owning the configuration
user - The class using the configuration
core - The core used by the user
Returns:
The XMLMapping, or null if none is defined.