K
- the type of the keys in the decorated mappublic abstract class BaseDynaBeanMapDecorator<K>
extends java.lang.Object
implements java.util.Map<K,java.lang.Object>
A base class for decorators providing Map
behavior on
DynaBean
s.
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 rather technical base class implements the methods of the
Map
interface on top of a DynaBean
. It was introduced
to handle generic parameters in a meaningful way without breaking
backwards compatibility of the DynaBeanMapDecorator
class: A
map wrapping a DynaBean
should be of type Map<String, Object>
.
However, when using these generic parameters in DynaBeanMapDecorator
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 while
DynaBeanMapDecorator
could still remain with compatible
parameters.
Modifier and Type | Class and Description |
---|---|
private static class |
BaseDynaBeanMapDecorator.MapEntry<K>
Map.Entry implementation.
|
Modifier and Type | Field and Description |
---|---|
private DynaBean |
dynaBean |
private java.util.Set<K> |
keySet |
private boolean |
readOnly |
Constructor and Description |
---|
BaseDynaBeanMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specified
DynaBean . |
BaseDynaBeanMapDecorator(DynaBean dynaBean,
boolean readOnly)
Construct a Map for the specified
DynaBean . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
clear() operation is not supported.
|
boolean |
containsKey(java.lang.Object key)
Indicate whether the
DynaBean contains a specified
value for one (or more) of its properties. |
boolean |
containsValue(java.lang.Object value)
Indicates whether the decorated
DynaBean 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 decorated
DynaBean . |
java.lang.Object |
get(java.lang.Object key)
Return the value for the specified key from
the decorated
DynaBean . |
DynaBean |
getDynaBean()
Provide access to the underlying
DynaBean
this Map decorates. |
private DynaProperty[] |
getDynaProperties()
Convenience method to retrieve the
DynaProperty s
for this DynaClass . |
boolean |
isEmpty()
Indicate whether the decorated
DynaBean 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 decorated
DynaBean . |
java.lang.Object |
put(K key,
java.lang.Object value)
Set the value for the specified property in
the decorated
DynaBean . |
void |
putAll(java.util.Map<? extends K,? extends java.lang.Object> map)
Copy the contents of a Map to the decorated
DynaBean . |
java.lang.Object |
remove(java.lang.Object key)
remove() operation is not supported.
|
int |
size()
Returns the number properties in the decorated
DynaBean . |
private java.lang.String |
toString(java.lang.Object obj)
Convenience method to convert an Object
to a String.
|
java.util.Collection<java.lang.Object> |
values()
Returns the set of property values in the
decorated
DynaBean . |
private final DynaBean dynaBean
private final boolean readOnly
private transient java.util.Set<K> keySet
public BaseDynaBeanMapDecorator(DynaBean dynaBean)
DynaBean
.dynaBean
- The dyna bean being decoratedjava.lang.IllegalArgumentException
- if the DynaBean
is null.public BaseDynaBeanMapDecorator(DynaBean dynaBean, boolean readOnly)
DynaBean
.dynaBean
- The dyna bean being decoratedreadOnly
- true
if the Map is read only
otherwise false
java.lang.IllegalArgumentException
- if the DynaBean
is null.public boolean isReadOnly()
true
if the Map is read only,
otherwise false
.public void clear()
clear
in interface java.util.Map<K,java.lang.Object>
java.lang.UnsupportedOperationException
public boolean containsKey(java.lang.Object key)
DynaBean
contains a specified
value for one (or more) of its properties.public boolean containsValue(java.lang.Object value)
DynaBean
contains
a specified value.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.
entrySet
in interface java.util.Map<K,java.lang.Object>
public java.lang.Object get(java.lang.Object key)
DynaBean
.public boolean isEmpty()
DynaBean
has
any properties.public java.util.Set<K> keySet()
Returns the Set of the property
names in the decorated DynaBean
.
N.B.For DynaBean
s whose associated DynaClass
is a MutableDynaClass
a new Set is created every
time, otherwise the Set is created only once and cached.
public java.lang.Object put(K key, java.lang.Object value)
DynaBean
.public void putAll(java.util.Map<? extends K,? extends java.lang.Object> map)
DynaBean
.putAll
in interface java.util.Map<K,java.lang.Object>
map
- The Map of values to copy.java.lang.UnsupportedOperationException
- if
isReadOnly()
is true.public java.lang.Object remove(java.lang.Object key)
public int size()
DynaBean
.size
in interface java.util.Map<K,java.lang.Object>
public java.util.Collection<java.lang.Object> values()
DynaBean
.values
in interface java.util.Map<K,java.lang.Object>
public DynaBean getDynaBean()
DynaBean
this Map decorates.DynaBean
.protected abstract K convertKey(java.lang.String propertyName)
propertyName
- the name of a propertyprivate DynaProperty[] getDynaProperties()
DynaProperty
s
for this DynaClass
.DynaProperty
s.private java.lang.String toString(java.lang.Object obj)
obj
- The Object to convertCopyright (c) 2000-2008 - Apache Software Foundation