Class DynaBeanPropertyMapDecorator
Decorates a DynaBean
to provide Map
behavior.
The motivation for this implementation is to provide access to DynaBean
properties in technologies that are unaware of BeanUtils and
DynaBean
s - such as the expression languages of JSTL and JSF.
This can be achieved either by wrapping the DynaBean
prior to providing it to the technology to process or by providing a Map
accessor method
on the DynaBean implementation:
public Map<String, Object> getMap() {
return new DynaBeanPropertyMapDecorator(this);
}
This, for example, could be used in JSTL in the following way to access a DynaBean's fooProperty
:
${myDynaBean.<strong>map</strong>.fooProperty}
Usage
To decorate a DynaBean
simply instantiate this class with the target DynaBean
:
Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean);
The above example creates a read only Map
. To create a Map
which can be modified, construct a
DynaBeanPropertyMapDecorator
with the read only attribute set to false
:
Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean, false);
Limitations
In this implementation the entrySet()</code>, <code>keySet()
and values()
methods create an unmodifiable
Set</code> and it does not support the Map's <code>clear()
and remove()
operations.
- Since:
- 1.9.0
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionDynaBeanPropertyMapDecorator
(DynaBean dynaBean) Constructs a read only Map for the specifiedDynaBean
.DynaBeanPropertyMapDecorator
(DynaBean dynaBean, boolean readOnly) Constructs a Map for the specifiedDynaBean
. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
convertKey
(String propertyName) Converts the name of a property to the key type of this decorator.Methods inherited from class org.apache.commons.beanutils2.BaseDynaBeanMapDecorator
clear, containsKey, containsValue, entrySet, get, getDynaBean, isEmpty, isReadOnly, keySet, put, putAll, remove, size, values
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
DynaBeanPropertyMapDecorator
Constructs a read only Map for the specifiedDynaBean
.- Parameters:
dynaBean
- The dyna bean being decorated- Throws:
IllegalArgumentException
- if theDynaBean
is null.
-
DynaBeanPropertyMapDecorator
Constructs a Map for the specifiedDynaBean
.- Parameters:
dynaBean
- The dyna bean being decoratedreadOnly
-true
if the Map is read only otherwisefalse
- Throws:
IllegalArgumentException
- if theDynaBean
is null.
-
-
Method Details
-
convertKey
Description copied from class:BaseDynaBeanMapDecorator
Converts the name of a property to the key type of this decorator.- Specified by:
convertKey
in classBaseDynaBeanMapDecorator<String>
- Parameters:
propertyName
- the name of a property- Returns:
- the converted key to be used in the decorated map
-