org.apache.commons.configuration

Class AbstractHierarchicalFileConfiguration

public abstract class AbstractHierarchicalFileConfiguration extends HierarchicalConfiguration implements FileConfiguration, ConfigurationListener

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: $Revision: 492216 $, $Date: 2007-01-03 17:51:24 +0100 (Mi, 03 Jan 2007) $

Author: Emmanuel Bourg

Nested Class Summary
protected classAbstractHierarchicalFileConfiguration.FileConfigurationDelegate
A special implementation of the FileConfiguration interface that is used internally to implement the FileConfiguration methods for hierarchical configurations.
Field Summary
AbstractHierarchicalFileConfiguration.FileConfigurationDelegatedelegate
Stores the delegate used for implementing functionality related to the FileConfiguration interface.
Constructor Summary
protected AbstractHierarchicalFileConfiguration()
Creates a new instance of AbstractHierarchicalFileConfiguration.
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(File file)
Creates and loads the configuration from the specified file.
AbstractHierarchicalFileConfiguration(URL url)
Creates and loads the configuration from the specified URL.
Method Summary
protected voidaddPropertyDirect(String key, Object obj)
voidclearProperty(String key)
voidclearTree(String key)
voidconfigurationChanged(ConfigurationEvent event)
Reacts on configuration change events triggered by the delegate.
booleancontainsKey(String key)
protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegatecreateDelegate()
Creates the file configuration delegate, i.e. the object that implements functionality required by the FileConfiguration interface.
protected ListfetchNodeList(String key)
Fetches a list of nodes, which are selected by the specified key.
StringgetBasePath()
protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegategetDelegate()
Returns the file configuration delegate.
StringgetEncoding()
FilegetFile()
StringgetFileName()
IteratorgetKeys(String prefix)
ObjectgetProperty(String key)
ReloadingStrategygetReloadingStrategy()
URLgetURL()
voidinitDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate del)
Helper method for initializing the file configuration delegate.
voidinitialize()
Initializes this instance, mainly the internally used delegate object.
booleanisAutoSave()
booleanisEmpty()
voidload()
voidload(String fileName)
voidload(File file)
voidload(URL url)
voidload(InputStream in)
voidload(InputStream in, String encoding)
voidreload()
voidsave()
voidsave(String fileName)
voidsave(File file)
voidsave(URL url)
voidsave(OutputStream out)
voidsave(OutputStream out, String encoding)
voidsetAutoSave(boolean autoSave)
voidsetBasePath(String basePath)
protected voidsetDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
Allows to set the file configuration delegate.
voidsetEncoding(String encoding)
voidsetFile(File file)
voidsetFileName(String fileName)
voidsetProperty(String key, Object value)
voidsetReloadingStrategy(ReloadingStrategy strategy)
voidsetURL(URL url)

Field Detail

delegate

private AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate
Stores the delegate used for implementing functionality related to the FileConfiguration interface.

Constructor Detail

AbstractHierarchicalFileConfiguration

protected AbstractHierarchicalFileConfiguration()
Creates a new instance of AbstractHierarchicalFileConfiguration.

AbstractHierarchicalFileConfiguration

protected AbstractHierarchicalFileConfiguration(HierarchicalConfiguration c)
Creates a new instance of AbstractHierarchicalFileConfiguration and copies the content of the specified configuration into this object.

Parameters: c the configuration to copy

Since: 1.4

AbstractHierarchicalFileConfiguration

public AbstractHierarchicalFileConfiguration(String fileName)
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

public AbstractHierarchicalFileConfiguration(File file)
Creates and loads the configuration from the specified file.

Parameters: file The configuration file to load.

Throws: ConfigurationException Error while loading the file

AbstractHierarchicalFileConfiguration

public AbstractHierarchicalFileConfiguration(URL url)
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 Detail

addPropertyDirect

protected void addPropertyDirect(String key, Object obj)

clearProperty

public void clearProperty(String key)

clearTree

public void clearTree(String key)

configurationChanged

public void configurationChanged(ConfigurationEvent event)
Reacts on configuration change events triggered by the delegate. These events are passed to the registered configuration listeners.

Parameters: event the triggered event

Since: 1.3

containsKey

public boolean containsKey(String key)

createDelegate

protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate createDelegate()
Creates the file configuration delegate, i.e. the object that implements functionality required by the FileConfiguration interface. This base implementation will return an instance of the FileConfigurationDelegate class. Derived classes may override it to create a different delegate object.

Returns: the file configuration delegate

fetchNodeList

protected List fetchNodeList(String key)
Fetches a list of nodes, which are selected by the specified key. This implementation will perform a reload if necessary.

Parameters: key the key

Returns: a list with the selected nodes

getBasePath

public String getBasePath()

getDelegate

protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate getDelegate()
Returns the file configuration delegate.

Returns: the delegate

getEncoding

public String getEncoding()

getFile

public File getFile()

getFileName

public String getFileName()

getKeys

public Iterator getKeys(String prefix)

getProperty

public Object getProperty(String key)

getReloadingStrategy

public ReloadingStrategy getReloadingStrategy()

getURL

public URL getURL()

initDelegate

private void initDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate del)
Helper method for initializing the file configuration delegate.

Parameters: del the delegate

initialize

private void initialize()
Initializes this instance, mainly the internally used delegate object.

isAutoSave

public boolean isAutoSave()

isEmpty

public boolean isEmpty()

load

public void load()

load

public void load(String fileName)

load

public void load(File file)

load

public void load(URL url)

load

public void load(InputStream in)

load

public void load(InputStream in, String encoding)

reload

public void reload()

save

public void save()

save

public void save(String fileName)

save

public void save(File file)

save

public void save(URL url)

save

public void save(OutputStream out)

save

public void save(OutputStream out, String encoding)

setAutoSave

public void setAutoSave(boolean autoSave)

setBasePath

public void setBasePath(String basePath)

setDelegate

protected void setDelegate(AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate)
Allows to set the file configuration delegate.

Parameters: delegate the new delegate

setEncoding

public void setEncoding(String encoding)

setFile

public void setFile(File file)

setFileName

public void setFileName(String fileName)

setProperty

public void setProperty(String key, Object value)

setReloadingStrategy

public void setReloadingStrategy(ReloadingStrategy strategy)

setURL

public void setURL(URL url)