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
Mapbehavior onDynaBeans.The motivation for this implementation is to provide access to
DynaBeanproperties in technologies that are unaware of BeanUtils andDynaBeans - such as the expression languages of JSTL and JSF.This rather technical base class implements the methods of the
Mapinterface on top of aDynaBean. It was introduced to handle generic parameters in a meaningful way without breaking backwards compatibility of theDynaBeanMapDecoratorclass: A map wrapping aDynaBeanshould be of typeMap<String, Object>. However, when using these generic parameters inDynaBeanMapDecoratorthis 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 whileDynaBeanMapDecoratorcould still remain with compatible parameters.- Since:
- BeanUtils 1.9.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBaseDynaBeanMapDecorator.MapEntry<K>Map.Entry implementation.
-
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 voidclear()Always throws UnsupportedOperationException because this operation is unsupported.booleancontainsKey(java.lang.Object key)Indicate whether theDynaBeancontains a specified value for one (or more) of its properties.booleancontainsValue(java.lang.Object value)Indicates whether the decoratedDynaBeancontains a specified value.protected abstract KconvertKey(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.Objectget(java.lang.Object key)Return the value for the specified key from the decoratedDynaBean.DynaBeangetDynaBean()Provide access to the underlyingDynaBeanthis Map decorates.private DynaProperty[]getDynaProperties()Convenience method to retrieve theDynaPropertys for thisDynaClass.booleanisEmpty()Indicate whether the decoratedDynaBeanhas any properties.booleanisReadOnly()Indicate whether the Map is read only.java.util.Set<K>keySet()Returns the Set of the property names in the decoratedDynaBean.java.lang.Objectput(K key, java.lang.Object value)Set the value for the specified property in the decoratedDynaBean.voidputAll(java.util.Map<? extends K,? extends java.lang.Object> map)Copy the contents of a Map to the decoratedDynaBean.java.lang.Objectremove(java.lang.Object key)Always throws UnsupportedOperationException because this operation is unsupported.intsize()Returns the number properties in the decoratedDynaBean.private java.lang.StringtoString(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 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 theDynaBeanis null.
-
BaseDynaBeanMapDecorator
public BaseDynaBeanMapDecorator(DynaBean dynaBean, boolean readOnly)
Construct a Map for the specifiedDynaBean.- Parameters:
dynaBean- The dyna bean being decoratedreadOnly-trueif the Map is read only otherwisefalse- Throws:
java.lang.IllegalArgumentException- if theDynaBeanis null.
-
-
Method Detail
-
clear
public void clear()
Always throws UnsupportedOperationException because this operation is unsupported.- Specified by:
clearin interfacejava.util.Map<K,java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- Always thrown.
-
containsKey
public boolean containsKey(java.lang.Object key)
Indicate whether theDynaBeancontains a specified value for one (or more) of its properties.
-
containsValue
public boolean containsValue(java.lang.Object value)
Indicates whether the decoratedDynaBeancontains a specified value.
-
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
-
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.Entrytype.- Specified by:
entrySetin 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.
-
getDynaBean
public DynaBean getDynaBean()
Provide access to the underlyingDynaBeanthis Map decorates.- Returns:
- the decorated
DynaBean.
-
getDynaProperties
private DynaProperty[] getDynaProperties()
Convenience method to retrieve theDynaPropertys for thisDynaClass.- Returns:
- The an array of the
DynaPropertys.
-
isEmpty
public boolean isEmpty()
Indicate whether the decoratedDynaBeanhas any properties.
-
isReadOnly
public boolean isReadOnly()
Indicate whether the Map is read only.- Returns:
trueif the Map is read only, otherwisefalse.
-
keySet
public java.util.Set<K> keySet()
Returns the Set of the property names in the decorated
DynaBean.N.B.For
DynaBeans whose associatedDynaClassis aMutableDynaClassa 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:
putAllin 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)
Always throws UnsupportedOperationException because this operation is unsupported.
-
size
public int size()
Returns the number properties in the decoratedDynaBean.- Specified by:
sizein interfacejava.util.Map<K,java.lang.Object>- Returns:
- The number of properties.
-
toString
private java.lang.String toString(java.lang.Object obj)
Convenience method to convert an Object to a String.- Parameters:
obj- The Object to convert- Returns:
- String representation of the object
-
-