|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.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 FileConfiguration.load(Reader)
and AbstractFileConfiguration#save(Reader).
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
|
protected String |
basePath
|
protected String |
fileName
|
protected ReloadingStrategy |
strategy
|
| Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
END_TOKEN, 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 | |
protected void |
addPropertyDirect(String key,
Object obj)
Adds a key/value pair to the map. |
void |
clearProperty(String key)
Remove a property from the configuration. |
boolean |
containsKey(String key)
Check if the configuration contains the specified key. |
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 of 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 path name. |
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 |
clear |
| Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
addProperty, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, isThrowExceptionOnMissing, resolveContainerStore, setDelimiter, setProperty, setThrowExceptionOnMissing, subset |
| Methods inherited from class java.lang.Object |
clone, 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, setProperty, subset |
| Field Detail |
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 loaded
ConfigurationException
public void load(File file)
throws ConfigurationException
load in interface FileConfigurationfile - the loaded file
ConfigurationException
public void load(URL url)
throws ConfigurationException
load in interface FileConfigurationurl - the URL of the file loaded
ConfigurationException
public void load(InputStream in)
throws ConfigurationException
getEncoding().
load in interface FileConfigurationin - the input stream
ConfigurationException
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
public void save()
throws ConfigurationException
save in interface FileConfigurationConfigurationException
public void save(String fileName)
throws ConfigurationException
save in interface FileConfigurationfileName -
ConfigurationException
public void save(URL url)
throws ConfigurationException
save in interface FileConfigurationurl -
ConfigurationException
public void save(File file)
throws ConfigurationException
setFile(java.io.File) if you need it.
save in interface FileConfigurationfile -
ConfigurationException
public void save(OutputStream out)
throws ConfigurationException
getEncoding().
save in interface FileConfigurationout -
ConfigurationException
public void save(OutputStream out,
String encoding)
throws ConfigurationException
save in interface FileConfigurationout - encoding -
ConfigurationExceptionpublic 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()
protected void addPropertyDirect(String key,
Object obj)
BaseConfiguration
addPropertyDirect in class BaseConfigurationkey - key to use for mappingobj - object to storepublic void clearProperty(String key)
Configuration
clearProperty in interface ConfigurationclearProperty in class BaseConfigurationkey - the key to remove along with corresponding value.public ReloadingStrategy getReloadingStrategy()
FileConfiguration
getReloadingStrategy in interface FileConfigurationpublic void setReloadingStrategy(ReloadingStrategy strategy)
FileConfiguration
setReloadingStrategy in interface FileConfigurationpublic void reload()
FileConfiguration
reload in interface FileConfigurationpublic Object getProperty(String key)
Configuration
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()
Configuration
getKeys in interface ConfigurationgetKeys in class BaseConfigurationpublic String getEncoding()
FileConfiguration
getEncoding in interface FileConfigurationpublic void setEncoding(String encoding)
FileConfiguration
setEncoding in interface FileConfiguration
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||