edu.cmu.sphinx.util.props
Class ConfigurationManager

java.lang.Object
  extended by edu.cmu.sphinx.util.props.ConfigurationManager
All Implemented Interfaces:
java.lang.Cloneable

public class ConfigurationManager
extends java.lang.Object
implements java.lang.Cloneable

Manages a set of Configurables, their parametrization and the relationships between them. Configurations can be specified either by xml or on-the-fly during runtime.

See Also:
Configurable, PropertySheet

Constructor Summary
ConfigurationManager()
          Creates a new empty configuration manager.
ConfigurationManager(java.lang.String configFileName)
          Creates a new configuration manager.
ConfigurationManager(java.net.URL url)
          Creates a new configuration manager.
 
Method Summary
 void addConfigurable(java.lang.Class<? extends Configurable> confClass, java.lang.String name)
          Registers a new configurable to this configuration manager.
 void addConfigurable(java.lang.Class<? extends Configurable> confClass, java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> props)
          Registers a new configurable to this configuration manager.
 void addConfigurable(Configurable configurable, java.lang.String name)
          Adds an already instantiated Configurable to this configuration manager.
 void addConfigurationChangeListener(ConfigurationChangeListener l)
          Adds a new listener for configuration change events.
 void addSubConfiguration(ConfigurationManager subCM)
           
 void addSubConfiguration(ConfigurationManager subCM, boolean doOverrideComponents)
          Adds a subconfiguration to this instance by registering all subCM-components and all its global properties.
 java.lang.Object clone()
          Creates a deep copy of the given CM instance.
 boolean equals(java.lang.Object obj)
          Test wether the given configuration manager instance equals this instance in terms of same configuration.
 java.util.Collection<java.lang.String> getComponentNames()
          Returns all names of configurables registered to this instance.
 java.net.URL getConfigURL()
          Returns the url of the xml-configuration which defined this configuration or null if it was created dynamically.
 GlobalProperties getGlobalProperties()
          Returns a copy of the map of global properties set for this configuration manager.
 java.lang.String getGlobalProperty(java.lang.String propertyName)
          Returns a global property.
 GlobalProperty getGloPropReference(java.lang.String propertyName)
           
static
<C extends Configurable>
C
getInstance(java.lang.Class<C> targetClass)
          Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component.
static
<C extends Configurable>
C
getInstance(java.lang.Class<C> targetClass, java.util.Map<java.lang.String,java.lang.Object> props)
          Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component.
static
<C extends Configurable>
C
getInstance(java.lang.Class<C> targetClass, java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String compName)
          Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component.
 java.util.Collection<java.lang.String> getInstanceNames(java.lang.Class<? extends Configurable> type)
          Gets all instances that are of the given type.
 PropertySheet getPropertySheet(java.lang.String instanceName)
          Returns the property sheet for the given object instance
 java.util.List<PropertySheet> getPropSheets(java.lang.Class<? extends Configurable> confClass)
          Given a Configurable-class/interface, all property-sheets which are subclassing/implemting this class/interface are collected and returned.
 java.util.logging.Logger getRootLogger()
          Returns the root-logger of this configuration manager.
 java.lang.String getStrippedComponentName(java.lang.String propertyName)
           
 Configurable lookup(java.lang.String instanceName)
          Looks up a configurable component by name.
 void removeConfigurable(java.lang.String name)
          Removes a configurable from this configuration manager.
 void removeConfigurationChangeListener(ConfigurationChangeListener l)
          Removes a listener for configuration change events.
 void renameConfigurable(java.lang.String oldName, java.lang.String newName)
           
 void setGlobalProperty(java.lang.String propertyName, java.lang.String value)
          Sets a global property.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigurationManager

public ConfigurationManager()
Creates a new empty configuration manager. This constructor is only of use in cases when a system configuration is created during runtime.


ConfigurationManager

public ConfigurationManager(java.lang.String configFileName)
                     throws PropertyException
Creates a new configuration manager. Initial properties are loaded from the given URL. No need to keep the notion of 'context' around anymore we will just pass around this property manager.

Parameters:
configFileName - The location of the configuration file.
Throws:
PropertyException

ConfigurationManager

public ConfigurationManager(java.net.URL url)
                     throws PropertyException
Creates a new configuration manager. Initial properties are loaded from the given URL. No need to keep the notion of 'context' around anymore we will just pass around this property manager.

Parameters:
url - The location of the configuration file.
Throws:
PropertyException
Method Detail

getPropertySheet

public PropertySheet getPropertySheet(java.lang.String instanceName)
Returns the property sheet for the given object instance

Parameters:
instanceName - the instance name of the object
Returns:
the property sheet for the object.

getInstanceNames

public java.util.Collection<java.lang.String> getInstanceNames(java.lang.Class<? extends Configurable> type)
Gets all instances that are of the given type.

Parameters:
type - the desired type of instance
Returns:
the set of all instances

getComponentNames

public java.util.Collection<java.lang.String> getComponentNames()
Returns all names of configurables registered to this instance. The resulting set includes instantiated and noninstantiated components.

Returns:
all component named registered to this instance of ConfigurationManager

