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

Inner Class Summary
protected static class BeanMap.MyMapEntry
           
 
Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
static HashMap defaultTransformers
           
static Object[] NULL_ARGUMENTS
           
 
Constructor Summary
BeanMap()
           
BeanMap(Object bean)
           
 
Method Summary
 void clear()
          This method reinitializes the bean map to have default values for the bean's properties.
 Object clone()
          Clone this bean map using the following process: If there is no underlying bean, return a cloned BeanMap without a bean.
 boolean containsKey(Object name)
           
 boolean containsValue(Object value)
           
protected  Object convertType(Class newType, Object value)
           
protected  Object[] createWriteMethodArguments(Method method, Object value)
           
 Iterator entryIterator()
           
 Set entrySet()
          Get the mappings for this BeanMap
protected  void firePropertyChange(Object key, Object oldValue, Object newValue)
           
 Object get(Object name)
           
 Object getBean()
           
protected  Method getReadMethod(Object name)
           
 Class getType(String name)
           
protected  Transformer getTypeTransformer(Class aType)
           
protected  Method getWriteMethod(Object name)
           
 Iterator keyIterator()
           
 Set keySet()
          Get the keys for this BeanMap.
protected  void logInfo(Exception e)
           
protected  void logWarn(Exception e)
           
 Object put(Object name, Object value)
           
protected  void reinitialise()
           
 void setBean(Object newBean)
           
 int size()
           
 Iterator valueIterator()
           
 Collection values()
          Returns the values for the BeanMap.
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, putAll, remove, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultTransformers

public static HashMap defaultTransformers

NULL_ARGUMENTS

public static final Object[] NULL_ARGUMENTS
Constructor Detail

BeanMap

public BeanMap()

BeanMap

public BeanMap(Object bean)
Method Detail

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:

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.