public class ConfigurationManager
extends java.lang.Object
implements java.lang.Cloneable
Configurable
s, their parameterization and the relationships between them. Configurations
can be specified either by xml or on-the-fly during runtime.Configurable
,
PropertySheet
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
ConfigurationManager |
clone()
Creates a deep copy of the given CM instance.
|
boolean |
equals(java.lang.Object obj)
Test whether the given configuration manager instance equals this instance in terms of same configuration.
|
java.util.Set<java.lang.String> |
getComponentNames()
Returns all names of configurables registered to this instance.
|
java.net.URL |
getConfigURL() |
java.util.Map<java.lang.String,java.lang.String> |
getGlobalProperties() |
java.lang.String |
getGlobalProperty(java.lang.String propertyName)
Returns a global property.
|
java.lang.String |
getGloPropReference(java.lang.String propertyName) |
static <C extends Configurable> |
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> |
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> |
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) |
int |
hashCode() |
<C extends Configurable> |
lookup(java.lang.Class<C> confClass)
Returns a
Configurable instance of a given type C , if such a component (or a derived
one) is registered to this ConfigurationManager instance, and there is one and only match. |
<C extends 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.
|
public ConfigurationManager()
public ConfigurationManager(java.lang.String configFileName) throws PropertyException
configFileName
- The location of the configuration file.PropertyException
public ConfigurationManager(java.net.URL url) throws PropertyException
url
- The location of the configuration file.PropertyException
public PropertySheet getPropertySheet(java.lang.String instanceName)
instanceName
- the instance name of the objectpublic java.util.Collection<java.lang.String> getInstanceNames(java.lang.Class<? extends Configurable> type)
type
- the desired type of instancepublic java.util.Set<java.lang.String> getComponentNames()
ConfigurationManager
public <C extends Configurable> C lookup(java.lang.String instanceName) throws InternalConfigurationException
C
- component typeinstanceName
- the name of the componentInternalConfigurationException
- 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.public <C extends Configurable> C lookup(java.lang.Class<C> confClass)
Configurable
instance of a given type C
, if such a component (or a derived
one) is registered to this ConfigurationManager
instance, and there is one and only match.
This is a convenience method that allows to access a system configuration without knowing the instance names of registered components.
C
- A component typeconfClass
- class to lookupConfigurable
instance of null if there is no matching Configurable
.java.lang.IllegalArgumentException
- if more than one component of the given type is registered to this
ConfigurationManager.public java.util.List<PropertySheet> getPropSheets(java.lang.Class<? extends Configurable> confClass)
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.confClass
- class to lookuppublic void addConfigurable(java.lang.Class<? extends Configurable> confClass, java.lang.String name)
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 configurablejava.lang.IllegalArgumentException
- if the there's already a component with the same name
registered to
this configuration manager instance.public void addConfigurable(java.lang.Class<? extends Configurable> confClass, java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> props)
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 configurableprops
- The properties to be used for component configurationjava.lang.IllegalArgumentException
- if the there's already a component with the same name
registered to
this configuration manager instance.public void addConfigurable(Configurable configurable, java.lang.String name)
Configurable
to this configuration manager.configurable
- A configurable to addname
- The desired lookup-instanceName of the configurablepublic void renameConfigurable(java.lang.String oldName, java.lang.String newName)
public void removeConfigurable(java.lang.String name)
name
- a name to removepublic void addSubConfiguration(ConfigurationManager subCM)
subCM
- The subconfiguration that should be to this instancepublic void addSubConfiguration(ConfigurationManager subCM, boolean doOverrideComponents)
subCM
- The subconfiguration that should be to this instancedoOverrideComponents
- If true
non-instantiated components will be overridden by elements of
subCM even if already being registered to this CM-instance. The same holds for global
properties.java.lang.RuntimeException
- if an already instantiated component in this instance is redefined in subCM.public java.util.Map<java.lang.String,java.lang.String> getGlobalProperties()
public java.lang.String getGlobalProperty(java.lang.String propertyName)
propertyName
- The name of the global property or null
if no such property existspublic java.lang.String getGloPropReference(java.lang.String propertyName)
public java.net.URL getConfigURL()
null
if it was created
dynamically.public void setGlobalProperty(java.lang.String propertyName, java.lang.String value)
propertyName
- The name of the global property.value
- The new value of the global property. If the value is null
the property becomes
removed.public java.lang.String getStrippedComponentName(java.lang.String propertyName)
public void addConfigurationChangeListener(ConfigurationChangeListener l)
l
- listener to addpublic void removeConfigurationChangeListener(ConfigurationChangeListener l)
l
- listener to removepublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public ConfigurationManager clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public static <C extends Configurable> C getInstance(java.lang.Class<C> targetClass) throws PropertyException
Configurable
by using the default parameters as defined by the
class annotations to parameterize the component.C
- component classtargetClass
- target classPropertyException
- if no such class is definedpublic static <C extends Configurable> C getInstance(java.lang.Class<C> targetClass, java.util.Map<java.lang.String,java.lang.Object> props) throws PropertyException
Configurable
by using the default parameters as defined by the
class annotations to parameterize the component. Default parameters will be overridden if a their names are
contained in the given props
-mapC
- component classtargetClass
- target classprops
- additional propertiesPropertyException
- if no such class is definedpublic 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
Configurable
by using the default parameters as defined by the
class annotations to parameterize the component. Default parameters will be overridden if a their names are
contained in the given props
-map. The component is used to create a parameterized logger for the
Configurable being created.C
- component classtargetClass
- target classprops
- additional propertiescompName
- component namePropertyException
- if no such class is definedpublic java.util.logging.Logger getRootLogger()