lookup

public Configurable lookup(java.lang.String instanceName)
                    throws InternalConfigurationException
Looks up a configurable component by name. Creates it if necessary

Parameters:
instanceName - the name of the component
Returns:
the compnent, or null if a component was not found.
Throws:
InternalConfigurationException - If the requested object could not be properly created, or is not a configurable object, or if an error occured while setting a component property.

getPropSheets

public java.util.List<PropertySheet> getPropSheets(java.lang.Class<? extends Configurable> confClass)
Given a Configurable-class/interface, all property-sheets which are subclassing/implemting this class/interface are collected and returned. No Configurable will be instantiated by this method.


addConfigurable

public void addConfigurable(java.lang.Class<? extends Configurable> confClass,
                            java.lang.String name)
Registers a new configurable to this configuration manager.

Parameters:
confClass - The class of the configurable to be instantiated and to be added to this configuration manager instance.
name - The desired lookup-name of the configurable
Throws:
java.lang.IllegalArgumentException - if the there's already a component with the same name registered to this configuration manager instance.

addConfigurable

public void addConfigurable(java.lang.Class<? extends Configurable> confClass,
                            java.lang.String name,
                            java.util.Map<java.lang.String,java.lang.Object> props)
Registers a new configurable to this configuration manager.

Parameters:
confClass - The class of the configurable to be instantiated and to be added to this configuration manager instance.
name - The desired lookup-name of the configurable
props - The properties to be used for component configuration
Throws:
java.lang.IllegalArgumentException - if the there's already a component with the same name registered to this configuration manager instance.

addConfigurable

public void addConfigurable(Configurable configurable,
                            java.lang.String name)
Adds an already instantiated Configurable to this configuration manager.

Parameters:
name - The desired lookup-instanceName of the configurable

renameConfigurable

public void renameConfigurable(java.lang.String oldName,
                               java.lang.String newName)

removeConfigurable

public void removeConfigurable(java.lang.String name)
Removes a configurable from this configuration manager.


addSubConfiguration

public void addSubConfiguration(ConfigurationManager subCM)
Parameters:
subCM - The subconfiguration that shouwld be to this instance

addSubConfiguration

public void addSubConfiguration(ConfigurationManager subCM,
                                boolean doOverrideComponents)
Adds a subconfiguration to this instance by registering all subCM-components and all its global properties.

Parameters:
subCM - The subconfiguration that shouwld be to this instance
doOverrideComponents - If true non-instantiated components will be overriden by elements of subCM even if already being registered to this CM-instance. The same holds for global properties.
Throws:
java.lang.RuntimeException - if an already instantiated component in this instance is redefined in subCM.

getGlobalProperties

public GlobalProperties getGlobalProperties()
Returns a copy of the map of global properties set for this configuration manager.


getGlobalProperty

public java.lang.String getGlobalProperty(java.lang.String propertyName)
Returns a global property.

Parameters:
propertyName - The name of the global property or null if no such property exists

getGloPropReference

public GlobalProperty getGloPropReference(java.lang.String propertyName)

getConfigURL

public java.net.URL getConfigURL()
Returns the url of the xml-configuration which defined this configuration or null if it was created dynamically.


setGlobalProperty

public void setGlobalProperty(java.lang.String propertyName,
                              java.lang.String value)
Sets a global property.

Parameters:
propertyName - The name of the global property.
value - The new value of the global property. If the value is null the property becomes removed.

getStrippedComponentName

public java.lang.String getStrippedComponentName(java.lang.String propertyName)

addConfigurationChangeListener

public void addConfigurationChangeListener(ConfigurationChangeListener l)
Adds a new listener for configuration change events.


removeConfigurationChangeListener

public void removeConfigurationChangeListener(ConfigurationChangeListener l)
Removes a listener for configuration change events.


equals

public boolean equals(java.lang.Object obj)
Test wether the given configuration manager instance equals this instance in terms of same configuration. This This equals implemenation does not care about instantiation of components.

Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a deep copy of the given CM instance.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getInstance

public static <C extends Configurable> C getInstance(java.lang.Class<C> targetClass)
                                          throws PropertyException
Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component.

Throws:
PropertyException

getInstance

public static <C extends Configurable> C getInstance(java.lang.Class<C> targetClass,
                                                     java.util.Map<java.lang.String,java.lang.Object> props)
                                          throws PropertyException
Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component. Default prarmeters will be overrided if a their names are containd in the given props-map

Throws:
PropertyException

getInstance

public static <C extends Configurable> C getInstance(java.lang.Class<C> targetClass,
                                                     java.util.Map<java.lang.String,java.lang.Object> props,
                                                     java.lang.String compName)
                                          throws PropertyException
Creates an instance of the given Configurable by using the default parameters as defined by the class annotations to parameterize the component. Default prarmeters will be overrided if a their names are containd in the given props-map. The component is used to create a parameterized logger for the Configurable being created.

Throws:
PropertyException

getRootLogger

public java.util.logging.Logger getRootLogger()
Returns the root-logger of this configuration manager. This method is just a convenience mapper around a few CMU calls.

Returns:
the root logger of this CM-instance