| java.lang.Object org.apache.commons.configuration.event.EventSource org.apache.commons.configuration.AbstractConfiguration
All known Subclasses: org.apache.commons.configuration.DatabaseConfiguration, org.apache.commons.configuration.web.BaseWebConfiguration, org.apache.commons.configuration.JNDIConfiguration, org.apache.commons.configuration.DataConfiguration, org.apache.commons.configuration.HierarchicalConfiguration, org.apache.commons.configuration.CompositeConfiguration, org.apache.commons.configuration.NonCloneableConfiguration, org.apache.commons.configuration.SubsetConfiguration, org.apache.commons.configuration.MapConfiguration, org.apache.commons.configuration.BaseConfiguration,
AbstractConfiguration | abstract public class AbstractConfiguration extends EventSource implements Configuration(Code) | | Abstract configuration class. Provides basic functionality but does not
store any data.
If you want to write your own Configuration class then you should
implement only abstract methods from this class. A lot of functionality
needed by typical implementations of the Configuration
interface is already provided by this base class. Following is a list of
feauters implemented here:
- Data conversion support. The various data types required by the
Configuration interface are already handled by this base class.
A concrete sub class only needs to provide a generic getProperty()
method.
- Support for variable interpolation. Property values containing special
variable tokens (like
${var} ) will be replaced by their
corresponding values.
- Support for string lists. The values of properties to be added to this
configuration are checked whether they contain a list delimiter character. If
this is the case and if list splitting is enabled, the string is splitted and
multiple values are added for this property. (With the
setListDelimiter() method the delimiter character can be
specified; per default a comma is used. The
setDelimiterParsingDisabled() method can be used to disable
list splitting completely.)
- Allows to specify how missing properties are treated. Per default the
get methods returning an object will return null if the searched
property key is not found (and no default value is provided). With the
setThrowExceptionOnMissing() method this behavior can be
changed to throw an exception when a requested property cannot be found.
- Basic event support. Whenever this configuration is modified registered
event listeners are notified. Refer to the various
EVENT_XXX
constants to get an impression about which event types are supported.
author: Konstantin Shaposhnikov author: Oliver Heger author: Henning P. Schmiedehausen version: $Id: AbstractConfiguration.java,v 1.29 2004/12/02 22:05:52 ebourg version: Exp $ |
Method Summary | |
public void | addErrorLogListener() Adds a special
org.apache.commons.configuration.event.ConfigurationErrorListener
object to this configuration that will log all internal errors. | public void | addProperty(String key, Object value) | abstract protected void | addPropertyDirect(String key, Object value) Adds a key/value pair to the Configuration. | public void | clear() | public void | clearProperty(String key) Removes the specified property from this configuration. | protected void | clearPropertyDirect(String key) Removes the specified property from this configuration. | abstract public boolean | containsKey(String key) | protected ConfigurationInterpolator | createInterpolator() Creates the interpolator object that is responsible for variable
interpolation. | public BigDecimal | getBigDecimal(String key) | public BigDecimal | getBigDecimal(String key, BigDecimal defaultValue) | public BigInteger | getBigInteger(String key) | public BigInteger | getBigInteger(String key, BigInteger defaultValue) | public boolean | getBoolean(String key) | public boolean | getBoolean(String key, boolean defaultValue) | public Boolean | getBoolean(String key, Boolean defaultValue) Obtains the value of the specified key and tries to convert it into a
Boolean object. | public byte | getByte(String key) | public byte | getByte(String key, byte defaultValue) | public Byte | getByte(String key, Byte defaultValue) | public static char | getDefaultListDelimiter() Retrieve the current delimiter. | public static char | getDelimiter() Returns the default list delimiter. | public double | getDouble(String key) | public double | getDouble(String key, double defaultValue) | public Double | getDouble(String key, Double defaultValue) | public float | getFloat(String key) | public float | getFloat(String key, float defaultValue) | public Float | getFloat(String key, Float defaultValue) | public int | getInt(String key) | public int | getInt(String key, int defaultValue) | public Integer | getInteger(String key, Integer defaultValue) | public ConfigurationInterpolator | getInterpolator() Returns the ConfigurationInterpolator object that manages
the lookup objects for resolving variables. | abstract public Iterator | getKeys() | public Iterator | getKeys(String prefix) | public List | getList(String key) | public List | getList(String key, List defaultValue) | public char | getListDelimiter() Retrieve the delimiter for this configuration. | public Log | getLogger() Returns the logger used by this configuration object. | public long | getLong(String key) | public long | getLong(String key, long defaultValue) | public Long | getLong(String key, Long defaultValue) | public Properties | getProperties(String key) | public Properties | getProperties(String key, Properties defaults) Get a list of properties associated with the given configuration key.
Parameters: key - The configuration key. Parameters: defaults - Any default values for the returnedProperties object. | public short | getShort(String key) | public short | getShort(String key, short defaultValue) | public Short | getShort(String key, Short defaultValue) | public String | getString(String key) | public String | getString(String key, String defaultValue) | public String[] | getStringArray(String key) Get an array of strings associated with the given configuration key.
If the key doesn't map to an existing object, an empty array is returned.
If a property is added to a configuration, it is checked whether it
contains multiple values. | public synchronized StrSubstitutor | getSubstitutor() Returns the object that is responsible for variable interpolation. | protected String | interpolate(String base) | protected Object | interpolate(Object value) Returns the interpolated value. | protected String | interpolateHelper(String base, List priorVariables) Recursive handler for multple levels of interpolation.
When called the first time, priorVariables should be null.
Parameters: base - string with the ${key} variables Parameters: priorVariables - serves two purposes: to allow checking for loops,and creating a meaningful exception message should a loop occur. | public boolean | isDelimiterParsingDisabled() Determine if this configuration is using delimiters when parsing
property values to convert them to lists of values. | abstract public boolean | isEmpty() | public boolean | isThrowExceptionOnMissing() Returns true if missing values throw Exceptions. | protected Object | resolveContainerStore(String key) Returns an object from the store described by the key. | public static void | setDefaultListDelimiter(char delimiter) For configurations extending AbstractConfiguration, allow them to change
the listDelimiter from the default comma (","). | public static void | setDelimiter(char delimiter) Sets the default list delimiter. | public void | setDelimiterParsingDisabled(boolean delimiterParsingDisabled) Set whether this configuration should use delimiters when parsing
property values to convert them to lists of values. | public void | setListDelimiter(char listDelimiter) Change the list delimiter for this configuration.
Note: this change will only be effective for new parsings. | public void | setLogger(Log log) Allows to set the logger to be used by this configuration object. | public void | setProperty(String key, Object value) | public void | setThrowExceptionOnMissing(boolean throwExceptionOnMissing) Allows to set the throwExceptionOnMissing flag. | public Configuration | subset(String prefix) |
END_TOKEN | final protected static String END_TOKEN(Code) | | end token
|
EVENT_ADD_PROPERTY | final public static int EVENT_ADD_PROPERTY(Code) | | Constant for the add property event type.
since: 1.3 |
EVENT_CLEAR | final public static int EVENT_CLEAR(Code) | | Constant for the clear configuration event type.
since: 1.3 |
EVENT_CLEAR_PROPERTY | final public static int EVENT_CLEAR_PROPERTY(Code) | | Constant for the clear property event type.
since: 1.3 |
EVENT_READ_PROPERTY | final public static int EVENT_READ_PROPERTY(Code) | | Constant for the get property event type. This event type is used for
error events.
since: 1.4 |
EVENT_SET_PROPERTY | final public static int EVENT_SET_PROPERTY(Code) | | Constant for the set property event type.
since: 1.3 |
START_TOKEN | final protected static String START_TOKEN(Code) | | start token
|
AbstractConfiguration | public AbstractConfiguration()(Code) | | Creates a new instance of AbstractConfiguration .
|
addErrorLogListener | public void addErrorLogListener()(Code) | | Adds a special
org.apache.commons.configuration.event.ConfigurationErrorListener
object to this configuration that will log all internal errors. This
method is intended to be used by certain derived classes, for which it is
known that they can fail on property access (e.g.
DatabaseConfiguration ).
since: 1.4 |
addPropertyDirect | abstract protected void addPropertyDirect(String key, Object value)(Code) | | Adds a key/value pair to the Configuration. Override this method to
provide write acces to underlying Configuration store.
Parameters: key - key to use for mapping Parameters: value - object to store |
clear | public void clear()(Code) | | |
clearProperty | public void clearProperty(String key)(Code) | | Removes the specified property from this configuration. This
implementation performs some preparations and then delegates to
clearPropertyDirect() , which will do the real work.
Parameters: key - the key to be removed |
clearPropertyDirect | protected void clearPropertyDirect(String key)(Code) | | Removes the specified property from this configuration. This method is
called by clearProperty() after it has done some
preparations. It should be overriden in sub classes. This base
implementation is just left empty.
Parameters: key - the key to be removed |
containsKey | abstract public boolean containsKey(String key)(Code) | | |
createInterpolator | protected ConfigurationInterpolator createInterpolator()(Code) | | Creates the interpolator object that is responsible for variable
interpolation. This method is invoked on first access of the
interpolation features. It creates a new instance of
ConfigurationInterpolator and sets the default lookup
object to an implementation that queries this configuration.
the newly created interpolator object since: 1.4 |
getBoolean | public Boolean getBoolean(String key, Boolean defaultValue)(Code) | | Obtains the value of the specified key and tries to convert it into a
Boolean object. If the property has no value, the passed
in default value will be used.
Parameters: key - the key of the property Parameters: defaultValue - the default value the value of this key converted to a Boolean throws: ConversionException - if the value cannot be converted to aBoolean See Also: PropertyConverter.toBoolean(Object) |
getByte | public byte getByte(String key, byte defaultValue)(Code) | | |
getDefaultListDelimiter | public static char getDefaultListDelimiter()(Code) | | Retrieve the current delimiter. By default this is a comma (",").
The delimiter in use |
getDelimiter | public static char getDelimiter()(Code) | | Returns the default list delimiter.
the default list delimiter |
getDouble | public double getDouble(String key, double defaultValue)(Code) | | |
getFloat | public float getFloat(String key, float defaultValue)(Code) | | |
getInterpolator | public ConfigurationInterpolator getInterpolator()(Code) | | Returns the ConfigurationInterpolator object that manages
the lookup objects for resolving variables. Note: If this
object is manipulated (e.g. new lookup objects added), synchronisation
has to be manually ensured. Because
ConfigurationInterpolator is not thread-safe concurrent
access to properties of this configuration instance (which causes the
interpolator to be invoked) may cause race conditions.
the ConfigurationInterpolator associated with thisconfiguration since: 1.4 |
getListDelimiter | public char getListDelimiter()(Code) | | Retrieve the delimiter for this configuration. The default
is the value of defaultListDelimiter.
The listDelimiter in use |
getLogger | public Log getLogger()(Code) | | Returns the logger used by this configuration object.
the logger since: 1.4 |
getLong | public long getLong(String key, long defaultValue)(Code) | | |
getProperties | public Properties getProperties(String key, Properties defaults)(Code) | | Get a list of properties associated with the given configuration key.
Parameters: key - The configuration key. Parameters: defaults - Any default values for the returnedProperties object. Ignored if null . The associated properties if key is found. throws: ConversionException - is thrown if the key maps to an object thatis not a String/List of Strings. throws: IllegalArgumentException - if one of the tokens is malformed (doesnot contain an equals sign). |
getShort | public short getShort(String key, short defaultValue)(Code) | | |
getStringArray | public String[] getStringArray(String key)(Code) | | Get an array of strings associated with the given configuration key.
If the key doesn't map to an existing object, an empty array is returned.
If a property is added to a configuration, it is checked whether it
contains multiple values. This is obvious if the added object is a list
or an array. For strings it is checked whether the string contains the
list delimiter character that can be specified using the
setListDelimiter() method. If this is the case, the string
is splitted at these positions resulting in a property with multiple
values.
Parameters: key - The configuration key. The associated string array if key is found. throws: ConversionException - is thrown if the key maps to anobject that is not a String/List of Strings. See Also: AbstractConfiguration.setListDelimiter(char) See Also: AbstractConfiguration.setDelimiterParsingDisabled(boolean) |
getSubstitutor | public synchronized StrSubstitutor getSubstitutor()(Code) | | Returns the object that is responsible for variable interpolation.
the object responsible for variable interpolation since: 1.4 |
interpolate | protected String interpolate(String base)(Code) | | interpolate key names to handle ${key} stuff
Parameters: base - string to interpolate returns the key name with the ${key} substituted |
interpolate | protected Object interpolate(Object value)(Code) | | Returns the interpolated value. Non String values are returned without change.
Parameters: value - the value to interpolate returns the value with variables substituted |
interpolateHelper | protected String interpolateHelper(String base, List priorVariables)(Code) | | Recursive handler for multple levels of interpolation.
When called the first time, priorVariables should be null.
Parameters: base - string with the ${key} variables Parameters: priorVariables - serves two purposes: to allow checking for loops,and creating a meaningful exception message should a loop occur. It's0'th element will be set to the value of base from the first call. Allsubsequent interpolated variables are added afterward. the string with the interpolation taken care ofPropertyConverter |
isDelimiterParsingDisabled | public boolean isDelimiterParsingDisabled()(Code) | | Determine if this configuration is using delimiters when parsing
property values to convert them to lists of values. Defaults to false
true if delimiters are not being used |
isEmpty | abstract public boolean isEmpty()(Code) | | |
isThrowExceptionOnMissing | public boolean isThrowExceptionOnMissing()(Code) | | Returns true if missing values throw Exceptions.
true if missing values throw Exceptions |
resolveContainerStore | protected Object resolveContainerStore(String key)(Code) | | Returns an object from the store described by the key. If the value is a
List object, replace it with the first object in the list.
Parameters: key - The property key. value Value, transparently resolving a possible List dependency. |
setDefaultListDelimiter | public static void setDefaultListDelimiter(char delimiter)(Code) | | For configurations extending AbstractConfiguration, allow them to change
the listDelimiter from the default comma (","). This value will be used
only when creating new configurations. Those already created will not be
affected by this change
Parameters: delimiter - The new listDelimiter |
setDelimiter | public static void setDelimiter(char delimiter)(Code) | | Sets the default list delimiter.
Parameters: delimiter - the delimiter character |
setDelimiterParsingDisabled | public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)(Code) | | Set whether this configuration should use delimiters when parsing
property values to convert them to lists of values. By default delimiter
parsing is enabled
Note: this change will only be effective for new parsings. If you
want it to take effect for all loaded properties use the no arg constructor
and call this method before setting source.
Parameters: delimiterParsingDisabled - a flag whether delimiter parsing shouldbe disabled |
setListDelimiter | public void setListDelimiter(char listDelimiter)(Code) | | Change the list delimiter for this configuration.
Note: this change will only be effective for new parsings. If you
want it to take effect for all loaded properties use the no arg constructor
and call this method before setting the source.
Parameters: listDelimiter - The new listDelimiter |
setLogger | public void setLogger(Log log)(Code) | | Allows to set the logger to be used by this configuration object. This
method makes it possible for clients to exactly control logging behavior.
Per default a logger is set that will ignore all log messages. Derived
classes that want to enable logging should call this method during their
initialization with the logger to be used.
Parameters: log - the new logger since: 1.4 |
setThrowExceptionOnMissing | public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)(Code) | | Allows to set the throwExceptionOnMissing flag. This
flag controls the behavior of property getter methods that return
objects if the requested property is missing. If the flag is set to
false (which is the default value), these methods will return
null. If set to true, they will throw a
NoSuchElementException exception. Note that getter methods
for primitive data types are not affected by this flag.
Parameters: throwExceptionOnMissing - The new value for the property |
Methods inherited from org.apache.commons.configuration.event.EventSource | public void addConfigurationListener(ConfigurationListener l)(Code)(Java Doc) public void addErrorListener(ConfigurationErrorListener l)(Code)(Java Doc) public void clearConfigurationListeners()(Code)(Java Doc) public void clearErrorListeners()(Code)(Java Doc) protected Object clone() throws CloneNotSupportedException(Code)(Java Doc) protected ConfigurationErrorEvent createErrorEvent(int type, String propName, Object propValue, Throwable ex)(Code)(Java Doc) protected ConfigurationEvent createEvent(int type, String propName, Object propValue, boolean before)(Code)(Java Doc) protected void fireError(int type, String propName, Object propValue, Throwable ex)(Code)(Java Doc) protected void fireEvent(int type, String propName, Object propValue, boolean before)(Code)(Java Doc) public Collection getConfigurationListeners()(Code)(Java Doc) public Collection getErrorListeners()(Code)(Java Doc) public boolean isDetailEvents()(Code)(Java Doc) public boolean removeConfigurationListener(ConfigurationListener l)(Code)(Java Doc) public boolean removeErrorListener(ConfigurationErrorListener l)(Code)(Java Doc) public void setDetailEvents(boolean enable)(Code)(Java Doc)
|
|
|