|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.beanutils.DynaBeanMapDecorator
public class DynaBeanMapDecorator
Decorates a DynaBean to provide Map behaviour.
The motivation for this implementation is to provide access to DynaBean
properties in technologies that are unaware of BeanUtils and DynaBeans -
such as the expression languages of JSTL and JSF.
This can be achieved either by wrapping the DynaBean prior to
providing it to the technolody to process or by providing a Map
accessor method on the DynaBean implementation:
public Map getMap() {
return new DynaBeanMapDecorator(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 fooMap = new DynaBeanMapDecorator(fooDynaBean);The above example creates a read only Map.
To create a Map which can be modified, construct a
DynaBeanMapDecorator with the read only
attribute set to false:
Map fooMap = new DynaBeanMapDecorator(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.
| Nested Class Summary | |
|---|---|
private static class |
DynaBeanMapDecorator.MapEntry
Map.Entry implementation. |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Field Summary | |
|---|---|
private DynaBean |
dynaBean
|
private java.util.Set |
keySet
|
private boolean |
readOnly
|
| Constructor Summary | |
|---|---|
DynaBeanMapDecorator(DynaBean dynaBean)
Constructs a read only Map for the specified DynaBean. |
|
DynaBeanMapDecorator(DynaBean dynaBean,
boolean readOnly)
Construct a Map for the specified DynaBean. |
|
| Method Summary | |
|---|---|
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. |
java.util.Set |
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 DynaPropertys
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 |
keySet()
Returns the Set of the property names in the decorated DynaBean. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Set the value for the specified property in the decorated DynaBean. |
void |
putAll(java.util.Map 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 |
values()
Returns the set of property values in the decorated DynaBean. |
| 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 |
|---|
equals, hashCode |
| Field Detail |
|---|
private DynaBean dynaBean
private boolean readOnly
private transient java.util.Set keySet
| Constructor Detail |
|---|
public DynaBeanMapDecorator(DynaBean dynaBean)
DynaBean.
dynaBean - The dyna bean being decorated
java.lang.IllegalArgumentException - if the DynaBean is null.
public DynaBeanMapDecorator(DynaBean dynaBean,
boolean readOnly)
DynaBean.
dynaBean - The dyna bean being decoratedreadOnly - true if the Mpa is read only
otherwise false
java.lang.IllegalArgumentException - if the DynaBean is null.| Method Detail |
|---|
public boolean isReadOnly()
true if the Map is read only,
otherwise false.public void clear()
clear in interface java.util.Mapjava.lang.UnsupportedOperationExceptionpublic boolean containsKey(java.lang.Object key)
DynaBean contains a specified
value for one (or more) of its properties.
containsKey in interface java.util.Mapkey - The DynaBean's property name
true if one of the DynaBean's
properties contains a specified value.public boolean containsValue(java.lang.Object value)
DynaBean contains
a specified value.
containsValue in interface java.util.Mapvalue - The value to check for.
true if one of the the DynaBean's
properties contains the specified value, otherwise
false.public java.util.Set 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.Mappublic java.lang.Object get(java.lang.Object key)
DynaBean.
get in interface java.util.Mapkey - The DynaBean's property name
public boolean isEmpty()
DynaBean has
any properties.
isEmpty in interface java.util.Maptrue if the DynaBean has
no properties, otherwise false.public java.util.Set keySet()
Returns the Set of the property
names in the decorated DynaBean.
N.B.For DynaBeans whose associated DynaClass
is a MutableDynaClass a new Set is created every
time, otherwise the Set is created only once and cached.
keySet in interface java.util.MapDynaBeans
property names.
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
DynaBean.
put in interface java.util.Mapkey - The DynaBean's property namevalue - The value for the specified property.
java.lang.UnsupportedOperationException - if
isReadOnly() is true.public void putAll(java.util.Map map)
DynaBean.
putAll in interface java.util.Mapmap - The Map of values to copy.
java.lang.UnsupportedOperationException - if
isReadOnly() is true.public java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapkey - The DynaBean's property name
java.lang.UnsupportedOperationExceptionpublic int size()
DynaBean.
size in interface java.util.Mappublic java.util.Collection values()
DynaBean.
values in interface java.util.Mappublic DynaBean getDynaBean()
DynaBean
this Map decorates.
DynaBean.private DynaProperty[] getDynaProperties()
DynaPropertys
for this DynaClass.
DynaPropertys.private java.lang.String toString(java.lang.Object obj)
obj - The Object to convert
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||