Package org.jfree.base.config
Class HierarchicalConfiguration
java.lang.Object
org.jfree.base.config.HierarchicalConfiguration
- All Implemented Interfaces:
Serializable
,Cloneable
,ModifiableConfiguration
,Configuration
,PublicCloneable
- Direct Known Subclasses:
PropertyFileConfiguration
,SystemPropertyConfiguration
public class HierarchicalConfiguration
extends Object
implements ModifiableConfiguration, PublicCloneable
A hierarchical configuration. Such a configuration can have one or more
parent configurations providing usefull default values.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Properties
The instance configuration properties.private Configuration
The parent configuration (null if this is the root configuration). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new configuration.HierarchicalConfiguration
(Configuration parentConfiguration) Creates a new configuration. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this instance.private void
collectPropertyKeys
(String prefix, Configuration config, TreeSet collector) Collects property keys from this and all parent report configurations, which start with the given prefix.protected void
A callback method to reconnect this configuration with the global configuration after deserialization.findPropertyKeys
(String prefix) Searches all property keys that start with a given prefix.Returns all defined configuration properties for the report.getConfigProperty
(String key) Returns the configuration property with the specified key.getConfigProperty
(String key, String defaultValue) Returns the configuration property with the specified key (or the specified default value if there is no such property).protected Properties
Returns the collection of properties for the configuration.protected Configuration
Returns the parent configuration.void
The new configuartion will be inserted into the list of report configuration, so that this configuration has the given report configuration instance as parent.boolean
isLocallyDefined
(String key) Checks, whether the given key is localy defined in this instance or whether the key's value is inherited.protected boolean
Checks, whether the parent configuration can be serialized.private boolean
Returns true if this object has no parent.private void
Helper method for serialization.void
setConfigProperty
(String key, String value) Sets a configuration property.protected void
setParentConfig
(Configuration config) Set the parent configuration.private void
Helper method for serialization.
-
Field Details
-
configuration
The instance configuration properties. -
parentConfiguration
The parent configuration (null if this is the root configuration).
-
-
Constructor Details
-
HierarchicalConfiguration
public HierarchicalConfiguration()Creates a new configuration. -
HierarchicalConfiguration
Creates a new configuration.- Parameters:
parentConfiguration
- the parent configuration.
-
-
Method Details
-
getConfigProperty
Returns the configuration property with the specified key.- Specified by:
getConfigProperty
in interfaceConfiguration
- Parameters:
key
- the property key.- Returns:
- the property value.
-
getConfigProperty
Returns the configuration property with the specified key (or the specified default value if there is no such property).If the property is not defined in this configuration, the code will lookup the property in the parent configuration.
- Specified by:
getConfigProperty
in interfaceConfiguration
- Parameters:
key
- the property key.defaultValue
- the default value.- Returns:
- the property value.
-
setConfigProperty
Sets a configuration property.- Specified by:
setConfigProperty
in interfaceModifiableConfiguration
- Parameters:
key
- the property key.value
- the property value.
-
isRootConfig
private boolean isRootConfig()Returns true if this object has no parent.- Returns:
- true, if this report is the root configuration, false otherwise.
-
isLocallyDefined
Checks, whether the given key is localy defined in this instance or whether the key's value is inherited.- Parameters:
key
- the key that should be checked.- Returns:
- true, if the key is defined locally, false otherwise.
-
getConfiguration
Returns the collection of properties for the configuration.- Returns:
- the properties.
-
insertConfiguration
The new configuartion will be inserted into the list of report configuration, so that this configuration has the given report configuration instance as parent.- Parameters:
config
- the new report configuration.
-
setParentConfig
Set the parent configuration. The parent configuration is queried, if the requested configuration values was not found in this report configuration.- Parameters:
config
- the parent configuration.
-
getParentConfig
Returns the parent configuration. The parent configuration is queried, if the requested configuration values was not found in this report configuration.- Returns:
- the parent configuration.
-
getConfigProperties
Returns all defined configuration properties for the report. The enumeration contains all keys of the changed properties, properties set from files or the system properties are not included.- Specified by:
getConfigProperties
in interfaceConfiguration
- Specified by:
getConfigProperties
in interfaceModifiableConfiguration
- Returns:
- all defined configuration properties for the report.
-
findPropertyKeys
Searches all property keys that start with a given prefix.- Specified by:
findPropertyKeys
in interfaceConfiguration
- Specified by:
findPropertyKeys
in interfaceModifiableConfiguration
- Parameters:
prefix
- the prefix that all selected property keys should share- Returns:
- the properties as iterator.
-
collectPropertyKeys
Collects property keys from this and all parent report configurations, which start with the given prefix.- Parameters:
prefix
- the prefix, that selects the property keys.config
- the currently processed report configuration.collector
- the target list, that should receive all valid keys.
-
isParentSaved
protected boolean isParentSaved()Checks, whether the parent configuration can be serialized. Usually the global configuration is not serialized and should return false here.- Returns:
- true, if the parent config can be serialized, false otherwise.
-
configurationLoaded
protected void configurationLoaded()A callback method to reconnect this configuration with the global configuration after deserialization. -
writeObject
Helper method for serialization.- Parameters:
out
- the output stream where to write the object.- Throws:
IOException
- if errors occur while writing the stream.
-
readObject
Helper method for serialization.- Parameters:
in
- the input stream from where to read the serialized object.- Throws:
IOException
- when reading the stream fails.ClassNotFoundException
- if a class definition for a serialized object could not be found.
-
clone
Returns a clone of this instance.- Specified by:
clone
in interfaceConfiguration
- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- if there is a problem cloning.
-