Class DynaBeanPropertyMapDecorator
- java.lang.Object
-
- org.apache.commons.beanutils.BaseDynaBeanMapDecorator<java.lang.String>
-
- org.apache.commons.beanutils.DynaBeanPropertyMapDecorator
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>
public class DynaBeanPropertyMapDecorator extends BaseDynaBeanMapDecorator<java.lang.String>
Decorates a
DynaBean
to provideMap
behavior.The motivation for this implementation is to provide access to
DynaBean
properties in technologies that are unaware of BeanUtils andDynaBean
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 aMap
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.map.fooProperty}
Usage
To decorate a
DynaBean
simply instantiate this class with the targetDynaBean
:Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean);
The above example creates a read only
Map
. To create aMap
which can be modified, construct aDynaBeanPropertyMapDecorator
with the read only attribute set tofalse
:Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean, false);
Limitations
In this implementation the
entrySet()
,keySet()
andvalues()
methods create an unmodifiableSet
and it does not support the Map'sclear()
andremove()
operations.- Since:
- BeanUtils 1.9.0
- Version:
- $Id: DynaBeanPropertyMapDecorator.java 1540518 2013-11-10 19:04:04Z oheger $
-
-
Constructor Summary
Constructors Constructor Description DynaBeanPropertyMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specifiedDynaBean
.DynaBeanPropertyMapDecorator(DynaBean dynaBean, boolean readOnly)
Construct a Map for the specifiedDynaBean
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
convertKey(java.lang.String propertyName)
Converts the name of a property to the key type of this decorator.-
Methods inherited from class org.apache.commons.beanutils.BaseDynaBeanMapDecorator
clear, containsKey, containsValue, entrySet, get, getDynaBean, isEmpty, isReadOnly, keySet, put, putAll, remove, size, values
-
-
-
-
Constructor Detail
-
DynaBeanPropertyMapDecorator
public DynaBeanPropertyMapDecorator(DynaBean dynaBean, boolean readOnly)
Construct a Map for the specifiedDynaBean
.- Parameters:
dynaBean
- The dyna bean being decoratedreadOnly
-true
if the Map is read only otherwisefalse
- Throws:
java.lang.IllegalArgumentException
- if theDynaBean
is null.
-
-
Method Detail
-
convertKey
protected java.lang.String convertKey(java.lang.String propertyName)
Description copied from class:BaseDynaBeanMapDecorator
Converts the name of a property to the key type of this decorator.- Specified by:
convertKey
in classBaseDynaBeanMapDecorator<java.lang.String>
- Parameters:
propertyName
- the name of a property- Returns:
- the converted key to be used in the decorated map
-
-