Interface ConfigurationService
-
- All Known Implementing Classes:
DSpaceConfigurationService
public interface ConfigurationService
This service handles retrieval of the configuration data for a DSpace instance.The configuration files are properties files which look like this for simple values:
thing.name = aaronz thing.number = 1234 thing.on = true thing.value = abc,def,ghi
For these simple cases the service will automatically translate the settings into strings, booleans, numbers and arrays as requested in the variousgetPropertyAsType(String, Class)
methods.There are special case configuration parameters allowed as well.
The first allows setting of a parameter on any DSpace service by the given name:
[email protected] = true [email protected] = aaronz
This should be used sparingly and really only by system admins (not developers). Developers should be using simple config values to expose service configurations.The second allows controlling the implementation used for a service interface or provider:
$org.dspace.Service = org.dspace.impl.MyService
- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
addPropertyValue(String name, Object value)
Add a value to a configuration property.String[]
getArrayProperty(String name)
Convenience method - get a configuration property (setting) from the system as a String Array.String[]
getArrayProperty(String name, String[] defaultValue)
Convenience method - get a configuration property (setting) from the system as a String Array.boolean
getBooleanProperty(String name)
Convenience method - get a configuration property (setting) from the system as a boolean value.boolean
getBooleanProperty(String name, boolean defaultValue)
Convenience method - get a configuration property (setting) from the system as a boolean value.org.apache.commons.configuration2.Configuration
getConfiguration()
Convenience method - get entire configuration (settings) from the system.int
getIntProperty(String name)
Convenience method - get a configuration property (setting) from the system as an int value.int
getIntProperty(String name, int defaultValue)
Convenience method - get a configuration property (setting) from the system as an int value.long
getLongProperty(String name)
Convenience method - get a configuration property (setting) from the system as a long value.long
getLongProperty(String name, long defaultValue)
Convenience method - get a configuration property (setting) from the system as a long value.Properties
getProperties()
Convenience method - get all configuration properties (settings) from the system.String
getProperty(String name)
Convenience method - get a configuration property (setting) from the system as a String.String
getProperty(String name, String defaultValue)
Convenience method - get a configuration property (setting) from the system as a String.<T> T
getPropertyAsType(String name, Class<T> type)
Get a configuration property (setting) from the system as a specified type.<T> T
getPropertyAsType(String name, T defaultValue)
Get a configuration property (setting) from the system, or return a default value if none is found.<T> T
getPropertyAsType(String name, T defaultValue, boolean setDefaultIfNotFound)
Get a configuration property (setting) from the system, or return (and possibly store) a default value if none is found.List<String>
getPropertyKeys()
Get keys all currently known configuration settingsList<String>
getPropertyKeys(String prefix)
Get keys all currently known configuration settings, which begin with a given prefix.Object
getPropertyValue(String name)
Convenience method - get a configuration property (setting) from the system as its stored objectboolean
hasProperty(String name)
Return whether a property exists within the configurationvoid
reloadConfig()
Reload the configuration from the DSpace configuration files.boolean
setProperty(String name, Object value)
Set a configuration property (setting) in the system.
-
-
-
Method Detail
-
getPropertyAsType
<T> T getPropertyAsType(String name, Class<T> type)
Get a configuration property (setting) from the system as a specified type.- Type Parameters:
T
- class type- Parameters:
name
- the property nametype
- the type to return the property as- Returns:
- the property value OR null if none is found
- Throws:
UnsupportedOperationException
- if the type cannot be converted to the requested type
-
getPropertyAsType
<T> T getPropertyAsType(String name, T defaultValue)
Get a configuration property (setting) from the system, or return a default value if none is found.- Type Parameters:
T
- class type- Parameters:
name
- the property namedefaultValue
- the value to return if this name is not found- Returns:
- the property value OR null if none is found
- Throws:
IllegalArgumentException
- if the defaultValue type does not match the type of the property by name
-
getPropertyAsType
<T> T getPropertyAsType(String name, T defaultValue, boolean setDefaultIfNotFound)
Get a configuration property (setting) from the system, or return (and possibly store) a default value if none is found.- Type Parameters:
T
- class type- Parameters:
name
- the property namedefaultValue
- the value to return if this name is not foundsetDefaultIfNotFound
- if this is true and the config value is not found then the default value will be set in the configuration store assuming it is not null. Otherwise the default value is just returned but not set.- Returns:
- the property value OR null if none is found
- Throws:
IllegalArgumentException
- if the defaultValue type does not match the type of the property by name
-
getPropertyKeys
List<String> getPropertyKeys()
Get keys all currently known configuration settings- Returns:
- all the configuration keys as a List
-
getPropertyKeys
List<String> getPropertyKeys(String prefix)
Get keys all currently known configuration settings, which begin with a given prefix.For example, passing in "db" would return the keys "db.url", "db.username", etc.
- Parameters:
prefix
- prefix of key- Returns:
- all the configuration keys as a List
-
getProperty
String getProperty(String name)
Convenience method - get a configuration property (setting) from the system as a String.- Parameters:
name
- the property name- Returns:
- the property value OR null if none is found
-
getProperty
String getProperty(String name, String defaultValue)
Convenience method - get a configuration property (setting) from the system as a String.- Parameters:
name
- the property namedefaultValue
- default value if property not found- Returns:
- the property value OR default value if not found
-
getArrayProperty
String[] getArrayProperty(String name)
Convenience method - get a configuration property (setting) from the system as a String Array.- Parameters:
name
- the property name- Returns:
- the String Array value
-
getArrayProperty
String[] getArrayProperty(String name, String[] defaultValue)
Convenience method - get a configuration property (setting) from the system as a String Array.- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the String Array value or default value if not found
-
getBooleanProperty
boolean getBooleanProperty(String name)
Convenience method - get a configuration property (setting) from the system as a boolean value.- Parameters:
name
- the property name- Returns:
- the boolean property value (true/false)
-
getBooleanProperty
boolean getBooleanProperty(String name, boolean defaultValue)
Convenience method - get a configuration property (setting) from the system as a boolean value.- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the boolean property value (true/false) or default value if not found
-
getIntProperty
int getIntProperty(String name)
Convenience method - get a configuration property (setting) from the system as an int value.- Parameters:
name
- the property name- Returns:
- the integer property value
-
getIntProperty
int getIntProperty(String name, int defaultValue)
Convenience method - get a configuration property (setting) from the system as an int value.- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the integer property value or default value if not found
-
getLongProperty
long getLongProperty(String name)
Convenience method - get a configuration property (setting) from the system as a long value.- Parameters:
name
- the property name- Returns:
- the long property value
-
getLongProperty
long getLongProperty(String name, long defaultValue)
Convenience method - get a configuration property (setting) from the system as a long value.- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the long property value or default value if not found
-
getPropertyValue
Object getPropertyValue(String name)
Convenience method - get a configuration property (setting) from the system as its stored object- Parameters:
name
- the property name- Returns:
- the property value OR null if none is found
-
getProperties
Properties getProperties()
Convenience method - get all configuration properties (settings) from the system.- Returns:
- all the configuration properties in a properties object (name to value)
-
getConfiguration
org.apache.commons.configuration2.Configuration getConfiguration()
Convenience method - get entire configuration (settings) from the system.- Returns:
- Configuration object representing the system configuration
-
hasProperty
boolean hasProperty(String name)
Return whether a property exists within the configuration- Parameters:
name
- the property name- Returns:
- true if property exists, false if not
-
addPropertyValue
boolean addPropertyValue(String name, Object value)
Add a value to a configuration property.- Parameters:
name
- the property name. May not be null.value
- the property value. May not be null.- Returns:
- true if a new property was created.
- Throws:
IllegalArgumentException
- if the name or value is null.
-
setProperty
boolean setProperty(String name, Object value)
Set a configuration property (setting) in the system. Type is not important here since conversion happens automatically when properties are requested.- Parameters:
name
- the property namevalue
- the property value (set this to null to clear out the property)- Returns:
- true if the property is new or changed from the existing value, false if it is the same
- Throws:
IllegalArgumentException
- if the name is nullUnsupportedOperationException
- if the type cannot be converted to something that is understandable by the system as a configuration property value
-
reloadConfig
void reloadConfig()
Reload the configuration from the DSpace configuration files.Uses the initialized ConfigurationService to reload all configurations.
-
-