|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.configuration.AbstractConfiguration | +--org.apache.commons.configuration.HierarchicalConfiguration | +--org.apache.commons.configuration.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.
Inner 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. |
Inner classes inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor |
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
END_TOKEN, START_TOKEN |
Constructor Summary | |
protected |
AbstractHierarchicalFileConfiguration()
|
|
AbstractHierarchicalFileConfiguration(File file)
Creates and loads the configuration from the specified file. |
|
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.To be able to deal with the structure supported by this configuration implementation the passed in key is of importance, especially the indices it might contain. |
void |
clearProperty(String key)
Remove a property from the configuration. |
void |
clearTree(String key)
Removes all values of the property with the given name and of keys that start with this name. |
boolean |
containsKey(String key)
Check if the configuration contains the specified key. |
protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate |
createDelegate()
Creates the file configuration delegate, i.e. the object that implements functionality required by the FileConfiguration interface.
|
String |
getBasePath()
Return 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)
Get the list of the keys contained in the configuration that match the specified prefix. |
Object |
getProperty(String key)
Gets a property from the configuration. |
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()
Check if the 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 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 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)
Set 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)
Set a property, this will replace any previously set values. |
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, clone, createAddPath, createNode, fetchAddNode, fetchNodeList, findLastPathNode, findPropertyNodes, getKeys, getMaxIndex, getRoot, nodeDefined, removeNode, setRoot, subset |
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolate, interpolateHelper, isThrowExceptionOnMissing, resolveContainerStore, setDelimiter, setThrowExceptionOnMissing |
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()
public 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
Adds the property with the specified key.
To be able to deal with the structure supported by this configuration implementation the passed in key is of importance, especially the indices it might contain. The following example should clearify this: Suppose the actual configuration contains the following elements:
tables +-- table +-- name = user +-- fields +-- field +-- name = uid +-- field +-- name = firstName ... +-- table +-- name = documents +-- fields ...
In this example a database structure is defined, e.g. all fields
of the first table could be accessed using the key
tables.table(0).fields.field.name
. If now properties are
to be added, it must be exactly specified at which position in the
hierarchy the new property is to be inserted. So to add a new field name
to a table it is not enough to say just
config.addProperty("tables.table.fields.field.name", "newField");
The statement given above contains some ambiguity. For instance
it is not clear, to which table the new field should be added. If this
method finds such an ambiguity, it is resolved by following the last
valid path. Here this would be the last table. The same is true for the
field
; because there are multiple fields and no explicit
index is provided, a new name
property would be added to
the last field - which is propably not what was desired.
To make
things clear explicit indices should be provided whenever possible. In
the example above the exact table could be specified by providing an
index for the table
element as in
tables.table(1).fields
. By specifying an index it can
also be expressed that at a given position in the configuration tree a
new branch should be added. In the example above we did not want to add
an additional name
element to the last field of the table,
but we want a complete new field
element. This can be
achieved by specifying an invalid index (like -1) after the element where
a new branch should be created. Given this our example would run:
config.addProperty("tables.table(1).fields.field(-1).name", "newField");
With this notation it is possible to add new branches
everywhere. We could for instance create a new table
element by specifying
config.addProperty("tables.table(-1).fields.field.name", "newField2");
(Note that because after the table
element a new
branch is created indices in following elements are not relevant; the
branch is new so there cannot be any ambiguities.)
addPropertyDirect
in class HierarchicalConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
key
- the key of the new propertyobj
- the value of the new propertypublic void clearProperty(String key)
Configuration
clearProperty
in interface Configuration
clearProperty
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
key
- the key to remove along with corresponding value.public void clearTree(String key)
HierarchicalConfiguration
clearTree("foo")
would remove both properties.clearTree
in class HierarchicalConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
key
- the key of the property to be removedpublic void setProperty(String key, Object value)
Configuration
setProperty
in interface Configuration
setProperty
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
key
- The key of the property to changevalue
- The new valuepublic void load() throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
ConfigurationException
- if an error occurs during the load operationpublic void load(String fileName) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
org.apache.commons.configuration.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
org.apache.commons.configuration.FileConfiguration
file
- the loaded fileConfigurationException
- if an error occurs during the load operationpublic void load(URL url) throws ConfigurationException
FileConfiguration
load
in interface FileConfiguration
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.FileConfiguration
ConfigurationException
- if an error occurs during the save operationpublic void save(String fileName) throws ConfigurationException
FileConfiguration
save
in interface FileConfiguration
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.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
org.apache.commons.configuration.FileConfiguration
public void setFileName(String fileName)
FileConfiguration
setFileName
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
fileName
- the name of the filepublic String getBasePath()
FileConfiguration
getBasePath
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
public void setBasePath(String basePath)
FileConfiguration
setBasePath
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
basePath
- the base path.public File getFile()
FileConfiguration
getFile
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
public void setFile(File file)
FileConfiguration
setFile
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
file
- the filepublic URL getURL()
FileConfiguration
getURL
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
public void setURL(URL url)
FileConfiguration
setURL
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
url
- the URLpublic void setAutoSave(boolean autoSave)
FileConfiguration
setAutoSave
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
autoSave
- true
to enable, false
to disablepublic boolean isAutoSave()
FileConfiguration
isAutoSave
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
true
if auto-saving is enabled, false
otherwisepublic ReloadingStrategy getReloadingStrategy()
FileConfiguration
getReloadingStrategy
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
public void setReloadingStrategy(ReloadingStrategy strategy)
FileConfiguration
setReloadingStrategy
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
strategy
- the reloading strategy to usepublic void reload()
FileConfiguration
reload
in interface FileConfiguration
public String getEncoding()
FileConfiguration
getEncoding
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
public void setEncoding(String encoding)
FileConfiguration
setEncoding
in interface FileConfiguration
org.apache.commons.configuration.FileConfiguration
encoding
- the encoding to usepublic boolean containsKey(String key)
Configuration
containsKey
in interface Configuration
containsKey
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
key
- the key whose presence in this configuration is to be testedtrue
if the configuration contains a value for this
key, false
otherwisepublic Iterator getKeys(String prefix)
Configuration
getKeys
in interface Configuration
getKeys
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
prefix
- The prefix to test against.Configuration.getKeys()
public Object getProperty(String key)
Configuration
getProperty
in interface Configuration
getProperty
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
key
- property to retrievepublic boolean isEmpty()
Configuration
isEmpty
in interface Configuration
isEmpty
in class HierarchicalConfiguration
org.apache.commons.configuration.Configuration
true
if the configuration contains no property,
false
otherwise.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.protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate getDelegate()
protected void setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
delegate
- the new delegate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |