Package co.luminositylabs.config
Class Configuration
- java.lang.Object
-
- co.luminositylabs.config.Configuration
-
- All Implemented Interfaces:
Serializable
@ApplicationScoped public class Configuration extends Object implements Serializable
An application-scoped CDI managed bean named which serves as an injectable component for managing configuration parameters.- Author:
- Phillip Ross
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_CONFIG_FILE_PATH_PROPERTY_NAMEThe default name of the system property referencing to the location of the configuration file.
-
Constructor Summary
Constructors Constructor Description Configuration()Instantiates a new configuration object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectget(Object key)Delegates toProperties.get(Object).ObjectgetOrDefault(Object key, Object defaultValue)Delegates toProperties.getOrDefault(Object, Object).PropertiesgetProperties()Gets the properties.PropertiesgetPropertiesWithPrefix(String prefix)Gets the properties that begin with a specified prefix.StringgetProperty(String propertyName)Gets the property value with the specified name.StringgetProperty(String propertyName, String defaultValue)Gets the property value with the specified name.Objectput(Object key, Object value)Delegates toProperties.put(Object, Object).voidputAll(Map<?,?> map)Delegates toProperties.putAll(Map).ObjectputIfAbsent(Object key, Object value)Delegates toProperties.putIfAbsent(Object, Object).voidreadProperties()Reads in the configuration properties.voidsetProperties(Properties properties)Clears existing configuration properties replaces with the specified properties.voidsetProperty(String propertyName, String propertyValue)Sets the specified property to the specified value.
-
-
-
Field Detail
-
DEFAULT_CONFIG_FILE_PATH_PROPERTY_NAME
public static final String DEFAULT_CONFIG_FILE_PATH_PROPERTY_NAME
The default name of the system property referencing to the location of the configuration file.- See Also:
- Constant Field Values
-
-
Method Detail
-
getProperties
public Properties getProperties()
Gets the properties.- Returns:
- the properties
-
getPropertiesWithPrefix
public Properties getPropertiesWithPrefix(String prefix)
Gets the properties that begin with a specified prefix.- Parameters:
prefix- the prefix- Returns:
- the properties
-
setProperties
public void setProperties(Properties properties)
Clears existing configuration properties replaces with the specified properties.- Parameters:
properties- the properties
-
setProperty
public void setProperty(String propertyName, String propertyValue)
Sets the specified property to the specified value.- Parameters:
propertyName- the property name to be setpropertyValue- the property value to set the property to
-
getProperty
public String getProperty(String propertyName)
Gets the property value with the specified name.- Parameters:
propertyName- the name of the property to get- Returns:
- the value of the property retrieved
-
getProperty
public String getProperty(String propertyName, String defaultValue)
Gets the property value with the specified name. If the property does not exist, the specified default value is returned.- Parameters:
propertyName- the name of the property to getdefaultValue- the value returned if the property does not exist- Returns:
- the value of the property retrieved
-
get
public Object get(Object key)
Delegates toProperties.get(Object).- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key - Throws:
NullPointerException- if the specified key is null
-
getOrDefault
public Object getOrDefault(Object key, Object defaultValue)
Delegates toProperties.getOrDefault(Object, Object).- Parameters:
key- the key whose associated value is to be returneddefaultValue- the value to be returned if the associated property value is null- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key
-
put
public Object put(Object key, Object value)
Delegates toProperties.put(Object, Object).- Parameters:
key- the hashtable keyvalue- the value- Returns:
- the previous value of the specified key in this hashtable, or
nullif it did not have one - Throws:
NullPointerException- if the key or value isnull
-
putAll
public void putAll(Map<?,?> map)
Delegates toProperties.putAll(Map).- Parameters:
map- mappings to be stored in this map- Throws:
NullPointerException- if the specified map is null
-
putIfAbsent
public Object putIfAbsent(Object key, Object value)
Delegates toProperties.putIfAbsent(Object, Object).- Parameters:
key- the hashtable keyvalue- the value- Returns:
- the previous value of the specified key in this hashtable, or
nullif it did not have one - Throws:
NullPointerException- if the key or value isnull
-
readProperties
@PostConstruct public void readProperties()
Reads in the configuration properties. If theco.luminositylabs.configFilesystem property exists, the value of this property is used as the path to read the configuration from. If the property does not exist, a path namedco.luminositylabs.config.propertiesis used.If the configuration pathname does NOT represent an absolute path, the pathname will be treated as a relative path, and the file will be searched for in a series of relative locations:
- First, the file will be searched for at the path relative to the current working directory.
- Second, the file will be searched for at the path relative to the home directory.
- Lastly, the file will be searched for at the path relative to the classpath.
If the configuration file is not found, an
IOExceptionis thrown.
-
-