|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--org.apache.commons.collections.BeanMap
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
Nested Class Summary | |
protected static class |
BeanMap.MyMapEntry
Map entry used by BeanMap . |
Field Summary | |
static HashMap |
defaultTransformers
Maps primitive Class types to transformers. |
static Object[] |
NULL_ARGUMENTS
An empty array. |
Constructor Summary | |
BeanMap()
Constructs a new empty BeanMap . |
|
BeanMap(Object bean)
Constructs a new BeanMap that operates on the
specified 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)
Returns true if the bean defines a property with the given name. |
boolean |
containsValue(Object value)
Returns true if the bean defines a property whose current value is the given object. |
protected Object |
convertType(Class newType,
Object value)
Converts the given value to the given type. |
protected Object[] |
createWriteMethodArguments(Method method,
Object value)
Creates an array of parameters to pass to the given mutator method. |
Iterator |
entryIterator()
Convenience method for getting an iterator over the entries. |
Set |
entrySet()
Get the mappings for this BeanMap |
protected void |
firePropertyChange(Object key,
Object oldValue,
Object newValue)
Called during a successful put(Object,Object) operation.
|
Object |
get(Object name)
Returns the value of the bean's property with the given name. |
Object |
getBean()
Returns the bean currently being operated on. |
protected Method |
getReadMethod(Object name)
Returns the accessor for the property with the given name. |
Class |
getType(String name)
Returns the type of the property with the given name. |
protected Transformer |
getTypeTransformer(Class aType)
Returns a transformer for the given primitive type. |
protected Method |
getWriteMethod(Object name)
Returns the mutator for the property with the given name. |
Iterator |
keyIterator()
Convenience method for getting an iterator over the keys. |
Set |
keySet()
Get the keys for this BeanMap. |
protected void |
logInfo(Exception e)
Logs the given exception to System.out . |
protected void |
logWarn(Exception e)
Logs the given exception to System.err . |
Object |
put(Object name,
Object value)
Sets the bean property with the given name to the given value. |
void |
putAllWriteable(BeanMap map)
Puts all of the writeable properties from the given BeanMap into this BeanMap. |
protected void |
reinitialise()
Reinitializes this bean. |
void |
setBean(Object newBean)
Sets the bean to be operated on by this map. |
int |
size()
Returns the number of properties defined by the bean. |
Iterator |
valueIterator()
Convenience method for getting an iterator over the values. |
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 |
public static HashMap defaultTransformers
public static final Object[] NULL_ARGUMENTS
Constructor Detail |
public BeanMap()
BeanMap
.
public BeanMap(Object bean)
BeanMap
that operates on the
specified bean. If the given bean is null
, then
this map will be empty.
bean
- the bean for this map to operate onMethod Detail |
public void clear()
clear()
differs from the Map contract in that
the mappings are not actually removed from the map (the mappings for a
BeanMap are fixed).
clear
in interface Map
clear
in class AbstractMap
public Object clone() throws CloneNotSupportedException
clone
in class AbstractMap
public boolean containsKey(Object name)
String
; if not, this method
returns false. This method will also return false if the bean
does not define a property with that name.
containsKey
in interface Map
containsKey
in class AbstractMap
name
- the name of the property to check
String
;
false if the bean does not define a property with that name; or
true if the bean does define a property with that namepublic boolean containsValue(Object value)
containsValue
in interface Map
containsValue
in class AbstractMap
value
- the value to check
protected Object convertType(Class newType, Object value) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
If no such constructor exists, and the given type is a primitive
type, then the given value is converted to a string using its
toString()
method, and that string is
parsed into the correct primitve type using, for instance,
Integer.valueOf(String)
to convert the string into an
int
.
If no special constructor exists and the given type is not a primitive type, this method returns the original value.
newType
- the type to convert the value tovalue
- the value to conert
NumberFormatException
- if newType is a primitive type, and
the string representation of the given value cannot be converted
to that type
InstantiationException
- if the constructor found with
reflection raises it
InvocationTargetExcetpion
- if the constructor found with
reflection raises it
IllegalAccessException
- never
IllegalArgumentException
- never
InvocationTargetException
protected Object[] createWriteMethodArguments(Method method, Object value) throws IllegalAccessException, ClassCastException
convertType(Class,Object)
.
method
- the mutator methodvalue
- the value to pass to the mutator method
IllegalAccessException
- if convertType(Class,Object)
raises it
IllegalArgumentException
- if any other exception is raised
by convertType(Class,Object)
ClassCastException
public Iterator entryIterator()
public Set entrySet()
entrySet
in interface Map
entrySet
in class AbstractMap
protected void firePropertyChange(Object key, Object oldValue, Object newValue)
put(Object,Object)
operation.
Default implementation does nothing. Override to be notified of
property changes in the bean caused by this map.
key
- the name of the property that changedoldValue
- the old value for that propertynewValue
- the new value for that propertypublic Object get(Object name)
String
and must not be
null; otherwise, this method returns null
.
If the bean defines a property with the given name, the value of
that property is returned. Otherwise, null
is
returned.
get
in interface Map
get
in class AbstractMap
name
- the name of the property whose value to return
public Object getBean()
protected Method getReadMethod(Object name)
name
- the name of the property
String
; null if no such property exists; or the accessor
method for that propertypublic Class getType(String name)
name
- the name of the property
null
if no such
property existsprotected Transformer getTypeTransformer(Class aType)
aType
- the primitive type whose transformer to return
protected Method getWriteMethod(Object name)
name
- the name of the
String
; null if no such property exists; null if the
property is read-only; or the mutator method for that propertypublic Iterator keyIterator()
public Set keySet()
keySet
in interface Map
keySet
in class AbstractMap
protected void logInfo(Exception e)
System.out
. Used to display
warnings while accessing/mutating the bean.
e
- the exception to logprotected void logWarn(Exception e)
System.err
. Used to display
errors while accessing/mutating the bean.
e
- the exception to logpublic Object put(Object name, Object value) throws IllegalArgumentException, ClassCastException
put
in interface Map
put
in class AbstractMap
name
- the name of the property to setvalue
- the value to set that property to
IllegalArgumentException
- if the given name is null;
if the given name is not a String
; if the bean doesn't
define a property with that name; or if the bean property with
that name is read-only
ClassCastException
public void putAllWriteable(BeanMap map)
map
- the BeanMap whose properties to putprotected void reinitialise()
setBean(Object)
.
Does introspection to find properties.
public void setBean(Object newBean)
newBean
- the new bean to operate onpublic int size()
size
in interface Map
size
in class AbstractMap
public Iterator valueIterator()
public Collection values()
values
in interface Map
values
in class AbstractMap
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |