Class BaseDynaBeanMapDecorator<K>
- java.lang.Object
-
- org.apache.commons.beanutils.BaseDynaBeanMapDecorator<K>
-
- Type Parameters:
K
- the type of the keys in the decorated map
- All Implemented Interfaces:
java.util.Map<K,java.lang.Object>
- Direct Known Subclasses:
DynaBeanMapDecorator
,DynaBeanPropertyMapDecorator
public abstract class BaseDynaBeanMapDecorator<K> extends java.lang.Object implements java.util.Map<K,java.lang.Object>
A base class for decorators providing
Map
behavior onDynaBean
s.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 rather technical base class implements the methods of the
Map
interface on top of aDynaBean
. It was introduced to handle generic parameters in a meaningful way without breaking backwards compatibility of theDynaBeanMapDecorator
class: A map wrapping aDynaBean
should be of typeMap<String, Object>
. However, when using these generic parameters inDynaBeanMapDecorator
this would be an incompatible change (as method signatures would have to be adapted). To solve this problem, this generic base class is added which allows specifying the key type as parameter. This makes it easy to have a new subclass using the correct generic parameters whileDynaBeanMapDecorator
could still remain with compatible parameters.- Since:
- BeanUtils 1.9.0
- Version:
- $Id: BaseDynaBeanMapDecorator.java 1746219 2016-05-31 05:05:09Z ggregory $
-
-
Constructor Summary
Constructors Constructor Description BaseDynaBeanMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specifiedDynaBean
.BaseDynaBeanMapDecorator(DynaBean dynaBean, boolean readOnly)
Construct a Map for the specifiedDynaBean
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
clear() operation is not supported.boolean
containsKey(java.lang.Object key)
Indicate whether theDynaBean
contains a specified value for one (or more) of its properties.boolean
containsValue(java.lang.Object value)
Indicates whether the decoratedDynaBean
contains a specified value.protected abstract K
convertKey(java.lang.String propertyName)
Converts the name of a property to the key type of this decorator.java.util.Set<java.util.Map.Entry<K,java.lang.Object>>
entrySet()
Returns the Set of the property/value mappings in the decoratedDynaBean
.java.lang.Object
get(java.lang.Object key)
Return the value for the specified key from the decoratedDynaBean
.DynaBean
getDynaBean()
Provide access to the underlyingDynaBean
this Map decorates.boolean
isEmpty()
Indicate whether the decoratedDynaBean
has any properties.boolean
isReadOnly()
Indicate whether the Map is read only.java.util.Set<K>
keySet()
Returns the Set of the property names in the decoratedDynaBean
.java.lang.Object
put(K key, java.lang.Object value)
Set the value for the specified property in the decoratedDynaBean
.void
putAll(java.util.Map<? extends K,? extends java.lang.Object> map)
Copy the contents of a Map to the decoratedDynaBean
.java.lang.Object
remove(java.lang.Object key)
remove() operation is not supported.int
size()
Returns the number properties in the decoratedDynaBean
.java.util.Collection<java.lang.Object>
values()
Returns the set of property values in the decoratedDynaBean
.
-
-
-
Constructor Detail
-
BaseDynaBeanMapDecorator
public BaseDynaBeanMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specifiedDynaBean
.- Parameters:
dynaBean
- The dyna bean being decorated- Throws:
java.lang.IllegalArgumentException
- if theDynaBean
is null.
-
BaseDynaBeanMapDecorator
public BaseDynaBeanMapDecorator(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
-
isReadOnly
public boolean isReadOnly()
Indicate whether the Map is read only.- Returns:
true
if the Map is read only, otherwisefalse
.
-
clear
public void clear()
clear() operation is not supported.- Specified by:
clear
in interfacejava.util.Map<K,java.lang.Object>
- Throws:
java.lang.UnsupportedOperationException
-
containsKey
public boolean containsKey(java.lang.Object key)
Indicate whether theDynaBean
contains a specified value for one (or more) of its properties.
-
containsValue
public boolean containsValue(java.lang.Object value)
Indicates whether the decoratedDynaBean
contains a specified value.
-
entrySet
public java.util.Set<java.util.Map.Entry<K,java.lang.Object>> entrySet()
Returns the Set of the property/value mappings in the decorated
DynaBean
.Each element in the Set is a
Map.Entry
type.- Specified by:
entrySet
in interfacejava.util.Map<K,java.lang.Object>
- Returns:
- An unmodifiable set of the DynaBean property name/value pairs
-
get
public java.lang.Object get(java.lang.Object key)
Return the value for the specified key from the decoratedDynaBean
.
-
isEmpty
public boolean isEmpty()
Indicate whether the decoratedDynaBean
has any properties.
-
keySet
public java.util.Set<K> keySet()
Returns the Set of the property names in the decorated
DynaBean
.N.B.For
DynaBean
s whose associatedDynaClass
is aMutableDynaClass
a new Set is created every time, otherwise the Set is created only once and cached.
-
put
public java.lang.Object put(K key, java.lang.Object value)
Set the value for the specified property in the decoratedDynaBean
.
-
putAll
public void putAll(java.util.Map<? extends K,? extends java.lang.Object> map)
Copy the contents of a Map to the decoratedDynaBean
.- Specified by:
putAll
in interfacejava.util.Map<K,java.lang.Object>
- Parameters:
map
- The Map of values to copy.- Throws:
java.lang.UnsupportedOperationException
- ifisReadOnly()
is true.
-
remove
public java.lang.Object remove(java.lang.Object key)
remove() operation is not supported.
-
size
public int size()
Returns the number properties in the decoratedDynaBean
.- Specified by:
size
in interfacejava.util.Map<K,java.lang.Object>
- Returns:
- The number of properties.
-
values
public java.util.Collection<java.lang.Object> values()
Returns the set of property values in the decoratedDynaBean
.- Specified by:
values
in interfacejava.util.Map<K,java.lang.Object>
- Returns:
- Unmodifiable collection of values.
-
getDynaBean
public DynaBean getDynaBean()
Provide access to the underlyingDynaBean
this Map decorates.- Returns:
- the decorated
DynaBean
.
-
convertKey
protected abstract K convertKey(java.lang.String propertyName)
Converts the name of a property to the key type of this decorator.- Parameters:
propertyName
- the name of a property- Returns:
- the converted key to be used in the decorated map
-
-