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 ConfigRegistryImplementation 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 thecombinedConfigurationDefinitionconfiguration 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 voidaddConfigurationFromFile(String name, Path file)Load configuration from the given file.voidaddConfigurationFromFile(String name, Path file, String prefix)Load configuration from the given file.voidaddConfigurationFromResource(String name, String resource)Load configuration from the given classloader resource.voidaddConfigurationFromResource(String name, String resource, String prefix)Load configuration from the given classloader resource.Stringdump()Dump the entire registry to a string, for debugging purposes.Collection<String>getBaseKeys()Get all keys on the base level in this registry.booleangetBoolean(String key)Get a boolean value from the registry.booleangetBoolean(String key, boolean defaultValue)Get a boolean value from the registry.org.apache.commons.configuration2.builder.ConfigurationBuilder<? extends org.apache.commons.configuration2.Configuration>getConfigurationBuilder()intgetInt(String key)Get an integer value from the registry.intgetInt(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.ConfigRegistrygetPartOfCombined(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.StringgetPropertyDelimiter()StringgetString(String key)Get a string value from the registry.StringgetString(String key, String defaultValue)Get a string value from the registry.ConfigRegistrygetSubset(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.ObjectgetValue(String key)Get the original value stored in the registry.voidinitialize()Initializes the given registry.booleanisAddSystemProperties()Returns true, if the system properties are added to the base configuration.booleanisEmpty()Determine if the registry contains any elements.voidregisterChangeListener(RegistryListener listener, String prefix)Register a change listener for configuration keys that match the given patterns.voidremove(String key)Remove a keyed element from the registry.voidremoveSubset(String key)Remove a keyed subset of the registry.voidsave()Save any changes to the registry since it was loaded.voidsetAddSystemProperties(boolean addSystemProperties)Set to true, if the system properties should be added to the base configuration.voidsetBoolean(String key, boolean value)Set a boolean value in the registry.voidsetCombinedConfigurationDefinition(String combinedConfigurationDefinition)voidsetConfiguration(org.apache.commons.configuration2.Configuration configuration)voidsetInt(String key, int value)Set an integer value in the registry.voidsetPropertyDelimiter(String propertyDelimiter)voidsetString(String key, String value)Set a string value in the registry.booleanunregisterChangeListener(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:ConfigRegistryDump the entire registry to a string, for debugging purposes.- Specified by:
dumpin interfaceConfigRegistry- Returns:
- the registry contents
-
isEmpty
public boolean isEmpty()
Description copied from interface:ConfigRegistryDetermine if the registry contains any elements.- Specified by:
isEmptyin interfaceConfigRegistry- Returns:
- whether the registry contains any elements
-
getSubset
public ConfigRegistry getSubset(String key) throws RegistryException
Description copied from interface:ConfigRegistryGet a subset of the registry, for all keys descended from the given key.- Specified by:
getSubsetin 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:ConfigRegistryGet a list of strings at the given key in the registry. If not found a empty list will be returned.- Specified by:
getListin 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:ConfigRegistryGet a list of subsets of the registry, for all keys descended from the given key.- Specified by:
getSubsetListin 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:ConfigRegistryGet a configuration source part of the registry, identified by the given name. If it doesn't exist,nullwill 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:
getPartOfCombinedin 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:ConfigRegistryGet the properties at the given key in the registry.- Specified by:
getPropertiesin interfaceConfigRegistry- Parameters:
key- the key to lookup- Returns:
- the properties
-
save
public void save() throws RegistryException
Description copied from interface:ConfigRegistrySave any changes to the registry since it was loaded.- Specified by:
savein interfaceConfigRegistry- Throws:
RegistryException- if there was a problem saving the registry
-
registerChangeListener
public void registerChangeListener(RegistryListener listener, String prefix)
Description copied from interface:ConfigRegistryRegister a change listener for configuration keys that match the given patterns.- Specified by:
registerChangeListenerin interfaceConfigRegistry- Parameters:
listener- the listener
-
unregisterChangeListener
public boolean unregisterChangeListener(RegistryListener listener)
Description copied from interface:ConfigRegistryUnregister the change listener for all events.- Specified by:
unregisterChangeListenerin interfaceConfigRegistry- Returns:
trueif has been removed
-
getBaseKeys
public Collection<String> getBaseKeys()
Description copied from interface:ConfigRegistryGet all keys on the base level in this registry. Keys are only retrieved at a depth of 1.- Specified by:
getBaseKeysin interfaceConfigRegistry- Returns:
- the set of keys
-
getKeys
public Collection<String> getKeys()
Description copied from interface:ConfigRegistryGet all the keys in this registry.- Specified by:
getKeysin interfaceConfigRegistry- Returns:
- the set of keys
-
getKeys
public Collection<String> getKeys(String prefix)
Description copied from interface:ConfigRegistryReturn the keys that match the given prefix.- Specified by:
getKeysin interfaceConfigRegistry- Parameters:
prefix- The prefix- Returns:
- A collection of keys
-
remove
public void remove(String key)
Description copied from interface:ConfigRegistryRemove a keyed element from the registry.- Specified by:
removein interfaceConfigRegistry- Parameters:
key- the key to remove
-
removeSubset
public void removeSubset(String key)
Description copied from interface:ConfigRegistryRemove a keyed subset of the registry.- Specified by:
removeSubsetin interfaceConfigRegistry- Parameters:
key- the subset to remove
-
getValue
public Object getValue(String key)
Description copied from interface:ConfigRegistryGet the original value stored in the registry. If not found,nullis returned.- Specified by:
getValuein interfaceConfigRegistry- Parameters:
key- The key in the registry.- Returns:
- The value.
-
getString
public String getString(String key)
Description copied from interface:ConfigRegistryGet a string value from the registry. If not found,nullis returned.- Specified by:
getStringin interfaceConfigRegistry- Parameters:
key- the key in the registry- Returns:
- the value
-
getString
public String getString(String key, String defaultValue)
Description copied from interface:ConfigRegistryGet a string value from the registry. If not found, the default value is used.- Specified by:
getStringin 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:ConfigRegistrySet a string value in the registry.- Specified by:
setStringin interfaceConfigRegistry- Parameters:
key- the key in the registryvalue- the value to set
-
getInt
public int getInt(String key)
Description copied from interface:ConfigRegistryGet an integer value from the registry. If not found, an exception is thrown.- Specified by:
getIntin interfaceConfigRegistry- Parameters:
key- the key in the registry- Returns:
- the value
-
getInt
public int getInt(String key, int defaultValue)
Description copied from interface:ConfigRegistryGet an integer value from the registry. If not found, the default value is used.- Specified by:
getIntin 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:ConfigRegistrySet an integer value in the registry.- Specified by:
setIntin interfaceConfigRegistry- Parameters:
key- the key in the registryvalue- the value to set
-
getBoolean
public boolean getBoolean(String key)
Description copied from interface:ConfigRegistryGet a boolean value from the registry. If not found, an exception is thrown.- Specified by:
getBooleanin interfaceConfigRegistry- Parameters:
key- the key in the registry- Returns:
- the value
-
getBoolean
public boolean getBoolean(String key, boolean defaultValue)
Description copied from interface:ConfigRegistryGet a boolean value from the registry. If not found, the default value is used.- Specified by:
getBooleanin 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:ConfigRegistrySet a boolean value in the registry.- Specified by:
setBooleanin 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:ConfigRegistryLoad configuration from the given classloader resource.- Specified by:
addConfigurationFromResourcein 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:ConfigRegistryLoad configuration from the given classloader resource.- Specified by:
addConfigurationFromResourcein 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:ConfigRegistryLoad configuration from the given file.- Specified by:
addConfigurationFromFilein 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:ConfigRegistryLoad configuration from the given file.- Specified by:
addConfigurationFromFilein 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:ConfigRegistryInitializes 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:
initializein 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.
-
-