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
FieldsModifier and TypeFieldDescriptionstatic final StringProviding aRIFE2_PROPERTIES_FILEenvironment variable, describes the path of a file that will be automatically read and parsed for additional properties. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks theHierarchicalPropertieshierarchy for the presence of the specified name.Creates a copy of thisHierarchicalPropertieshierarchy until a certain instance is reached.static HierarchicalPropertiesCreates a new instance that's populated with the system environment variables and JVM properties.Retrieves thePropertyValuefor a specific name from theHierarchicalPropertieshierarchy.Retrieves aSetwith the unique names that are present in theHierarchicalPropertieshierarchy and that conform to the Java rules for valid identifiers.Retrieves theMapwith only the properties that are locally present in thisHierarchicalPropertiesinstance.getNames()Retrieves aSetwith the unique names that are present in theHierarchicalPropertieshierarchy.Retrieves the parent of thisHierarchicalPropertiesinstance.getRoot()Retrieves the first parent of thisHierarchicalPropertieshierarchy.Retrieves the value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.Retrieves the value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.getValueString(String name) Retrieves the string value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.getValueString(String name, String defaultValue) Retrieves the string value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.<T> TgetValueTyped(String name, Class<T> type) Retrieves the typed value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.<T> TgetValueTyped(String name, Class<T> type, T defaultValue) Retrieves the typed value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.parent(HierarchicalProperties parent) Sets the parent of thisHierarchicalPropertiesinstance.Associates the specified fixed object value with the specified name in thisHierarchicalPropertiesinstance.put(String name, PropertyValue value) Associates the specified value with the specified name in thisHierarchicalPropertiesinstance.Copies all the entries for aMapinstance to thisHierarchicalPropertiesinstance.putAll(HierarchicalProperties source) Copies all the named properties from the specifiedHierarchicalPropertiesinstance to thisHierarchicalPropertiesinstance.Copies all the named properties from the specifiedHierarchicalPropertiesinstance to thisHierarchicalPropertiesinstance, without replacing existing properties.Removes the mapping for this name from thisHierarchicalPropertiesinstance, if it is present.voidsetParent(HierarchicalProperties parent) Sets the parent of thisHierarchicalPropertiesinstance.intsize()Retrieves the number of unique names in theHierarchicalPropertieshierarchy.
-
Field Details
-
SYSTEM_PROPERTY_FILE_NAME
Providing aRIFE2_PROPERTIES_FILEenvironment 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 thisHierarchicalPropertieshierarchy 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- theHierarchicalPropertiesinstance that will not be part of the shadow copy and interrupt the copying process; ornullif the entire hierachy should be copied.- Returns:
- the shadow copy of this
HierarchicalPropertieshierarchy - Since:
- 1.0
-
getRoot
Retrieves the first parent of thisHierarchicalPropertieshierarchy.- Returns:
- the root of this
HierarchicalPropertieshierarchy - Since:
- 1.0
-
getLocalMap
Retrieves theMapwith only the properties that are locally present in thisHierarchicalPropertiesinstance.- Returns:
- the local
Mapof thisHierarchicalPropertiesinstance - Since:
- 1.0
-
setParent
Sets the parent of thisHierarchicalPropertiesinstance.- Parameters:
parent- the parent of this instance; ornullif this instance should be isolated- Since:
- 1.0
- See Also:
-
parent
Sets the parent of thisHierarchicalPropertiesinstance.- Parameters:
parent- the parent of this instance; ornullif this instance should be isolated- Returns:
- this
HierarchicalPropertiesinstance - Since:
- 1.0
- See Also:
-
getParent
Retrieves the parent of thisHierarchicalPropertiesinstance.- Returns:
- the parent of this
HierarchicalPropertiesinstance; ornullif this instance is isolated - Since:
- 1.0
- See Also:
-
put
Associates the specified value with the specified name in thisHierarchicalPropertiesinstance. 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
HierarchicalPropertiesinstance - Since:
- 1.0
- See Also:
-
put
Associates the specified fixed object value with the specified name in thisHierarchicalPropertiesinstance. 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 aPropertyValueObjectinstance that will contain the value in a fixed manner- Returns:
- this
HierarchicalPropertiesinstance - Since:
- 1.0
- See Also:
-
remove
Removes the mapping for this name from thisHierarchicalPropertiesinstance, if it is present.- Parameters:
name- the name that will be removed- Returns:
- the previously associated value; or
nullif the name wasn't found in thisHierarchicalPropertiesinstance - Since:
- 1.0
-
putAll
Copies all the named properties from the specifiedHierarchicalPropertiesinstance to thisHierarchicalPropertiesinstance. The effect of this call is equivalent to that of callingput(java.lang.String, rife.ioc.PropertyValue)on thisHierarchicalPropertiesonce for each mapping from the specifiedHierarchicalPropertiesinstance.- Parameters:
source- the properties that will be stored in thisHierarchicalPropertiesinstance- Returns:
- this
HierarchicalPropertiesinstance - Since:
- 1.0
- See Also:
-
putAllWithoutReplacing
Copies all the named properties from the specifiedHierarchicalPropertiesinstance to thisHierarchicalPropertiesinstance, without replacing existing properties. The effect of this call is equivalent to that of callingput(java.lang.String, rife.ioc.PropertyValue)on thisHierarchicalPropertiesonce for each mapping from the specifiedHierarchicalPropertiesinstance that doesn't have a key in this instance yet.- Parameters:
source- the properties that will be stored in thisHierarchicalPropertiesinstance- Returns:
- this
HierarchicalPropertiesinstance - Since:
- 1.0
- See Also:
-
putAll
Copies all the entries for aMapinstance to thisHierarchicalPropertiesinstance.- Parameters:
source- the map entries that will be stored in thisHierarchicalPropertiesinstance- Returns:
- this
HierarchicalPropertiesinstance - Since:
- 1.0
-
contains
Checks theHierarchicalPropertieshierarchy for the presence of the specified name.- Parameters:
name- the name whose presence will be checked- Returns:
trueif the name was found; orfalseotherwise- Since:
- 1.0
- See Also:
-
get
Retrieves thePropertyValuefor a specific name from theHierarchicalPropertieshierarchy.- Parameters:
name- the name whose associated value will be returned- Returns:
- the associated
PropertyValue; ornullif the name could not be found - Since:
- 1.0
- See Also:
-
getValue
Retrieves the value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.- Parameters:
name- the name whose associated value will be returned- Returns:
- the associated
PropertyValue; ornullif 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 ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy. 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
defaultValueif 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 ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.- Parameters:
name- the name whose associated value will be returned- Returns:
- the string value of the retrieved
PropertyValue; ornullif 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 ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy. If the property couldn't be found, if the value wasnullor 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
defaultValueif the property couldn't be found or if the value wasnullor an empty string - Throws:
PropertyValueException- when an error occurred while retrieving the property value- Since:
- 1.0
- See Also:
-
getValueTyped
Retrieves the typed value ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.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
PropertyValueas an instance of the provided type; ornullif 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 ofPropertyValuefor a specific name from theHierarchicalPropertieshierarchy.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
PropertyValueas an instance of the provided type; orthe
defaultValueif 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 theHierarchicalPropertieshierarchy.- Returns:
- the amount of unique names
- Since:
- 1.0
-
getNames
Retrieves aSetwith the unique names that are present in theHierarchicalPropertieshierarchy.- Returns:
- a collection with the unique names
- Since:
- 1.0
- See Also:
-
getInjectableNames
Retrieves aSetwith the unique names that are present in theHierarchicalPropertieshierarchy 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
Setwith the unique injectable names - Since:
- 1.0
- See Also:
-