|
|||||||||||
| 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.BaseConfiguration
org.apache.commons.configuration.AbstractFileConfiguration
Partial implementation of the FileConfiguration interface.
Developpers of file based configuration may want to extend this class,
the two methods left to implement are
and FileConfiguration.load(Reader)FileConfiguration.save(Writer).
This base class already implements a couple of ways to specify the location of the file this configuration is based on. The following possibilities exist:
setURL() a full URL to the
configuration source can be specified. This is the most flexible way. Note
that the save() methods support only file: URLs.setFile() method allows to specify the
configuration source as a file. This can be either a relative or an
absolute file. In the former case the file is resolved based on the current
directory.setPath() method a
full path to a configuration file can be provided as a string.setBasePath()
method. The file name, non surprisingly, defines the name of the configuration
file.Note that the load() methods do not wipe out the configuration's
content before the new configuration file is loaded. Thus it is very easy to
construct a union configuration by simply loading multiple configuration
files, e.g.
config.load(configFile1); config.load(configFile2);
After executing this code fragment, the resulting configuration will
contain both the properties of configFile1 and configFile2. On the other
hand, if the current configuration file is to be reloaded, clear()
should be called first. Otherwise the properties are doubled. This behavior
is analogous to the behavior of the load(InputStream) method
in java.util.Properties.
| Field Summary | |
protected boolean |
autoSave
The auto save flag. |
protected String |
basePath
Stores the base path. |
static int |
EVENT_RELOAD
Constant for the configuration reload event. |
protected String |
fileName
Stores the file name. |
protected ReloadingStrategy |
strategy
Holds a reference to the reloading strategy. |
| Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN |
| Constructor Summary | |
AbstractFileConfiguration()
Default constructor |
|
AbstractFileConfiguration(File file)
Creates and loads the configuration from the specified file. |
|
AbstractFileConfiguration(String fileName)
Creates and loads the configuration from the specified file. |
|
AbstractFileConfiguration(URL url)
Creates and loads the configuration from the specified URL. |
|
| Method Summary | |
void |
addProperty(String key,
Object value)
Adds a new property to this configuration. |
void |
clearProperty(String key)
Remove a property from the configuration. |
Object |
clone()
Creates a copy of this configuration. |
boolean |
containsKey(String key)
Check if the configuration contains the specified key. |
protected void |
enterNoReload()
Enters the "No reloading mode". |
protected void |
exitNoReload()
Leaves the "No reloading mode". |
protected void |
fireEvent(int type,
String propName,
Object propValue,
boolean before)
Sends an event to all registered listeners. |
String |
getBasePath()
Return the base path. |
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()
Get the list of the keys contained in the configuration. |
String |
getPath()
Returns the full path to the file this configuration is based on. |
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 location. |
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. |
protected void |
possiblySave()
Save the configuration if the automatic persistence is enabled and if a file is specified. |
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. |
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 |
setPath(String path)
Sets the location of this configuration as a full or relative path name. |
void |
setProperty(String key,
Object value)
Sets a new value for the specified property. |
void |
setReloadingStrategy(ReloadingStrategy strategy)
Set the reloading strategy. |
void |
setURL(URL url)
Set the location of this configuration as a URL. |
| Methods inherited from class org.apache.commons.configuration.BaseConfiguration |
addPropertyDirect, clear, clearPropertyDirect |
| Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getListDelimiter, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolate, interpolateHelper, isDelimiterParsingDisabled, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setThrowExceptionOnMissing, subset |
| Methods inherited from class org.apache.commons.configuration.event.EventSource |
addConfigurationListener, clearConfigurationListeners, createEvent, getConfigurationListeners, isDetailEvents, removeConfigurationListener, 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 |
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 |
| Field Detail |
public static final int EVENT_RELOAD
protected String fileName
protected String basePath
protected boolean autoSave
protected ReloadingStrategy strategy
| Constructor Detail |
public AbstractFileConfiguration()
public AbstractFileConfiguration(String fileName)
throws ConfigurationException
fileName - The name of the file to load.
ConfigurationException - Error while loading the file
public AbstractFileConfiguration(File file)
throws ConfigurationException
file - The file to load.
ConfigurationException - Error while loading the file
public AbstractFileConfiguration(URL url)
throws ConfigurationException
url - The location of the file to load.
ConfigurationException - Error while loading the file| Method Detail |
public void load()
throws ConfigurationException
load in interface FileConfigurationConfigurationException - if loading of the configuration fails
public void load(String fileName)
throws ConfigurationException
load in interface FileConfigurationfileName - the name of the file to be loaded
ConfigurationException - if an error occurs
public void load(File file)
throws ConfigurationException
load in interface FileConfigurationfile - the file to load
ConfigurationException - if an error occurs
public void load(URL url)
throws ConfigurationException
load in interface FileConfigurationurl - the URL of the file to be loaded
ConfigurationException - if an error occurs
public void load(InputStream in)
throws ConfigurationException
getEncoding().
load in interface FileConfigurationin - the input stream
ConfigurationException - if an error occurs during the load operation
public void load(InputStream in,
String encoding)
throws ConfigurationException
load in interface FileConfigurationin - the input streamencoding - the encoding used. null to use the default encoding
ConfigurationException - if an error occurs during the load operation
public void save()
throws ConfigurationException
save in interface FileConfigurationConfigurationException - if an error occurs or no file name has
been set yet
public void save(String fileName)
throws ConfigurationException
save in interface FileConfigurationfileName - the file name
ConfigurationException - if an error occurs during the save operation
public void save(URL url)
throws ConfigurationException
save in interface FileConfigurationurl - the URL
ConfigurationException - if an error occurs during the save operation
public void save(File file)
throws ConfigurationException
setFile(java.io.File) if you need it.
save in interface FileConfigurationfile - the target file
ConfigurationException - if an error occurs during the save operation
public void save(OutputStream out)
throws ConfigurationException
getEncoding().
save in interface FileConfigurationout - the output stream
ConfigurationException - if an error occurs during the save operation
public void save(OutputStream out,
String encoding)
throws ConfigurationException
save in interface FileConfigurationout - the output streamencoding - the encoding to use
ConfigurationException - if an error occurs during the save operationpublic String getFileName()
getFileName in interface FileConfigurationpublic void setFileName(String fileName)
setPath() to set a full qualified file name.
setFileName in interface FileConfigurationfileName - the name of the filepublic String getBasePath()
getBasePath in interface FileConfigurationpublic void setBasePath(String basePath)
setBasePath in interface FileConfigurationbasePath - the base path.public File getFile()
getFile in interface FileConfigurationpublic void setFile(File file)
setFile in interface FileConfigurationfile - the file where the configuration is storedpublic String getPath()
public void setPath(String path)
path - the full path name of the configuration filepublic URL getURL()
getURL in interface FileConfigurationpublic void setURL(URL url)
setURL in interface FileConfigurationurl - the location of this configuration as URLpublic void setAutoSave(boolean autoSave)
FileConfiguration
setAutoSave in interface FileConfigurationautoSave - true to enable, false to disablepublic boolean isAutoSave()
FileConfiguration
isAutoSave in interface FileConfigurationtrue if auto-saving is enabled, false otherwiseprotected void possiblySave()
public void addProperty(String key,
Object value)
addProperty in interface ConfigurationaddProperty in class AbstractConfigurationkey - the key of the new propertyvalue - the value
public void setProperty(String key,
Object value)
setProperty in interface ConfigurationsetProperty in class AbstractConfigurationkey - the key of the affected propertyvalue - the valuepublic void clearProperty(String key)
Configuration
clearProperty in interface ConfigurationclearProperty in class AbstractConfigurationkey - the key to be removedpublic ReloadingStrategy getReloadingStrategy()
FileConfiguration
getReloadingStrategy in interface FileConfigurationpublic void setReloadingStrategy(ReloadingStrategy strategy)
FileConfiguration
setReloadingStrategy in interface FileConfigurationstrategy - the reloading strategy to usepublic void reload()
FileConfiguration
reload in interface FileConfigurationprotected void enterNoReload()
save() in derived classes, which may
cause a reload while accessing the properties to save. This may cause the
whole configuration to be erased. To avoid this, this method can be
called first. After a call to this method there always must be a
corresponding call of exitNoReload() later! (If
necessary, finally blocks must be used to ensure this.
protected void exitNoReload()
enterNoReload()
protected void fireEvent(int type,
String propName,
Object propValue,
boolean before)
fireEvent in class EventSourcetype - the event typepropName - the name of the propertypropValue - the value of the propertybefore - the before update flagpublic Object getProperty(String key)
ConfigurationConfiguration interface the other get methods (that
return specific data types) will internally make use of this method. On
this level variable substitution is not yet performed. The returned
object is an internal representation of the property value for the passed
in key. It is owned by the Configuration object. So a caller
should not modify this object. It cannot be guaranteed that this object
will stay constant over time (i.e. further update operations on the
configuration may change its internal state).
getProperty in interface ConfigurationgetProperty in class BaseConfigurationkey - key to use for mapping
public boolean isEmpty()
Configuration
isEmpty in interface ConfigurationisEmpty in class BaseConfigurationtrue if Configuration is empty,
false otherwise.public boolean containsKey(String key)
Configuration
containsKey in interface ConfigurationcontainsKey in class BaseConfigurationkey - the configuration key
true if Configuration contain given key,
false otherwise.public Iterator getKeys()
Configurationremove() method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
Configuration.clearProperty(String) for this property. So it is
highly recommended to avoid using the iterator's remove()
method.
getKeys in interface ConfigurationgetKeys in class BaseConfigurationpublic String getEncoding()
FileConfiguration
getEncoding in interface FileConfigurationpublic void setEncoding(String encoding)
FileConfiguration
setEncoding in interface FileConfigurationencoding - the encoding to usepublic Object clone()
clone in class BaseConfiguration
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||