|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
public abstract class AbstractHierarchicalFileConfiguration
Base class for implementing file based hierarchical configurations.
This class serves an analogous purpose as the
class for non hierarchical
configurations. It behaves in exactly the same way, so please refer to the
documentation of AbstractFileConfiguration
AbstractFileConfiguration
for further details.
Nested Class Summary | |
---|---|
protected class |
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate
A special implementation of the FileConfiguration interface that is
used internally to implement the FileConfiguration methods
for hierarchical configurations. |
Nested classes/interfaces inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.CloneVisitor, HierarchicalConfiguration.DefinedKeysVisitor, HierarchicalConfiguration.DefinedVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor |
Field Summary |
---|
Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
EVENT_ADD_NODES, EVENT_CLEAR_TREE |
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
---|
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
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. the object that implements functionality required by the FileConfiguration interface. |
protected List |
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. |
Iterator |
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. |
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 |
reload()
Reload the configuration. |
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 if it's a file URL. |
void |
setAutoSave(boolean autoSave)
Enable or disable the automatical 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 |
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. |
Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
addNodes, clearNode, clearNode, clearReferences, clone, configurationAt, configurationsAt, createAddPath, createNode, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, getExpressionEngine, getKeys, getMaxIndex, getRoot, getRootNode, nodeDefined, nodeDefined, removeNode, removeNode, setDefaultExpressionEngine, setExpressionEngine, setRoot, setRootNode, subset |
Methods inherited from class org.apache.commons.configuration.event.EventSource |
---|
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.commons.configuration.FileConfiguration |
---|
load, save |
Methods inherited from interface org.apache.commons.configuration.Configuration |
---|
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subset |
Constructor Detail |
---|
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 fileMethod Detail |
---|
protected 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 loaded
ConfigurationException
- if an error occurs during the load operationpublic void load(File file) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
file
- the loaded file
ConfigurationException
- 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 loaded
ConfigurationException
- if an error occurs during the load operationpublic void load(InputStream in) throws ConfigurationException
FileConfiguration
FileConfiguration.getEncoding()
.
load
in interface FileConfiguration
in
- the input stream
ConfigurationException
- 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 encoding
ConfigurationException
- 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 saved
ConfigurationException
- 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 saved
ConfigurationException
- if an error occurs during the save operationpublic void save(URL url) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
url
- the URL
ConfigurationException
- if an error occurs during the save operationpublic void save(OutputStream out) throws ConfigurationException
FileConfiguration
FileConfiguration.getEncoding()
.
save
in interface FileConfiguration
out
- the output stream
ConfigurationException
- 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 used
ConfigurationException
- 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 explictly 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 String getEncoding()
FileConfiguration
getEncoding
in interface FileConfiguration
public void setEncoding(String encoding)
FileConfiguration
setEncoding
in interface FileConfiguration
encoding
- the encoding to usepublic boolean containsKey(String key)
HierarchicalConfiguration
containsKey
in interface Configuration
containsKey
in class HierarchicalConfiguration
key
- the key to be chekced
public Iterator getKeys(String prefix)
HierarchicalConfiguration
getKeys
in interface Configuration
getKeys
in class HierarchicalConfiguration
prefix
- the prefix of the keys to start with
Configuration.getKeys()
public Object getProperty(String key)
HierarchicalConfiguration
getProperty
in interface Configuration
getProperty
in class HierarchicalConfiguration
key
- the key to be looked up
public boolean isEmpty()
HierarchicalConfiguration
isEmpty
in interface Configuration
isEmpty
in class HierarchicalConfiguration
protected List fetchNodeList(String key)
fetchNodeList
in class HierarchicalConfiguration
key
- the key
protected 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 eventprotected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate getDelegate()
protected void setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
delegate
- the new delegate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |