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.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate
A special implementation of the
FileConfiguration interface that is
used internally to implement the FileConfiguration methods
for hierarchical configurations. |
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGED
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN
Modifier | Constructor and Description |
---|---|
protected |
AbstractHierarchicalFileConfiguration()
Creates a new instance of
AbstractHierarchicalFileConfiguration . |
|
AbstractHierarchicalFileConfiguration(File file)
Creates and loads the configuration from the specified file.
|
protected |
AbstractHierarchicalFileConfiguration(HierarchicalConfiguration c)
Creates a new instance of
AbstractHierarchicalFileConfiguration and copies the
content of the specified configuration into this object. |
|
AbstractHierarchicalFileConfiguration(String fileName)
Creates and loads the configuration from the specified file.
|
|
AbstractHierarchicalFileConfiguration(URL url)
Creates and loads the configuration from the specified URL.
|
Modifier and Type | Method and Description |
---|---|
void |
addNodes(String key,
Collection<? extends ConfigurationNode> nodes)
Directly adds sub nodes to this configuration.
|
protected void |
addPropertyDirect(String key,
Object obj)
Adds the property with the specified key.
|
void |
clearProperty(String key)
Removes the property with the given key.
|
void |
clearTree(String key)
Removes all values of the property with the given name and of keys that
start with this name.
|
void |
configurationChanged(ConfigurationEvent event)
Reacts on configuration change events triggered by the delegate.
|
void |
configurationError(ConfigurationErrorEvent event)
Notifies this listener that in an observed configuration an error
occurred.
|
boolean |
containsKey(String key)
Checks if the specified key is contained in this configuration.
|
protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate |
createDelegate()
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.
|
String |
getBasePath()
Returns the base path.
|
protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate |
getDelegate()
Returns the file configuration delegate.
|
String |
getEncoding()
Return the encoding used to store the configuration file.
|
File |
getFile()
Return the file where the configuration is stored.
|
String |
getFileName()
Return the name of the file.
|
FileSystem |
getFileSystem()
Retrieve the FileSystem being used.
|
Iterator<String> |
getKeys()
Returns an iterator with all keys defined in this configuration.
|
Iterator<String> |
getKeys(String prefix)
Returns an iterator with all keys defined in this configuration that
start with the given prefix.
|
Object |
getProperty(String key)
Fetches the specified property.
|
ReloadingStrategy |
getReloadingStrategy()
Return the reloading strategy.
|
Object |
getReloadLock()
Returns the object to synchronize on a reload.
|
URL |
getURL()
Return the URL where the configuration is stored.
|
boolean |
isAutoSave()
Tells if properties are automatically saved to the disk.
|
boolean |
isEmpty()
Checks if this configuration is empty.
|
void |
load()
Load the configuration from the underlying URL.
|
void |
load(File file)
Load the configuration from the specified file.
|
void |
load(InputStream in)
Load the configuration from the specified stream, using the encoding
returned by
FileConfiguration.getEncoding() . |
void |
load(InputStream in,
String encoding)
Load the configuration from the specified stream, using the specified
encoding.
|
void |
load(String fileName)
Locate the specified file and load the configuration.
|
void |
load(URL url)
Load the configuration from the specified URL.
|
void |
refresh()
Reloads the associated configuration file.
|
void |
reload()
Reload the configuration.
|
void |
resetFileSystem()
Reset the FileSystem to the default;
|
void |
save()
Save the configuration.
|
void |
save(File file)
Save the configuration to the specified file.
|
void |
save(OutputStream out)
Save the configuration to the specified stream, using the encoding
returned by
FileConfiguration.getEncoding() . |
void |
save(OutputStream out,
String encoding)
Save the configuration to the specified stream, using the specified
encoding.
|
void |
save(String fileName)
Save the configuration to the specified file.
|
void |
save(URL url)
Save the configuration to the specified URL.
|
void |
setAutoSave(boolean autoSave)
Enable or disable the automatically saving of modified properties to the disk.
|
void |
setBasePath(String basePath)
Sets the base path.
|
protected void |
setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
Allows to set the file configuration delegate.
|
void |
setEncoding(String encoding)
Set the encoding used to store the configuration file.
|
void |
setFile(File file)
Set the file where the configuration is stored.
|
void |
setFileName(String fileName)
Set the name of the file.
|
void |
setFileSystem(FileSystem fileSystem)
Set the FileSystem to be used for this Configuration.
|
void |
setProperty(String key,
Object value)
Sets the value of the specified property.
|
void |
setReloadingStrategy(ReloadingStrategy strategy)
Set the reloading strategy.
|
void |
setURL(URL url)
The URL where the configuration is stored.
|
protected void |
subnodeConfigurationChanged(ConfigurationEvent event)
Reacts on changes of an associated subnode configuration.
|
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, subset
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, setThrowExceptionOnMissing
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
load, save
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, subset
protected AbstractHierarchicalFileConfiguration()
AbstractHierarchicalFileConfiguration
.protected AbstractHierarchicalFileConfiguration(HierarchicalConfiguration c)
AbstractHierarchicalFileConfiguration
and copies the
content of the specified configuration into this object.c
- the configuration to copypublic AbstractHierarchicalFileConfiguration(String fileName) throws ConfigurationException
fileName
- The name of the plist file to load.ConfigurationException
- Error while loading the filepublic AbstractHierarchicalFileConfiguration(File file) throws ConfigurationException
file
- The configuration file to load.ConfigurationException
- Error while loading the filepublic AbstractHierarchicalFileConfiguration(URL url) throws ConfigurationException
url
- The location of the configuration file to load.ConfigurationException
- Error while loading the fileprotected void addPropertyDirect(String key, Object obj)
HierarchicalConfiguration
ExpressionEngine
, so the passed in key
must match the requirements of this implementation.addPropertyDirect
in class HierarchicalConfiguration
key
- the key of the new propertyobj
- the value of the new propertypublic void clearProperty(String key)
HierarchicalConfiguration
clearProperty
in interface Configuration
clearProperty
in class HierarchicalConfiguration
key
- the key of the property to be removedpublic void clearTree(String key)
HierarchicalConfiguration
clearTree("foo")
would remove both properties.clearTree
in class HierarchicalConfiguration
key
- the key of the property to be removedpublic void setProperty(String key, Object value)
HierarchicalConfiguration
setProperty
in interface Configuration
setProperty
in class HierarchicalConfiguration
key
- the key of the property to setvalue
- the new value of this propertypublic void load() throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
ConfigurationException
- if an error occurs during the load operationpublic void load(String fileName) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
fileName
- the name of the file loadedConfigurationException
- if an error occurs during the load operationpublic void load(File file) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
file
- the loaded fileConfigurationException
- if an error occurs during the load operationpublic void load(URL url) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
url
- the URL of the file loadedConfigurationException
- if an error occurs during the load operationpublic void load(InputStream in) throws ConfigurationException
FileConfiguration
FileConfiguration.getEncoding()
.load
in interface FileConfiguration
in
- the input streamConfigurationException
- if an error occurs during the load operationpublic void load(InputStream in, String encoding) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
in
- the input streamencoding
- the encoding used. null
to use the default encodingConfigurationException
- if an error occurs during the load operationpublic void save() throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
ConfigurationException
- if an error occurs during the save operationpublic void save(String fileName) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
fileName
- the name of the file to be savedConfigurationException
- if an error occurs during the save operationpublic void save(File file) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
file
- specifies the file to be savedConfigurationException
- if an error occurs during the save operationpublic void save(URL url) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
url
- the URLConfigurationException
- if an error occurs during the save operationpublic void save(OutputStream out) throws ConfigurationException
FileConfiguration
FileConfiguration.getEncoding()
.save
in interface FileConfiguration
out
- the output streamConfigurationException
- if an error occurs during the save operationpublic void save(OutputStream out, String encoding) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
out
- the output streamencoding
- the encoding to be usedConfigurationException
- if an error occurs during the save operationpublic String getFileName()
FileConfiguration
getFileName
in interface FileConfiguration
public void setFileName(String fileName)
FileConfiguration
setFileName
in interface FileConfiguration
fileName
- the name of the filepublic String getBasePath()
FileConfiguration
setFile()
or setURL()
were used, the base
path typically points to the parent directory of the configuration file
(e.g. for the URL file:/temp/test.properties
the base path
will be file:/temp/
). If the base path was explicitly set
using setBasePath()
, this method will return the exact
value specified here without further modifications.getBasePath
in interface FileConfiguration
AbstractFileConfiguration.setBasePath(String)
public void setBasePath(String basePath)
FileConfiguration
setBasePath()
and
setFileName()
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 by
PropertiesConfiguration
), this base path will be used.setBasePath
in interface FileConfiguration
basePath
- the base path.public File getFile()
FileConfiguration
getFile
in interface FileConfiguration
public void setFile(File file)
FileConfiguration
setFile
in interface FileConfiguration
file
- the filepublic URL getURL()
FileConfiguration
getURL
in interface FileConfiguration
public void setURL(URL url)
FileConfiguration
setURL
in interface FileConfiguration
url
- the URLpublic void setAutoSave(boolean autoSave)
FileConfiguration
setAutoSave
in interface FileConfiguration
autoSave
- true
to enable, false
to disablepublic boolean isAutoSave()
FileConfiguration
isAutoSave
in interface FileConfiguration
true
if auto-saving is enabled, false
otherwisepublic ReloadingStrategy getReloadingStrategy()
FileConfiguration
getReloadingStrategy
in interface FileConfiguration
public void setReloadingStrategy(ReloadingStrategy strategy)
FileConfiguration
setReloadingStrategy
in interface FileConfiguration
strategy
- the reloading strategy to usepublic void reload()
FileConfiguration
reload
in interface FileConfiguration
public void refresh() throws ConfigurationException
reload()
without checking the reloading strategy.ConfigurationException
- if an error occurspublic String getEncoding()
FileConfiguration
getEncoding
in interface FileConfiguration
public void setEncoding(String encoding)
FileConfiguration
setEncoding
in interface FileConfiguration
encoding
- the encoding to usepublic Object getReloadLock()
HierarchicalConfiguration
getReloadLock
in interface Reloadable
getReloadLock
in class HierarchicalConfiguration
public boolean containsKey(String key)
HierarchicalConfiguration
containsKey
in interface Configuration
containsKey
in class HierarchicalConfiguration
key
- the key to be chekcedpublic Iterator<String> getKeys()
HierarchicalConfiguration
getKeys
in interface Configuration
getKeys
in class HierarchicalConfiguration
public Iterator<String> getKeys(String prefix)
HierarchicalConfiguration
getKeys
in interface Configuration
getKeys
in class HierarchicalConfiguration
prefix
- the prefix of the keys to start withConfiguration.getKeys()
public Object getProperty(String key)
HierarchicalConfiguration
getProperty
in interface Configuration
getProperty
in class HierarchicalConfiguration
key
- the key to be looked uppublic boolean isEmpty()
HierarchicalConfiguration
isEmpty
in interface Configuration
isEmpty
in class HierarchicalConfiguration
public void addNodes(String key, Collection<? extends ConfigurationNode> nodes)
addNodes
in class HierarchicalConfiguration
key
- the key where the nodes are to be addednodes
- a collection with the nodes to be addedprotected List<ConfigurationNode> fetchNodeList(String key)
fetchNodeList
in class HierarchicalConfiguration
key
- the keyprotected void subnodeConfigurationChanged(ConfigurationEvent event)
subnodeConfigurationChanged
in class HierarchicalConfiguration
event
- the event describing the changeprotected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate createDelegate()
FileConfiguration
interface.
This base implementation will return an instance of the
FileConfigurationDelegate
class. Derived classes may
override it to create a different delegate object.public void configurationChanged(ConfigurationEvent event)
configurationChanged
in interface ConfigurationListener
event
- the triggered eventpublic void configurationError(ConfigurationErrorEvent event)
ConfigurationErrorListener
Throwable
object, can be obtained from the passed
in event object.configurationError
in interface ConfigurationErrorListener
event
- the event object with information about the errorprotected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate getDelegate()
protected void setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
delegate
- the new delegatepublic void setFileSystem(FileSystem fileSystem)
setFileSystem
in interface FileSystemBased
fileSystem
- The FileSystem to use.public void resetFileSystem()
resetFileSystem
in interface FileSystemBased
public FileSystem getFileSystem()
getFileSystem
in interface FileSystemBased
Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.