org.apache.commons.collections
Class BeanMap
java.lang.Object
|
+--java.util.AbstractMap
|
+--org.apache.commons.collections.BeanMap
- All Implemented Interfaces:
- Cloneable, Map
- public class BeanMap
- extends AbstractMap
- implements Cloneable
An implementation of Map for JavaBeans which uses introspection to
get and put properties in the bean.
If an exception occurs during attempts to get or set a property then the
property is considered non existent in the Map
- Author:
- James Strachan
defaultTransformers
public static HashMap defaultTransformers
NULL_ARGUMENTS
public static final Object[] NULL_ARGUMENTS
BeanMap
public BeanMap()
BeanMap
public BeanMap(Object bean)
clear
public void clear()
- This method reinitializes the bean map to have default values for the
bean's properties. This is accomplished by constructing a new instance
of the bean which the map uses as its underlying data source. This
behavior for
clear()
differs from the Map contract in that
the mappings are not actually removed from the map (the mappings for a
BeanMap are fixed).
- Overrides:
clear
in class AbstractMap
clone
public Object clone()
throws CloneNotSupportedException
- Clone this bean map using the following process:
- If there is no underlying bean, return a cloned BeanMap without a
bean.
- Since there is an underlying bean, try to instantiate a new bean of
the same type using Class.newInstance().
- If the instantiation fails, throw a CloneNotSupportedException
- Clone the bean map and set the newly instantiated bean as the
underyling bean for the bean map.
- Copy each property that is both readable and writable from the
existing object to a cloned bean map.
- If anything fails along the way, throw a
CloneNotSupportedException.
containsKey
public boolean containsKey(Object name)
- Overrides:
containsKey
in class AbstractMap
containsValue
public boolean containsValue(Object value)
- Overrides:
containsValue
in class AbstractMap
convertType
protected Object convertType(Class newType,
Object value)
throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException
createWriteMethodArguments
protected Object[] createWriteMethodArguments(Method method,
Object value)
throws IllegalAccessException,
ClassCastException
entryIterator
public Iterator entryIterator()
entrySet
public Set entrySet()
- Get the mappings for this BeanMap
- Overrides:
entrySet
in class AbstractMap
- Returns:
- BeanMap mappings. The Set returned by this method
is not modifiable.
firePropertyChange
protected void firePropertyChange(Object key,
Object oldValue,
Object newValue)
get
public Object get(Object name)
- Overrides:
get
in class AbstractMap
getBean
public Object getBean()
getReadMethod
protected Method getReadMethod(Object name)
getType
public Class getType(String name)
getTypeTransformer
protected Transformer getTypeTransformer(Class aType)
getWriteMethod
protected Method getWriteMethod(Object name)
keyIterator
public Iterator keyIterator()
keySet
public Set keySet()
- Get the keys for this BeanMap.
- Overrides:
keySet
in class AbstractMap
- Returns:
- BeanMap keys. The Set returned bu this method is not
modifiable.
logInfo
protected void logInfo(Exception e)
logWarn
protected void logWarn(Exception e)
put
public Object put(Object name,
Object value)
throws IllegalArgumentException,
ClassCastException
- Overrides:
put
in class AbstractMap
reinitialise
protected void reinitialise()
setBean
public void setBean(Object newBean)
size
public int size()
- Overrides:
size
in class AbstractMap
valueIterator
public Iterator valueIterator()
values
public Collection values()
- Returns the values for the BeanMap.
- Overrides:
values
in class AbstractMap
- Returns:
- values for the BeanMap. The returned collection is not
modifiable.
Copyright © 2001 Apache Software Foundation. Documenation generated April 2 2002.