Class CommonsConfigurationRegistry
- java.lang.Object
-
- org.apache.archiva.redback.common.config.acc2.CommonsConfigurationRegistry
-
- All Implemented Interfaces:
ConfigRegistry
@Service("acc2-configuration") public class CommonsConfigurationRegistry extends Object implements ConfigRegistry
Implementation of the registry component using Commons Configuration 2. The use of Commons Configuration enables a variety of sources to be used, including XML files, properties, JNDI, JDBC, etc. The component can be configured using thecombinedConfigurationDefinition
configuration item, the content of which should take the format of an input to the Commons Configuration configuration builder.
-
-
Constructor Summary
Constructors Constructor Description CommonsConfigurationRegistry()
CommonsConfigurationRegistry(org.apache.commons.configuration2.CombinedConfiguration configuration, org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder configurationBuilder)
CommonsConfigurationRegistry(org.apache.commons.configuration2.Configuration configuration, org.apache.commons.configuration2.builder.ConfigurationBuilder<? extends org.apache.commons.configuration2.Configuration> configurationBuilder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfigurationFromFile(String name, Path file)
Load configuration from the given file.void
addConfigurationFromFile(String name, Path file, String prefix)
Load configuration from the given file.void
addConfigurationFromResource(String name, String resource)
Load configuration from the given classloader resource.void
addConfigurationFromResource(String name, String resource, String prefix)
Load configuration from the given classloader resource.String
dump()
Dump the entire registry to a string, for debugging purposes.Collection<String>
getBaseKeys()
Get all keys on the base level in this registry.boolean
getBoolean(String key)
Get a boolean value from the registry.boolean
getBoolean(String key, boolean defaultValue)
Get a boolean value from the registry.org.apache.commons.configuration2.builder.ConfigurationBuilder<? extends org.apache.commons.configuration2.Configuration>
getConfigurationBuilder()
int
getInt(String key)
Get an integer value from the registry.int
getInt(String key, int defaultValue)
Get an integer value from the registry.Collection<String>
getKeys()
Get all the keys in this registry.Collection<String>
getKeys(String prefix)
Return the keys that match the given prefix.List<String>
getList(String key)
Get a list of strings at the given key in the registry.ConfigRegistry
getPartOfCombined(String name)
Get a configuration source part of the registry, identified by the given name.Map<String,String>
getProperties(String key)
Get the properties at the given key in the registry.String
getPropertyDelimiter()
String
getString(String key)
Get a string value from the registry.String
getString(String key, String defaultValue)
Get a string value from the registry.ConfigRegistry
getSubset(String key)
Get a subset of the registry, for all keys descended from the given key.List<ConfigRegistry>
getSubsetList(String key)
Get a list of subsets of the registry, for all keys descended from the given key.Object
getValue(String key)
Get the original value stored in the registry.void
initialize()
Initializes the given registry.boolean
isAddSystemProperties()
Returns true, if the system properties are added to the base configuration.boolean
isEmpty()
Determine if the registry contains any elements.void
registerChangeListener(RegistryListener listener, String prefix)
Register a change listener for configuration keys that match the given patterns.void
remove(String key)
Remove a keyed element from the registry.void
removeSubset(String key)
Remove a keyed subset of the registry.void
save()
Save any changes to the registry since it was loaded.void
setAddSystemProperties(boolean addSystemProperties)
Set to true, if the system properties should be added to the base configuration.void
setBoolean(String key, boolean value)
Set a boolean value in the registry.void
setCombinedConfigurationDefinition(String combinedConfigurationDefinition)
void
setConfiguration(org.apache.commons.configuration2.Configuration configuration)
void
setInt(String key, int value)
Set an integer value in the registry.void
setPropertyDelimiter(String propertyDelimiter)
void
setString(String key, String value)
Set a string value in the registry.boolean
unregisterChangeListener(RegistryListener listener)
Unregister the change listener for all events.
-
-
-
Constructor Detail
-
CommonsConfigurationRegistry
public CommonsConfigurationRegistry()
-
CommonsConfigurationRegistry
public CommonsConfigurationRegistry(org.apache.commons.configuration2.CombinedConfiguration configuration, org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder configurationBuilder)
-
CommonsConfigurationRegistry
public CommonsConfigurationRegistry(org.apache.commons.configuration2.Configuration configuration, org.apache.commons.configuration2.builder.ConfigurationBuilder<? extends org.apache.commons.configuration2.Configuration> configurationBuilder)
-
-
Method Detail
-
setConfiguration
public void setConfiguration(org.apache.commons.configuration2.Configuration configuration)
-
dump
public String dump()
Description copied from interface:ConfigRegistry
Dump the entire registry to a string, for debugging purposes.- Specified by:
dump
in interfaceConfigRegistry
- Returns:
- the registry contents
-
isEmpty
public boolean isEmpty()
Description copied from interface:ConfigRegistry
Determine if the registry contains any elements.- Specified by:
isEmpty
in interfaceConfigRegistry
- Returns:
- whether the registry contains any elements
-
getSubset
public ConfigRegistry getSubset(String key) throws RegistryException
Description copied from interface:ConfigRegistry
Get a subset of the registry, for all keys descended from the given key.- Specified by:
getSubset
in interfaceConfigRegistry
- Parameters:
key
- the key to take the subset from- Returns:
- the registry subset
- Throws:
RegistryException
-
getList
public List<String> getList(String key)
Description copied from interface:ConfigRegistry
Get a list of strings at the given key in the registry. If not found a empty list will be returned.- Specified by:
getList
in interfaceConfigRegistry
- Parameters:
key
- the key to lookup- Returns:
- the list of strings
-
getSubsetList
public List<ConfigRegistry> getSubsetList(String key) throws RegistryException
Description copied from interface:ConfigRegistry
Get a list of subsets of the registry, for all keys descended from the given key.- Specified by:
getSubsetList
in interfaceConfigRegistry
- Parameters:
key
- the key to take the subsets from- Returns:
- the registry subsets
- Throws:
RegistryException
-
getPartOfCombined
public ConfigRegistry getPartOfCombined(String name)
Description copied from interface:ConfigRegistry
Get a configuration source part of the registry, identified by the given name. If it doesn't exist,null
will be returned. Configurations can be combined from different sources. This returns the configuration of a specific source. The names are the ones given by the addConfiguration* methods or defined during the initialization process.- Specified by:
getPartOfCombined
in interfaceConfigRegistry
- Parameters:
name
- The source name of the configuration source.- Returns:
- the The config registry object that represents this source part.
-
getProperties
public Map<String,String> getProperties(String key)
Description copied from interface:ConfigRegistry
Get the properties at the given key in the registry.- Specified by:
getProperties
in interfaceConfigRegistry
- Parameters:
key
- the key to lookup- Returns:
- the properties
-
save
public void save() throws RegistryException
Description copied from interface:ConfigRegistry
Save any changes to the registry since it was loaded.- Specified by:
save
in interfaceConfigRegistry
- Throws:
RegistryException
- if there was a problem saving the registry
-
registerChangeListener
public void registerChangeListener(RegistryListener listener, String prefix)
Description copied from interface:ConfigRegistry
Register a change listener for configuration keys that match the given patterns.- Specified by:
registerChangeListener
in interfaceConfigRegistry
- Parameters:
listener
- the listener
-
unregisterChangeListener
public boolean unregisterChangeListener(RegistryListener listener)
Description copied from interface:ConfigRegistry
Unregister the change listener for all events.- Specified by:
unregisterChangeListener
in interfaceConfigRegistry
- Returns:
true
if has been removed
-
getBaseKeys
public Collection<String> getBaseKeys()
Description copied from interface:ConfigRegistry
Get all keys on the base level in this registry. Keys are only retrieved at a depth of 1.- Specified by:
getBaseKeys
in interfaceConfigRegistry
- Returns:
- the set of keys
-
getKeys
public Collection<String> getKeys()
Description copied from interface:ConfigRegistry
Get all the keys in this registry.- Specified by:
getKeys
in interfaceConfigRegistry
- Returns:
- the set of keys
-
getKeys
public Collection<String> getKeys(String prefix)
Description copied from interface:ConfigRegistry
Return the keys that match the given prefix.- Specified by:
getKeys
in interfaceConfigRegistry
- Parameters:
prefix
- The prefix- Returns:
- A collection of keys
-
remove
public void remove(String key)
Description copied from interface:ConfigRegistry
Remove a keyed element from the registry.- Specified by:
remove
in interfaceConfigRegistry
- Parameters:
key
- the key to remove
-
removeSubset
public void removeSubset(String key)
Description copied from interface:ConfigRegistry
Remove a keyed subset of the registry.- Specified by:
removeSubset
in interfaceConfigRegistry
- Parameters:
key
- the subset to remove
-
getValue
public Object getValue(String key)
Description copied from interface:ConfigRegistry
Get the original value stored in the registry. If not found,null
is returned.- Specified by:
getValue
in interfaceConfigRegistry
- Parameters:
key
- The key in the registry.- Returns:
- The value.
-
getString
public String getString(String key)
Description copied from interface:ConfigRegistry
Get a string value from the registry. If not found,null
is returned.- Specified by:
getString
in interfaceConfigRegistry
- Parameters:
key
- the key in the registry- Returns:
- the value
-
getString
public String getString(String key, String defaultValue)
Description copied from interface:ConfigRegistry
Get a string value from the registry. If not found, the default value is used.- Specified by:
getString
in interfaceConfigRegistry
- Parameters:
key
- the key in the registrydefaultValue
- the default value- Returns:
- the value
-
setString
public void setString(String key, String value)
Description copied from interface:ConfigRegistry
Set a string value in the registry.- Specified by:
setString
in interfaceConfigRegistry
- Parameters:
key
- the key in the registryvalue
- the value to set
-
getInt
public int getInt(String key)
Description copied from interface:ConfigRegistry
Get an integer value from the registry. If not found, an exception is thrown.- Specified by:
getInt
in interfaceConfigRegistry
- Parameters:
key
- the key in the registry- Returns:
- the value
-
getInt
public int getInt(String key, int defaultValue)
Description copied from interface:ConfigRegistry
Get an integer value from the registry. If not found, the default value is used.- Specified by:
getInt
in interfaceConfigRegistry
- Parameters:
key
- the key in the registrydefaultValue
- the default value- Returns:
- the value
-
setInt
public void setInt(String key, int value)
Description copied from interface:ConfigRegistry
Set an integer value in the registry.- Specified by:
setInt
in interfaceConfigRegistry
- Parameters:
key
- the key in the registryvalue
- the value to set
-
getBoolean
public boolean getBoolean(String key)
Description copied from interface:ConfigRegistry
Get a boolean value from the registry. If not found, an exception is thrown.- Specified by:
getBoolean
in interfaceConfigRegistry
- Parameters:
key
- the key in the registry- Returns:
- the value
-
getBoolean
public boolean getBoolean(String key, boolean defaultValue)
Description copied from interface:ConfigRegistry
Get a boolean value from the registry. If not found, the default value is used.- Specified by:
getBoolean
in interfaceConfigRegistry
- Parameters:
key
- the key in the registrydefaultValue
- the default value- Returns:
- the value
-
setBoolean
public void setBoolean(String key, boolean value)
Description copied from interface:ConfigRegistry
Set a boolean value in the registry.- Specified by:
setBoolean
in interfaceConfigRegistry
- Parameters:
key
- the key in the registryvalue
- the value to set
-
addConfigurationFromResource
public void addConfigurationFromResource(String name, String resource) throws RegistryException
Description copied from interface:ConfigRegistry
Load configuration from the given classloader resource.- Specified by:
addConfigurationFromResource
in interfaceConfigRegistry
- Parameters:
name
- the unique name that identifies this configuration in the combined oneresource
- the location to load the configuration from- Throws:
RegistryException
- if a problem occurred reading the resource to add to the registry
-
addConfigurationFromResource
public void addConfigurationFromResource(String name, String resource, String prefix) throws RegistryException
Description copied from interface:ConfigRegistry
Load configuration from the given classloader resource.- Specified by:
addConfigurationFromResource
in interfaceConfigRegistry
- Parameters:
name
- the unique name that identifies this configuration in the combined oneresource
- the location to load the configuration fromprefix
- the location to add the configuration at in the registry- Throws:
RegistryException
- if a problem occurred reading the resource to add to the registry
-
addConfigurationFromFile
public void addConfigurationFromFile(String name, Path file) throws RegistryException
Description copied from interface:ConfigRegistry
Load configuration from the given file.- Specified by:
addConfigurationFromFile
in interfaceConfigRegistry
- Parameters:
name
- the unique name that identifies this configuration in the combined onefile
- the location to load the configuration from- Throws:
RegistryException
- if a problem occurred reading the resource to add to the registry
-
addConfigurationFromFile
public void addConfigurationFromFile(String name, Path file, String prefix) throws RegistryException
Description copied from interface:ConfigRegistry
Load configuration from the given file.- Specified by:
addConfigurationFromFile
in interfaceConfigRegistry
- Parameters:
name
- the unique name that identifies this configuration in the combined onefile
- the location to load the configuration fromprefix
- the location to add the configuration at in the registry- Throws:
RegistryException
- if a problem occurred reading the resource to add to the registry
-
initialize
@PostConstruct public void initialize() throws RegistryException
Description copied from interface:ConfigRegistry
Initializes the given registry. The definition for the configuration sources is implementation specific. Implementations should provide methods and/or constructors that allows to define the configuration source.- Specified by:
initialize
in interfaceConfigRegistry
- Throws:
RegistryException
- if the initialization was not successful
-
setCombinedConfigurationDefinition
public void setCombinedConfigurationDefinition(String combinedConfigurationDefinition)
-
getPropertyDelimiter
public String getPropertyDelimiter()
-
setPropertyDelimiter
public void setPropertyDelimiter(String propertyDelimiter)
-
getConfigurationBuilder
public org.apache.commons.configuration2.builder.ConfigurationBuilder<? extends org.apache.commons.configuration2.Configuration> getConfigurationBuilder()
-
isAddSystemProperties
public boolean isAddSystemProperties()
Returns true, if the system properties are added to the base configuration. Otherwise system properties can still be interpolated by ${sys:var} syntax.- Returns:
- True, if system properties are added to the configuration root
-
setAddSystemProperties
public void setAddSystemProperties(boolean addSystemProperties)
Set to true, if the system properties should be added to the base configuration. If set to false, system properties are no direct part of the configuration.- Parameters:
addSystemProperties
- True, or false.
-
-