public class MapConfiguration extends AbstractConfiguration implements Cloneable
A Map based Configuration.
This implementation of the Configuration
interface is
initialized with a java.util.Map
. The methods of the
Configuration
interface are implemented on top of the content of
this map. The following storage scheme is used:
Property keys are directly mapped to map keys, i.e. the
getProperty()
method directly performs a get()
on
the map. Analogously, setProperty()
or
addProperty()
operations write new data into the map. If a value
is added to an existing property, a java.util.List
is created,
which stores the values of this property.
An important use case of this class is to treat a map as a
Configuration
allowing access to its data through the richer
interface. This can be a bit problematic in some cases because the map may
contain values that need not adhere to the default storage scheme used by
typical configuration implementations, e.g. regarding lists. In such cases
care must be taken when manipulating the data through the
Configuration
interface, e.g. by calling
addProperty()
; results may be different than expected.
The handling of list delimiters is a bit different for this configuration
implementation: When a property of type String is queried, it is passed to
the current ListDelimiterHandler
which may generate multiple values.
Note that per default a list delimiter handler is set which does not do any
list splitting, so this feature is disabled. It can be enabled by setting
a properly configured ListDelimiterHandler
implementation, e.g. a
DefaultListDelimiterHandler
object.
Notice that list splitting is only performed for single string values. If a property has multiple values, the single values are not split even if they contain the list delimiter character.
As the underlying Map
is directly used as store of the property
values, the thread-safety of this Configuration
implementation
depends on the map passed to the constructor.
Notes about type safety: For properties with multiple values this implementation
creates lists of type Object
and stores them. If a property is assigned
another value, the value is added to the list. This can cause problems if the
map passed to the constructor already contains lists of other types. This
should be avoided, otherwise it cannot be guaranteed that the application
might throw ClassCastException
exceptions later.
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
map
The Map decorated by this configuration.
|
Constructor and Description |
---|
MapConfiguration(Map<String,?> map)
Create a Configuration decorator around the specified Map.
|
MapConfiguration(Properties props)
Creates a new instance of
MapConfiguration which uses the
specified Properties object as its data store. |
Modifier and Type | Method and Description |
---|---|
protected void |
addPropertyDirect(String key,
Object value)
Adds a key/value pair to the Configuration.
|
protected void |
clearPropertyDirect(String key)
Removes the specified property from this configuration.
|
Object |
clone()
Returns a copy of this object.
|
protected boolean |
containsKeyInternal(String key)
Actually checks whether the specified key is contained in this
configuration.
|
protected Iterator<String> |
getKeysInternal()
Actually creates an iterator for iterating over the keys in this
configuration.
|
Map<String,Object> |
getMap()
Return the Map decorated by this configuration.
|
protected Object |
getPropertyInternal(String key)
Actually obtains the value of the specified property.
|
protected boolean |
isEmptyInternal()
Actually checks whether this configuration contains data.
|
boolean |
isTrimmingDisabled()
Returns the flag whether trimming of property values is disabled.
|
void |
setTrimmingDisabled(boolean trimmingDisabled)
Sets a flag whether trimming of property values is disabled.
|
protected int |
sizeInternal()
Actually calculates the size of this configuration.
|
String |
toString()
Converts this object to a String suitable for debugging and logging.
|
addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearInternal, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, subset, unlock
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
public MapConfiguration(Map<String,?> map)
map
- the mappublic MapConfiguration(Properties props)
MapConfiguration
which uses the
specified Properties
object as its data store. All changes of
this configuration affect the given Properties
object and
vice versa. Note that while Properties
actually
implements Map<Object, Object>
, we expect it to contain only
string keys. Other key types will lead to ClassCastException
exceptions on certain methods.props
- the Properties
object defining the content of this
configurationpublic Map<String,Object> getMap()
public boolean isTrimmingDisabled()
public void setTrimmingDisabled(boolean trimmingDisabled)
trimmingDisabled
- a flag whether trimming of property values should
be disabledprotected Object getPropertyInternal(String key)
AbstractConfiguration
getProperty()
. Concrete subclasses must define it to
fetch the value of the desired property.getPropertyInternal
in class AbstractConfiguration
key
- the key of the property in questionprotected void addPropertyDirect(String key, Object value)
AbstractConfiguration
addPropertyDirect
in class AbstractConfiguration
key
- key to use for mappingvalue
- object to storeprotected boolean isEmptyInternal()
AbstractConfiguration
isEmpty()
. It has to be defined by concrete subclasses.isEmptyInternal
in class AbstractConfiguration
protected boolean containsKeyInternal(String key)
AbstractConfiguration
containsKey()
. It has to
be defined by concrete subclasses.containsKeyInternal
in class AbstractConfiguration
key
- the key in questionprotected void clearPropertyDirect(String key)
AbstractConfiguration
clearProperty()
after it has done some
preparations. It must be overridden in sub classes.clearPropertyDirect
in class AbstractConfiguration
key
- the key to be removedprotected Iterator<String> getKeysInternal()
AbstractConfiguration
getKeys()
, it has to be
defined by concrete subclasses.getKeysInternal
in class AbstractConfiguration
Iterator
with all property keys in this configurationprotected int sizeInternal()
AbstractConfiguration
size()
with a read lock held. The base implementation provided
here calculates the size based on the iterator returned by
getKeys()
. Sub classes which can determine the size in a more
efficient way should override this method.sizeInternal
in class AbstractConfiguration
public Object clone()
clone
in class BaseEventSource
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.