public class DynaBeanPropertyMapDecorator extends BaseDynaBeanMapDecorator<String>
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.map.fooProperty}
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);
In this implementation the entrySet()
, keySet()
and values()
methods create an unmodifiable
Set
and it does not support the Map's clear()
and remove()
operations.
Constructor and Description |
---|
DynaBeanPropertyMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specified
DynaBean . |
DynaBeanPropertyMapDecorator(DynaBean dynaBean,
boolean readOnly)
Construct a Map for the specified
DynaBean . |
Modifier and Type | Method and Description |
---|---|
protected String |
convertKey(String propertyName)
Converts the name of a property to the key type of this decorator.
|
clear, containsKey, containsValue, entrySet, get, getDynaBean, isEmpty, isReadOnly, keySet, put, putAll, remove, size, values
public DynaBeanPropertyMapDecorator(DynaBean dynaBean, boolean readOnly)
DynaBean
.dynaBean
- The dyna bean being decoratedreadOnly
- true
if the Map is read only
otherwise false
IllegalArgumentException
- if the DynaBean
is null.public DynaBeanPropertyMapDecorator(DynaBean dynaBean)
DynaBean
.dynaBean
- The dyna bean being decoratedIllegalArgumentException
- if the DynaBean
is null.protected String convertKey(String propertyName)
BaseDynaBeanMapDecorator
convertKey
in class BaseDynaBeanMapDecorator<String>
propertyName
- the name of a propertyCopyright © 2000–2013 The Apache Software Foundation. All rights reserved.