|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.conf.Configuration
public class Configuration
Base class for all configuration related tasks.
A Configuration instance's main goal is to act as a configuration data repository.
Once created, it can be used to retrieve, delete
and set configuration variables.
startup_folder.right.last_folder is interpreted as a variable called
last_folder contained in a section called right, itself contained in
another section called startup_folder.
com.mucommander.conf really only handles one type of variables, strings, it offers
tools to cast them as primitive Java types (int, long, float, double, boolean). This is done through the use
of the various primitive types' class implementation parseXXX method.null0000false
XmlConfigurationReader). However, application writers can modify that to any format they want
through the setReaderFactory and
setWriterFactory methods.
Configuration provides read and write methods that accept streams as parameters, it's
also possible to set the data source once and for all and let the API deal with the details. This can
be achieved through the setSource method.FileConfigurationSource, is provided. It covers the most
common case of configuration sources, a local configuration file.com.mucommander.file API.
ConfigurationListener
interface and register themselves through
addConfigurationListener. This guarantees that they
will receive configuration events whenever a modification occurs.
| Constructor Summary | |
|---|---|
Configuration()
Creates a new instance of Configuration. |
|
Configuration(ConfigurationReaderFactory reader,
ConfigurationWriterFactory writer)
Creates a new instance of Configuration using the specified format. |
|
Configuration(ConfigurationSource source)
Creates a new instance of Configuration using the specified source. |
|
Configuration(ConfigurationSource source,
ConfigurationReaderFactory reader,
ConfigurationWriterFactory writer)
Creates a new instance of Configuration using the specified source and format. |
|
| Method Summary | |
|---|---|
static void |
addConfigurationListener(ConfigurationListener listener)
Adds the specified object to the list of registered configuration listeners. |
void |
build(ConfigurationBuilder builder)
Explores the whole configuration tree and invokes the specified builder's callback methods. |
boolean |
getBooleanVariable(java.lang.String name)
Returns the value of the specified variable as a boolean. |
double |
getDoubleVariable(java.lang.String name)
Returns the value of the specified variable as a double. |
float |
getFloatVariable(java.lang.String name)
Returns the value of the specified variable as a float. |
int |
getIntegerVariable(java.lang.String name)
Returns the value of the specified variable as an integer. |
ValueList |
getListVariable(java.lang.String name,
java.lang.String separator)
Returns the value of the specified variable as a ValueList. |
long |
getLongVariable(java.lang.String name)
Returns the value of the specified variable as a long. |
ConfigurationReader |
getReader()
Returns an instance of the class that will be used to read configuration data. |
ConfigurationReaderFactory |
getReaderFactory()
Returns the factory that is being used to create reader instances. |
ConfigurationSource |
getSource()
Returns the current configuration source. |
java.lang.String |
getVariable(java.lang.String name)
Returns the value of the specified variable. |
boolean |
getVariable(java.lang.String name,
boolean defaultValue)
Retrieves the value of the specified variable as a boolean. |
double |
getVariable(java.lang.String name,
double defaultValue)
Retrieves the value of the specified variable as a double. |
float |
getVariable(java.lang.String name,
float defaultValue)
Retrieves the value of the specified variable as a float. |
int |
getVariable(java.lang.String name,
int defaultValue)
Retrieves the value of the specified variable as an integer. |
ValueList |
getVariable(java.lang.String name,
java.util.List defaultValue,
java.lang.String separator)
Retrieves the value of the specified variable as a ValueList. |
long |
getVariable(java.lang.String name,
long defaultValue)
Retrieves the value of the specified variable as a long. |
java.lang.String |
getVariable(java.lang.String name,
java.lang.String defaultValue)
Retrieves the value of the specified variable. |
ConfigurationWriter |
getWriter()
Returns an instance of the class that will be used to write configuration data. |
ConfigurationWriterFactory |
getWriterFactory()
Returns the factory that is being used to create writer instances. |
boolean |
isVariableSet(java.lang.String name)
Checks whether the specified variable has been set. |
void |
read()
Loads configuration. |
void |
read(ConfigurationReader reader)
Loads configuration using the specified configuration reader. |
void |
read(java.io.InputStream in)
Loads configuration from the specified input stream. |
boolean |
removeBooleanVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
static void |
removeConfigurationListener(ConfigurationListener listener)
Removes the specified object from the list of registered configuration listeners. |
double |
removeDoubleVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
float |
removeFloatVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
int |
removeIntegerVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
ValueList |
removeListVariable(java.lang.String name,
java.lang.String separator)
Deletes the specified variable from the configuration. |
long |
removeLongVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
java.lang.String |
removeVariable(java.lang.String name)
Deletes the specified variable from the configuration. |
void |
renameVariable(java.lang.String fromVar,
java.lang.String toVar)
Moves the value of fromVar to toVar. |
void |
setReaderFactory(ConfigurationReaderFactory f)
Sets the factory that will be used to create reader instances. |
void |
setSource(ConfigurationSource s)
Sets the source that will be used to read and write configuration information. |
boolean |
setVariable(java.lang.String name,
boolean value)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
double value)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
float value)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
int value)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
java.util.List value,
java.lang.String separator)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
long value)
Sets the value of the specified variable. |
boolean |
setVariable(java.lang.String name,
java.lang.String value)
Sets the value of the specified variable. |
void |
setWriterFactory(ConfigurationWriterFactory f)
Sets the factory that will be used to create writer instances. |
void |
write()
Writes configuration. |
void |
write(ConfigurationWriter writer)
Writes configuration using the specified writer. |
void |
write(java.io.OutputStream out)
Writes configuration to the specified output stream. |
void |
write(java.io.OutputStream out,
ConfigurationWriter writer)
Writes configuration to the specified output stream using the specified writer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Configuration()
Configuration.
The resulting instance will use the default reader and writer factories,
XmlConfigurationReaderFactory and XmlConfigurationWriterFactory.
Note that until the setSource method has been
invoked, calls to read or write methods without a stream parameter will fail.
public Configuration(ConfigurationSource source)
Configuration using the specified source.
The resulting instance will use the default reader and writer factories,
XmlConfigurationReaderFactory and XmlConfigurationWriterFactory.
source - where the resulting instance will look for its configuration data.
public Configuration(ConfigurationReaderFactory reader,
ConfigurationWriterFactory writer)
Configuration using the specified format.
Note that until the setSource method has been
invoked, calls to read or write methods without a stream parameter will fail.
reader - object that will be used to create ConfigurationReader instances.writer - object that will be used to create ConfigurationWriter instances.
public Configuration(ConfigurationSource source,
ConfigurationReaderFactory reader,
ConfigurationWriterFactory writer)
Configuration using the specified source and format.
source - where the resulting instance will look for its configuration data.reader - object that will be used to create ConfigurationReader instances.writer - object that will be used to create ConfigurationWriter instances.| Method Detail |
|---|
public void setSource(ConfigurationSource s)
s - new configuration source.getSource()public ConfigurationSource getSource()
null if it hasn't been set.setSource(ConfigurationSource)public void setReaderFactory(ConfigurationReaderFactory f)
reader instances.
In order to reset the configuration to its default reader factory (XmlConfigurationReaderFactory),
application writers can call setReaderFactory(null);.
f - factory that will be used to create reader instances.getReader(),
getReaderFactory()public ConfigurationReaderFactory getReaderFactory()
reader instances.
By default, this method will return an instance of XmlConfigurationReaderFactory. However,
this can be modified by calling setReaderFactory.
getReader(),
setReaderFactory(ConfigurationReaderFactory)
public ConfigurationReader getReader()
throws ReaderConfigurationException
By default, this method will return an instance of XmlConfigurationReader. However, this can be
modified by calling setReaderFactory.
ReaderConfigurationException - any configuration reader error, possibly wrapping another exception.setReaderFactory(ConfigurationReaderFactory),
getReaderFactory()public void setWriterFactory(ConfigurationWriterFactory f)
writer instances.
In order to reset the configuration to its default writer factory (XmlConfigurationWriterFactory),
application writers can call setWriterFactory(null);.
f - factory that will be used to create writer instances.getWriterFactory(),
getWriter()public ConfigurationWriterFactory getWriterFactory()
writer instances.
By default, this method will return an instance of XmlConfigurationWriterFactory. However, this
can be modified by calling setWriterFactory.
setWriterFactory(ConfigurationWriterFactory),
getWriter()
public ConfigurationWriter getWriter()
throws WriterConfigurationException
By default, this method will return an instance of XmlConfigurationWriter. However, this can be
modified by setWriterFactory.
WriterConfigurationException - any configuration writer error, possibly wrapping another exception.setWriterFactory(ConfigurationWriterFactory),
getWriterFactory()
public void read(java.io.InputStream in)
throws ConfigurationException,
java.io.IOException
This method will use the configuration reader set by setReaderFactory(ConfigurationReaderFactory) if any,
or an XmlConfigurationReader instance if not.
in - where to read the configuration from.
ConfigurationException - if a configuration error occurs.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.
ReaderConfigurationException - if the ConfigurationReaderFactory isn't properly configured.
java.io.IOException - if an I/O error occurs.write(OutputStream),
read(),
read(ConfigurationReader),
read(InputStream,ConfigurationReader)
public void read(ConfigurationReader reader)
throws java.io.IOException,
ConfigurationException
This method will use the input stream provided by setSource(ConfigurationSource) if any, or
fail otherwise.
reader - reader that will be used to interpret the content of in.
java.io.IOException - if an I/O error occurs.
ConfigurationException - if a configuration error occurs.
SourceConfigurationException - if no ConfigurationSource has been set.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.write(ConfigurationWriter),
read(InputStream),
read(),
read(InputStream,ConfigurationReader)
public void read()
throws ConfigurationException,
java.io.IOException
If a reader has been specified through setReaderFactory(ConfigurationReaderFactory), it
will be used to analyse the configuration. Otherwise, an XmlConfigurationReader instance
will be used.
If a configuration source has been specified through setSource(ConfigurationSource), it will be
used. Otherwise, this method will fail.
java.io.IOException - if an I/O error occurs.
ConfigurationException - if a configuration error occurs.
SourceConfigurationException - if no ConfigurationSource hasn been set.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.
ReaderConfigurationException - if the ConfigurationReaderFactory isn't properly configured.write(),
read(InputStream),
read(ConfigurationReader),
read(InputStream,ConfigurationReader)
public void write(java.io.OutputStream out,
ConfigurationWriter writer)
throws ConfigurationException
out - where to write the configuration to.writer - writer that will be used to format the configuration.
ConfigurationException - if any error occurs.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.read(InputStream,ConfigurationReader),
write(OutputStream),
write(ConfigurationWriter),
write()
public void write(java.io.OutputStream out)
throws ConfigurationException
If a writer was specified through setWriterFactory(ConfigurationWriterFactory), this will be
used to format the configuration. Otherwise, an XmlConfigurationWriter will be used.
out - where to write the configuration to.
ConfigurationException - if any error occurs.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.
WriterConfigurationException - if the ConfigurationWriterFactory isn't properly configured.read(InputStream),
write(OutputStream,ConfigurationWriter),
write(ConfigurationWriter),
write()
public void write(ConfigurationWriter writer)
throws java.io.IOException,
ConfigurationException
If a configuration source was specified through setSource(ConfigurationSource), it will be used
to open an output stream. Otherwise, this method will fail.
writer - writer that will be used to format the configuration.
ConfigurationException - if any error occurs.
SourceConfigurationException - if no ConfigurationSource has been set.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.
java.io.IOException - if any I/O error occurs.read(ConfigurationReader),
write(OutputStream,ConfigurationWriter),
write(OutputStream),
write()
public void write()
throws java.io.IOException,
ConfigurationException
If a writer was specified through setWriterFactory(ConfigurationWriterFactory), this will be
used to format the configuration. Otherwise, an XmlConfigurationWriter will be used.
If a configuration source was specified through setSource(ConfigurationSource), it will be used
to open an output stream. Otherwise, this method will fail.
SourceConfigurationException - if a ConfigurationSource hasn't been set.
ConfigurationException - if any error occurs.
ConfigurationFormatException - if a syntax error occurs in the configuration data.
ConfigurationStructureException - if the configuration data doesn't describe a valid configuration tree.
WriterConfigurationException - if the ConfigurationWriterFactory isn't properly configured.
java.io.IOException - if any I/O error occurs.read(),
write(OutputStream,ConfigurationWriter),
write(OutputStream),
write(ConfigurationWriter)
public void build(ConfigurationBuilder builder)
throws ConfigurationException
builder - object that will receive configuration building messages.
ConfigurationException - if any error occurs while going through the configuration tree.
public void renameVariable(java.lang.String fromVar,
java.lang.String toVar)
fromVar to toVar.
At the end of this call, fromVar will have been deleted. Note that if fromVar doesn't exist,
but toVar does, toVar will be deleted.
This method might trigger as many as two events:
fromVar is removed.toVar is set.
fromVar - fully qualified name of the variable to rename.toVar - fully qualified name of the variable that will receive fromVar's value.
public boolean setVariable(java.lang.String name,
java.lang.String value)
This method will return false if it didn't modify name's value. Note that this doesn't mean
the call failed, but that name's value was already equal to value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getVariable(String),
getVariable(String,String)
public boolean setVariable(java.lang.String name,
int value)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getIntegerVariable(String),
getVariable(String,int)
public boolean setVariable(java.lang.String name,
java.util.List value,
java.lang.String separator)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.separator - string used to separate each element of the list.
true if this call resulted in a modification of the variable's value, false otherwise.getListVariable(String,String),
getVariable(String,List,String)
public boolean setVariable(java.lang.String name,
float value)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getFloatVariable(String),
getVariable(String,float)
public boolean setVariable(java.lang.String name,
boolean value)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getBooleanVariable(String),
getVariable(String,boolean)
public boolean setVariable(java.lang.String name,
long value)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getLongVariable(String),
getVariable(String,long)
public boolean setVariable(java.lang.String name,
double value)
This method will return false if it didn't modify name's value. This, however, is not a way
of indicating that the call failed: false is only ever returned if the previous value is equal to the
new value.
If the value of the specified variable is actually modified, an event will be passed to all
listeners.
name - fully qualified name of the variable to set.value - new value for the variable.
true if this call resulted in a modification of the variable's value, false otherwise.getDoubleVariable(String),
getVariable(String,double)public java.lang.String getVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
null otherwise.setVariable(String,String),
getVariable(String,String)
public ValueList getListVariable(java.lang.String name,
java.lang.String separator)
ValueList.
name - fully qualified name of the variable whose value should be retrieved.separator - character used to split the variable's value into a list.
null otherwise.setVariable(String,List,String),
getVariable(String,List,String)public int getIntegerVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
0 otherwise.
java.lang.NumberFormatException - if the variable's value cannot be cast to an integer.setVariable(String,int),
getVariable(String,int)public long getLongVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
0 otherwise.
java.lang.NumberFormatException - if the variable's value cannot be cast to a long.setVariable(String,long),
getVariable(String,long)public float getFloatVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
0 otherwise.
java.lang.NumberFormatException - if the variable's value cannot be cast to a float.setVariable(String,float),
getVariable(String,float)public double getDoubleVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
0 otherwise.
java.lang.NumberFormatException - if the variable's value cannot be cast to a double.setVariable(String,double),
getVariable(String,double)public boolean getBooleanVariable(java.lang.String name)
name - fully qualified name of the variable whose value should be retrieved.
false otherwise.setVariable(String,boolean),
getVariable(String,boolean)public boolean isVariableSet(java.lang.String name)
name - fully qualified name of the variable to check for.
true if the variable is set, false otherwise.public java.lang.String removeVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
null if it wasn't set.
public ValueList removeListVariable(java.lang.String name,
java.lang.String separator)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.separator - character used to split the variable's value into a list.
null if it wasn't set.public int removeIntegerVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
0 if it wasn't set.public long removeLongVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
0 if it wasn't set.public float removeFloatVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
0 if it wasn't set.public double removeDoubleVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
0 if it wasn't set.public boolean removeBooleanVariable(java.lang.String name)
If the variable was set, a configuration event will be passed to
all registered listeners.
name - name of the variable to remove.
false if it wasn't set.
public java.lang.String getVariable(java.lang.String name,
java.lang.String defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
setVariable(String,String),
getVariable(String)
public ValueList getVariable(java.lang.String name,
java.util.List defaultValue,
java.lang.String separator)
ValueList.
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if variable name is not set.separator - separator to use for defaultValue if variable name is not set.
setVariable(String,List,String),
getListVariable(String,String)
public int getVariable(java.lang.String name,
int defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
java.lang.NumberFormatException - if the variable's value cannot be cast to an integer.setVariable(String,int),
getIntegerVariable(String)
public long getVariable(java.lang.String name,
long defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
java.lang.NumberFormatException - if the variable's value cannot be cast to a long.setVariable(String,long),
getLongVariable(String)
public float getVariable(java.lang.String name,
float defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
java.lang.NumberFormatException - if the variable's value cannot be cast to a float.setVariable(String,float),
getFloatVariable(String)
public boolean getVariable(java.lang.String name,
boolean defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
setVariable(String,boolean),
getBooleanVariable(String)
public double getVariable(java.lang.String name,
double defaultValue)
If the variable isn't set, this method will set it to defaultValue before
returning it. If this happens, a configuration event will
be sent to all registered listeners.
name - name of the variable to retrieve.defaultValue - value to use if name is not set.
java.lang.NumberFormatException - if the variable's value cannot be cast to a double.setVariable(String,double),
getDoubleVariable(String)public static void addConfigurationListener(ConfigurationListener listener)
listener - object to register as a configuration listener.removeConfigurationListener(ConfigurationListener)public static void removeConfigurationListener(ConfigurationListener listener)
listener - object to remove from the list of registered configuration listeners.addConfigurationListener(ConfigurationListener)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard