Class AbstractHierarchicalFileConfiguration
java.lang.Object
org.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
- All Implemented Interfaces:
Serializable, Cloneable, Configuration, ConfigurationErrorListener, ConfigurationListener, FileConfiguration, FileSystemBased, Reloadable
- Direct Known Subclasses:
HierarchicalINIConfiguration, MultiFileHierarchicalConfiguration, PatternSubtreeConfigurationWrapper, PropertyListConfiguration, XMLConfiguration, XMLPropertyListConfiguration
public abstract class AbstractHierarchicalFileConfiguration
extends HierarchicalConfiguration
implements FileConfiguration, ConfigurationListener, ConfigurationErrorListener, FileSystemBased, Reloadable
Base class for implementing file based hierarchical configurations.
This class serves an analogous purpose as the
AbstractFileConfiguration class for non hierarchical
configurations. It behaves in exactly the same way, so please refer to the
documentation of AbstractFileConfiguration for further details.
- Since:
- 1.2
- Version:
- $Id: AbstractHierarchicalFileConfiguration.java 1206575 2011-11-26 20:07:52Z oheger $
- Author:
- Emmanuel Bourg
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA special implementation of theFileConfigurationinterface that is used internally to implement theFileConfigurationmethods for hierarchical configurations.Nested classes/interfaces inherited from class HierarchicalConfiguration
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor -
Field Summary
Fields inherited from class HierarchicalConfiguration
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGEDFields inherited from class AbstractConfiguration
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance ofAbstractHierarchicalFileConfiguration.Creates and loads the configuration from the specified file.AbstractHierarchicalFileConfiguration(String fileName) Creates and loads the configuration from the specified file.Creates and loads the configuration from the specified URL.protectedCreates a new instance ofAbstractHierarchicalFileConfigurationand copies the content of the specified configuration into this object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNodes(String key, Collection<? extends ConfigurationNode> nodes) Directly adds sub nodes to this configuration.protected voidaddPropertyDirect(String key, Object obj) Adds the property with the specified key.voidclearProperty(String key) Removes the property with the given key.voidRemoves all values of the property with the given name and of keys that start with this name.voidReacts on configuration change events triggered by the delegate.voidNotifies this listener that in an observed configuration an error occurred.booleancontainsKey(String key) Checks if the specified key is contained in this configuration.Creates the file configuration delegate, i.e.protected List<ConfigurationNode> fetchNodeList(String key) Fetches a list of nodes, which are selected by the specified key.Returns the base path.Returns the file configuration delegate.Return the encoding used to store the configuration file.getFile()Return the file where the configuration is stored.Return the name of the file.Retrieve the FileSystem being used.getKeys()Returns an iterator with all keys defined in this configuration.Returns an iterator with all keys defined in this configuration that start with the given prefix.getProperty(String key) Fetches the specified property.Return the reloading strategy.Returns the object to synchronize on a reload.getURL()Return the URL where the configuration is stored.booleanTells if properties are automatically saved to the disk.booleanisEmpty()Checks if this configuration is empty.voidload()Load the configuration from the underlying URL.voidLoad the configuration from the specified file.voidload(InputStream in) Load the configuration from the specified stream, using the encoding returned byFileConfiguration.getEncoding().voidload(InputStream in, String encoding) Load the configuration from the specified stream, using the specified encoding.voidLocate the specified file and load the configuration.voidLoad the configuration from the specified URL.voidrefresh()Reloads the associated configuration file.voidreload()Reload the configuration.voidReset the FileSystem to the default;voidsave()Save the configuration.voidSave the configuration to the specified file.voidsave(OutputStream out) Save the configuration to the specified stream, using the encoding returned byFileConfiguration.getEncoding().voidsave(OutputStream out, String encoding) Save the configuration to the specified stream, using the specified encoding.voidSave the configuration to the specified file.voidSave the configuration to the specified URL.voidsetAutoSave(boolean autoSave) Enable or disable the automatically saving of modified properties to the disk.voidsetBasePath(String basePath) Sets the base path.protected voidAllows to set the file configuration delegate.voidsetEncoding(String encoding) Set the encoding used to store the configuration file.voidSet the file where the configuration is stored.voidsetFileName(String fileName) Set the name of the file.voidsetFileSystem(FileSystem fileSystem) Set the FileSystem to be used for this Configuration.voidsetProperty(String key, Object value) Sets the value of the specified property.voidsetReloadingStrategy(ReloadingStrategy strategy) Set the reloading strategy.voidThe URL where the configuration is stored.protected voidReacts on changes of an associated subnode configuration.Methods inherited from class HierarchicalConfiguration
clear, clearNode, clearNode, clearReferences, clone, configurationAt, configurationAt, configurationsAt, createAddPath, createNode, createSubnodeConfiguration, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, getExpressionEngine, getMaxIndex, getRoot, getRootNode, interpolatedConfiguration, nodeDefined, nodeDefined, removeNode, removeNode, setDefaultExpressionEngine, setExpressionEngine, setRoot, setRootNode, subsetMethods inherited from class AbstractConfiguration
addErrorLogListener, addProperty, append, clearPropertyDirect, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissingMethods inherited from class EventSource
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEventsMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Configuration
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subsetMethods inherited from interface FileConfiguration
load, save
-
Constructor Details
-
AbstractHierarchicalFileConfiguration
protected AbstractHierarchicalFileConfiguration()Creates a new instance ofAbstractHierarchicalFileConfiguration. -
AbstractHierarchicalFileConfiguration
Creates a new instance ofAbstractHierarchicalFileConfigurationand copies the content of the specified configuration into this object.- Parameters:
c- the configuration to copy- Since:
- 1.4
-
AbstractHierarchicalFileConfiguration
Creates and loads the configuration from the specified file.- Parameters:
fileName- The name of the plist file to load.- Throws:
ConfigurationException- Error while loading the file
-
AbstractHierarchicalFileConfiguration
Creates and loads the configuration from the specified file.- Parameters:
file- The configuration file to load.- Throws:
ConfigurationException- Error while loading the file
-
AbstractHierarchicalFileConfiguration
Creates and loads the configuration from the specified URL.- Parameters:
url- The location of the configuration file to load.- Throws:
ConfigurationException- Error while loading the file
-
-
Method Details
-
addPropertyDirect
Description copied from class:HierarchicalConfigurationAdds the property with the specified key. This task will be delegated to the associatedExpressionEngine, so the passed in key must match the requirements of this implementation.- Overrides:
addPropertyDirectin classHierarchicalConfiguration- Parameters:
key- the key of the new propertyobj- the value of the new property
-
clearProperty
Description copied from class:HierarchicalConfigurationRemoves the property with the given key. Properties with names that start with the given key (i.e. properties below the specified key in the hierarchy) won't be affected.- Specified by:
clearPropertyin interfaceConfiguration- Overrides:
clearPropertyin classHierarchicalConfiguration- Parameters:
key- the key of the property to be removed
-
clearTree
Description copied from class:HierarchicalConfigurationRemoves all values of the property with the given name and of keys that start with this name. So if there is a property with the key "foo" and a property with the key "foo.bar", a call ofclearTree("foo")would remove both properties.- Overrides:
clearTreein classHierarchicalConfiguration- Parameters:
key- the key of the property to be removed
-
setProperty
Description copied from class:HierarchicalConfigurationSets the value of the specified property.- Specified by:
setPropertyin interfaceConfiguration- Overrides:
setPropertyin classHierarchicalConfiguration- Parameters:
key- the key of the property to setvalue- the new value of this property
-
load
Description copied from interface:FileConfigurationLoad the configuration from the underlying URL. If the URL is not specified, it attempts to locate the specified file name.- Specified by:
loadin interfaceFileConfiguration- Throws:
ConfigurationException- if an error occurs during the load operation
-
load
Description copied from interface:FileConfigurationLocate the specified file and load the configuration.- Specified by:
loadin interfaceFileConfiguration- Parameters:
fileName- the name of the file loaded- Throws:
ConfigurationException- if an error occurs during the load operation
-
load
Description copied from interface:FileConfigurationLoad the configuration from the specified file.- Specified by:
loadin interfaceFileConfiguration- Parameters:
file- the loaded file- Throws:
ConfigurationException- if an error occurs during the load operation
-
load
Description copied from interface:FileConfigurationLoad the configuration from the specified URL.- Specified by:
loadin interfaceFileConfiguration- Parameters:
url- the URL of the file loaded- Throws:
ConfigurationException- if an error occurs during the load operation
-
load
Description copied from interface:FileConfigurationLoad the configuration from the specified stream, using the encoding returned byFileConfiguration.getEncoding().- Specified by:
loadin interfaceFileConfiguration- Parameters:
in- the input stream- Throws:
ConfigurationException- if an error occurs during the load operation
-
load
Description copied from interface:FileConfigurationLoad the configuration from the specified stream, using the specified encoding. If the encoding is null the default encoding is used.- Specified by:
loadin interfaceFileConfiguration- Parameters:
in- the input streamencoding- the encoding used.nullto use the default encoding- Throws:
ConfigurationException- if an error occurs during the load operation
-
save
Description copied from interface:FileConfigurationSave the configuration.- Specified by:
savein interfaceFileConfiguration- Throws:
ConfigurationException- if an error occurs during the save operation
-
save
Description copied from interface:FileConfigurationSave the configuration to the specified file.- Specified by:
savein interfaceFileConfiguration- Parameters:
fileName- the name of the file to be saved- Throws:
ConfigurationException- if an error occurs during the save operation
-
save
Description copied from interface:FileConfigurationSave the configuration to the specified file.- Specified by:
savein interfaceFileConfiguration- Parameters:
file- specifies the file to be saved- Throws:
ConfigurationException- if an error occurs during the save operation
-
save
Description copied from interface:FileConfigurationSave the configuration to the specified URL.- Specified by:
savein interfaceFileConfiguration- Parameters:
url- the URL- Throws:
ConfigurationException- if an error occurs during the save operation
-
save
Description copied from interface:FileConfigurationSave the configuration to the specified stream, using the encoding returned byFileConfiguration.getEncoding().- Specified by:
savein interfaceFileConfiguration- Parameters:
out- the output stream- Throws:
ConfigurationException- if an error occurs during the save operation
-
save
Description copied from interface:FileConfigurationSave the configuration to the specified stream, using the specified encoding. If the encoding is null the default encoding is used.- Specified by:
savein interfaceFileConfiguration- Parameters:
out- the output streamencoding- the encoding to be used- Throws:
ConfigurationException- if an error occurs during the save operation
-
getFileName
Description copied from interface:FileConfigurationReturn the name of the file.- Specified by:
getFileNamein interfaceFileConfiguration- Returns:
- the file name
-
setFileName
Description copied from interface:FileConfigurationSet the name of the file.- Specified by:
setFileNamein interfaceFileConfiguration- Parameters:
fileName- the name of the file
-
getBasePath
Description copied from interface:FileConfigurationReturns the base path. One way to specify the location of a configuration source is by setting its base path and its file name. This method returns this base path. The concrete value returned by this method depends on the way the location of the configuration file was set. If methods likesetFile()orsetURL()were used, the base path typically points to the parent directory of the configuration file (e.g. for the URLfile:/temp/test.propertiesthe base path will befile:/temp/). If the base path was explicitly set usingsetBasePath(), this method will return the exact value specified here without further modifications.- Specified by:
getBasePathin interfaceFileConfiguration- Returns:
- the base path
- See Also:
-
setBasePath
Description copied from interface:FileConfigurationSets the base path. The methodssetBasePath()andsetFileName()can be used together to specify the location of the configuration file to be loaded. If relative file names are to be resolved (e.g. for the include files supported byPropertiesConfiguration), this base path will be used.- Specified by:
setBasePathin interfaceFileConfiguration- Parameters:
basePath- the base path.
-
getFile
Description copied from interface:FileConfigurationReturn the file where the configuration is stored.- Specified by:
getFilein interfaceFileConfiguration- Returns:
- the configuration file
-
setFile
Description copied from interface:FileConfigurationSet the file where the configuration is stored.- Specified by:
setFilein interfaceFileConfiguration- Parameters:
file- the file
-
getURL
Description copied from interface:FileConfigurationReturn the URL where the configuration is stored.- Specified by:
getURLin interfaceFileConfiguration- Returns:
- the URL of the configuration
-
setURL
Description copied from interface:FileConfigurationThe URL where the configuration is stored.- Specified by:
setURLin interfaceFileConfiguration- Parameters:
url- the URL
-
setAutoSave
Description copied from interface:FileConfigurationEnable or disable the automatically saving of modified properties to the disk.- Specified by:
setAutoSavein interfaceFileConfiguration- Parameters:
autoSave-trueto enable,falseto disable
-
isAutoSave
Description copied from interface:FileConfigurationTells if properties are automatically saved to the disk.- Specified by:
isAutoSavein interfaceFileConfiguration- Returns:
trueif auto-saving is enabled,falseotherwise
-
getReloadingStrategy
Description copied from interface:FileConfigurationReturn the reloading strategy.- Specified by:
getReloadingStrategyin interfaceFileConfiguration- Returns:
- the reloading strategy currently used
-
setReloadingStrategy
Description copied from interface:FileConfigurationSet the reloading strategy.- Specified by:
setReloadingStrategyin interfaceFileConfiguration- Parameters:
strategy- the reloading strategy to use
-
reload
Description copied from interface:FileConfigurationReload the configuration.- Specified by:
reloadin interfaceFileConfiguration
-
refresh
Reloads the associated configuration file. This method first clears the content of this configuration, then the associated configuration file is loaded again. Updates on this configuration which have not yet been saved are lost. Calling this method is like invokingreload()without checking the reloading strategy.- Throws:
ConfigurationException- if an error occurs- Since:
- 1.7
-
getEncoding
Description copied from interface:FileConfigurationReturn the encoding used to store the configuration file. If the value is null the default encoding is used.- Specified by:
getEncodingin interfaceFileConfiguration- Returns:
- the current encoding
-
setEncoding
Description copied from interface:FileConfigurationSet the encoding used to store the configuration file. Set the encoding to null to use the default encoding.- Specified by:
setEncodingin interfaceFileConfiguration- Parameters:
encoding- the encoding to use
-
getReloadLock
Description copied from class:HierarchicalConfigurationReturns the object to synchronize on a reload. This class is not reloadable so this object isn't important- Specified by:
getReloadLockin interfaceReloadable- Overrides:
getReloadLockin classHierarchicalConfiguration- Returns:
- the lock object
-
containsKey
Description copied from class:HierarchicalConfigurationChecks if the specified key is contained in this configuration. Note that for this configuration the term "contained" means that the key has an associated value. If there is a node for this key that has no value but children (either defined or undefined), this method will still return false .- Specified by:
containsKeyin interfaceConfiguration- Overrides:
containsKeyin classHierarchicalConfiguration- Parameters:
key- the key to be chekced- Returns:
- a flag if this key is contained in this configuration
-
getKeys
Description copied from class:HierarchicalConfigurationReturns an iterator with all keys defined in this configuration. Note that the keys returned by this method will not contain any indices. This means that some structure will be lost.- Specified by:
getKeysin interfaceConfiguration- Overrides:
getKeysin classHierarchicalConfiguration- Returns:
- an iterator with the defined keys in this configuration
-
getKeys
Description copied from class:HierarchicalConfigurationReturns an iterator with all keys defined in this configuration that start with the given prefix. The returned keys will not contain any indices. This implementation tries to locate a node whose key is the same as the passed in prefix. Then the subtree of this node is traversed, and the keys of all nodes encountered (including attributes) are added to the result set.- Specified by:
getKeysin interfaceConfiguration- Overrides:
getKeysin classHierarchicalConfiguration- Parameters:
prefix- the prefix of the keys to start with- Returns:
- an iterator with the found keys
- See Also:
-
getProperty
Description copied from class:HierarchicalConfigurationFetches the specified property. This task is delegated to the associated expression engine.- Specified by:
getPropertyin interfaceConfiguration- Overrides:
getPropertyin classHierarchicalConfiguration- Parameters:
key- the key to be looked up- Returns:
- the found value
-
isEmpty
Description copied from class:HierarchicalConfigurationChecks if this configuration is empty. Empty means that there are no keys with any values, though there can be some (empty) nodes.- Specified by:
isEmptyin interfaceConfiguration- Overrides:
isEmptyin classHierarchicalConfiguration- Returns:
- a flag if this configuration is empty
-
addNodes
Directly adds sub nodes to this configuration. This implementation checks whether auto save is necessary after executing the operation.- Overrides:
addNodesin classHierarchicalConfiguration- Parameters:
key- the key where the nodes are to be addednodes- a collection with the nodes to be added- Since:
- 1.5
-
fetchNodeList
Fetches a list of nodes, which are selected by the specified key. This implementation will perform a reload if necessary.- Overrides:
fetchNodeListin classHierarchicalConfiguration- Parameters:
key- the key- Returns:
- a list with the selected nodes
-
subnodeConfigurationChanged
Reacts on changes of an associated subnode configuration. If the auto save mechanism is active, the configuration must be saved.- Overrides:
subnodeConfigurationChangedin classHierarchicalConfiguration- Parameters:
event- the event describing the change- Since:
- 1.5
-
createDelegate
Creates the file configuration delegate, i.e. the object that implements functionality required by theFileConfigurationinterface. This base implementation will return an instance of theFileConfigurationDelegateclass. Derived classes may override it to create a different delegate object.- Returns:
- the file configuration delegate
-
configurationChanged
Reacts on configuration change events triggered by the delegate. These events are passed to the registered configuration listeners.- Specified by:
configurationChangedin interfaceConfigurationListener- Parameters:
event- the triggered event- Since:
- 1.3
-
configurationError
Description copied from interface:ConfigurationErrorListenerNotifies this listener that in an observed configuration an error occurred. All information available about this error, including the causingThrowableobject, can be obtained from the passed in event object.- Specified by:
configurationErrorin interfaceConfigurationErrorListener- Parameters:
event- the event object with information about the error
-
getDelegate
Returns the file configuration delegate.- Returns:
- the delegate
-
setDelegate
protected void setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate) Allows to set the file configuration delegate.- Parameters:
delegate- the new delegate
-
setFileSystem
Set the FileSystem to be used for this Configuration.- Specified by:
setFileSystemin interfaceFileSystemBased- Parameters:
fileSystem- The FileSystem to use.
-
resetFileSystem
Reset the FileSystem to the default;- Specified by:
resetFileSystemin interfaceFileSystemBased
-
getFileSystem
Retrieve the FileSystem being used.- Specified by:
getFileSystemin interfaceFileSystemBased- Returns:
- The FileSystem.
-