Class HierarchicalProperties
PropertyValue
instances.
When a property is looked up in a child
HierarchicalProperties
instance, the lookup will be propagated
to its parent when it couldn't be found in the child. A single hierarchical
line is thus considered to be one collection that groups all involved
HierarchicalProperties
instances. Retrieving the names and the
size will recursively take all the properties of the parents into account
and return the consolidated result. To offer these features, intelligent
caching has been implemented to ensure optimal performance.
- Since:
- 1.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Providing aRIFE2_PROPERTIES_FILE
environment variable, describes the path of a file that will be automatically read and parsed for additional properties. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks theHierarchicalProperties
hierarchy for the presence of the specified name.Creates a copy of thisHierarchicalProperties
hierarchy until a certain instance is reached.static HierarchicalProperties
Creates a new instance that's populated with the system environment variables and JVM properties.Retrieves thePropertyValue
for a specific name from theHierarchicalProperties
hierarchy.Retrieves aSet
with the unique names that are present in theHierarchicalProperties
hierarchy and that conform to the Java rules for valid identifiers.Retrieves theMap
with only the properties that are locally present in thisHierarchicalProperties
instance.getNames()
Retrieves aSet
with the unique names that are present in theHierarchicalProperties
hierarchy.Retrieves the parent of thisHierarchicalProperties
instance.getRoot()
Retrieves the first parent of thisHierarchicalProperties
hierarchy.Retrieves the value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.Retrieves the value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.getValueString
(String name) Retrieves the string value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.getValueString
(String name, String defaultValue) Retrieves the string value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.<T> T
getValueTyped
(String name, Class<T> type) Retrieves the typed value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.<T> T
getValueTyped
(String name, Class<T> type, T defaultValue) Retrieves the typed value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.parent
(HierarchicalProperties parent) Sets the parent of thisHierarchicalProperties
instance.Associates the specified fixed object value with the specified name in thisHierarchicalProperties
instance.put
(String name, PropertyValue value) Associates the specified value with the specified name in thisHierarchicalProperties
instance.Copies all the entries for aMap
instance to thisHierarchicalProperties
instance.putAll
(HierarchicalProperties source) Copies all the named properties from the specifiedHierarchicalProperties
instance to thisHierarchicalProperties
instance.Copies all the named properties from the specifiedHierarchicalProperties
instance to thisHierarchicalProperties
instance, without replacing existing properties.Removes the mapping for this name from thisHierarchicalProperties
instance, if it is present.void
setParent
(HierarchicalProperties parent) Sets the parent of thisHierarchicalProperties
instance.int
size()
Retrieves the number of unique names in theHierarchicalProperties
hierarchy.
-
Field Details
-
SYSTEM_PROPERTY_FILE_NAME
Providing aRIFE2_PROPERTIES_FILE
environment variable, describes the path of a file that will be automatically read and parsed for additional properties. These properties will be inserted into the hierarchical properties hierarchy after the system environment variables and before the system properties.- Since:
- 1.5
- See Also:
-
-
Constructor Details
-
HierarchicalProperties
public HierarchicalProperties()
-
-
Method Details
-
createSystemInstance
Creates a new instance that's populated with the system environment variables and JVM properties.- Returns:
- a pre-populated new instance with system data
- Since:
- 1.4.1
-
createShadow
Creates a copy of thisHierarchicalProperties
hierarchy until a certain instance is reached.Each copied instance will share the datastructure in which the properties are stored with the original. Creating a shadow is for changing the hierarchical structure but maintaining a centralized management of the properties.
- Parameters:
limit
- theHierarchicalProperties
instance that will not be part of the shadow copy and interrupt the copying process; ornull
if the entire hierachy should be copied.- Returns:
- the shadow copy of this
HierarchicalProperties
hierarchy - Since:
- 1.0
-
getRoot
Retrieves the first parent of thisHierarchicalProperties
hierarchy.- Returns:
- the root of this
HierarchicalProperties
hierarchy - Since:
- 1.0
-
getLocalMap
Retrieves theMap
with only the properties that are locally present in thisHierarchicalProperties
instance.- Returns:
- the local
Map
of thisHierarchicalProperties
instance - Since:
- 1.0
-
setParent
Sets the parent of thisHierarchicalProperties
instance.- Parameters:
parent
- the parent of this instance; ornull
if this instance should be isolated- Since:
- 1.0
- See Also:
-
parent
Sets the parent of thisHierarchicalProperties
instance.- Parameters:
parent
- the parent of this instance; ornull
if this instance should be isolated- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
- See Also:
-
getParent
Retrieves the parent of thisHierarchicalProperties
instance.- Returns:
- the parent of this
HierarchicalProperties
instance; ornull
if this instance is isolated - Since:
- 1.0
- See Also:
-
put
Associates the specified value with the specified name in thisHierarchicalProperties
instance. If it previously contained a mapping for this name, the old value is replaced by the specified value.- Parameters:
name
- the name that will be associated with the propertyvalue
- the property value that will be associated with the specified name- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
- See Also:
-
put
Associates the specified fixed object value with the specified name in thisHierarchicalProperties
instance. If it previously contained a mapping for this name, the old value is replaced by the specified value.- Parameters:
name
- the name that will be associated with the propertyvalue
- the property value that will be associated with the specified name, note that this method will create aPropertyValueObject
instance that will contain the value in a fixed manner- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
- See Also:
-
remove
Removes the mapping for this name from thisHierarchicalProperties
instance, if it is present.- Parameters:
name
- the name that will be removed- Returns:
- the previously associated value; or
null
if the name wasn't found in thisHierarchicalProperties
instance - Since:
- 1.0
-
putAll
Copies all the named properties from the specifiedHierarchicalProperties
instance to thisHierarchicalProperties
instance. The effect of this call is equivalent to that of callingput(java.lang.String, rife.ioc.PropertyValue)
on thisHierarchicalProperties
once for each mapping from the specifiedHierarchicalProperties
instance.- Parameters:
source
- the properties that will be stored in thisHierarchicalProperties
instance- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
- See Also:
-
putAllWithoutReplacing
Copies all the named properties from the specifiedHierarchicalProperties
instance to thisHierarchicalProperties
instance, without replacing existing properties. The effect of this call is equivalent to that of callingput(java.lang.String, rife.ioc.PropertyValue)
on thisHierarchicalProperties
once for each mapping from the specifiedHierarchicalProperties
instance that doesn't have a key in this instance yet.- Parameters:
source
- the properties that will be stored in thisHierarchicalProperties
instance- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
- See Also:
-
putAll
Copies all the entries for aMap
instance to thisHierarchicalProperties
instance.- Parameters:
source
- the map entries that will be stored in thisHierarchicalProperties
instance- Returns:
- this
HierarchicalProperties
instance - Since:
- 1.0
-
contains
Checks theHierarchicalProperties
hierarchy for the presence of the specified name.- Parameters:
name
- the name whose presence will be checked- Returns:
true
if the name was found; orfalse
otherwise- Since:
- 1.0
- See Also:
-
get
Retrieves thePropertyValue
for a specific name from theHierarchicalProperties
hierarchy.- Parameters:
name
- the name whose associated value will be returned- Returns:
- the associated
PropertyValue
; ornull
if the name could not be found - Since:
- 1.0
- See Also:
-
getValue
Retrieves the value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.- Parameters:
name
- the name whose associated value will be returned- Returns:
- the associated
PropertyValue
; ornull
if the name could not be found - Throws:
PropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValue
Retrieves the value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy. If the property couldn't be found or if the value wasnull
, the default value will be returned.- Parameters:
name
- the name whose associated value will be returneddefaultValue
- the value that should be used as a fallback- Returns:
- the associated
PropertyValue
; orthe
defaultValue
if the property couldn't be found or if the value wasnull
- Throws:
PropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValueString
Retrieves the string value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.- Parameters:
name
- the name whose associated value will be returned- Returns:
- the string value of the retrieved
PropertyValue
; ornull
if the name could not be found - Throws:
PropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValueString
Retrieves the string value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy. If the property couldn't be found, if the value wasnull
or if the value was empty, the default value will be returned.- Parameters:
name
- the name whose associated value will be returneddefaultValue
- the value that should be used as a fallback- Returns:
- the string value of the retrieved
PropertyValue
; orthe
defaultValue
if the property couldn't be found or if the value wasnull
or an empty string - Throws:
PropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValueTyped
Retrieves the typed value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.Note that no conversion will occurr, the value is simple verified to be assignable to the requested type and then cast to it.
- Parameters:
name
- the name whose associated value will be returnedtype
- the class that the value has to be retrieved as- Returns:
- the associated
PropertyValue
as an instance of the provided type; ornull
if the name could not be found - Throws:
IncompatiblePropertyValueTypeException
- when the type of the property value wasn't compatible with the requested typePropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValueTyped
public <T> T getValueTyped(String name, Class<T> type, T defaultValue) throws PropertyValueException Retrieves the typed value ofPropertyValue
for a specific name from theHierarchicalProperties
hierarchy.Note that no conversion will occur, the value is simple verified to be assignable to the requested type and then cast to it.
- Parameters:
name
- the name whose associated value will be returnedtype
- the class that the value has to be retrieved asdefaultValue
- the value that should be used as a fallback- Returns:
- the associated
PropertyValue
as an instance of the provided type; orthe
defaultValue
if the property couldn't be found or if the value wasnull
- Throws:
IncompatiblePropertyValueTypeException
- when the type of the property value wasn't compatible with the requested typePropertyValueException
- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
size
public int size()Retrieves the number of unique names in theHierarchicalProperties
hierarchy.- Returns:
- the amount of unique names
- Since:
- 1.0
-
getNames
Retrieves aSet
with the unique names that are present in theHierarchicalProperties
hierarchy.- Returns:
- a collection with the unique names
- Since:
- 1.0
- See Also:
-
getInjectableNames
Retrieves aSet
with the unique names that are present in theHierarchicalProperties
hierarchy and that conform to the Java rules for valid identifiers. The names in this set are thus usable for injection through bean setters.- Returns:
- a
Set
with the unique injectable names - Since:
- 1.0
- See Also:
-