org.apache.commons.collections
public class BeanMap extends AbstractMap implements Cloneable
Deprecated: Identical class now available in commons-beanutils (full jar version). This version is due to be removed in collections v4.0.
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
Since: Commons Collections 1.0
Version: $Revision: 158697 $ $Date: 2005-03-22 23:47:45 +0000 (Tue, 22 Mar 2005) $
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:
|
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()
Gets a Set of MapEntry objects that are the mappings for this BeanMap.
|
protected void | firePropertyChange(Object key, Object oldValue, Object newValue)
Called during a successful put 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. |
Method | getReadMethod(String name)
Returns the accessor for the property with the given name.
|
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.
|
Method | getWriteMethod(String name)
Returns the mutator for the property with the given name.
|
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 ex)
Logs the given exception to System.out . |
protected void | logWarn(Exception ex)
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 writable 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.
|
String | toString() |
Iterator | valueIterator()
Convenience method for getting an iterator over the values.
|
Collection | values()
Returns the values for the BeanMap.
|
BeanMap
.BeanMap
that operates on the
specified bean. If the given bean is null
, then
this map will be empty.
Parameters: bean the bean for this map to operate on
clear()
differs from the Map contract in that
the mappings are not actually removed from the map (the mappings for a
BeanMap are fixed).
The given name must be a String
; if not, this method
returns false. This method will also return false if the bean
does not define a property with that name.
Write-only properties will not be matched as the test operates against property read methods.
Parameters: name the name of the property to check
Returns: false if the given name is null or is not a String
;
false if the bean does not define a property with that name; or
true if the bean does define a property with that name
Parameters: value the value to check
Returns: false true if the bean has at least one property whose current value is that object, false otherwise
If no such constructor exists, and the given type is a primitive
type, then the given value is converted to a string using its
Object#toString() toString()
method, and that string is
parsed into the correct primitive 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.
Parameters: newType the type to convert the value to value the value to convert
Returns: the converted value
Throws: 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 InvocationTargetException if the constructor found with reflection raises it IllegalAccessException never IllegalArgumentException never
Parameters: method the mutator method value the value to pass to the mutator method
Returns: an array containing one object that is either the given value or a transformed value
Throws: IllegalAccessException if convertType raises it IllegalArgumentException if any other exception is raised by convertType
Returns: an iterator over the entries
Each MapEntry can be set but not removed.
Returns: the unmodifiable set of mappings
Parameters: key the name of the property that changed oldValue the old value for that property newValue the new value for that property
The given name must be a 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.
Write-only properties will not be matched as the test operates against property read methods.
Parameters: name the name of the property whose value to return
Returns: the value of the property with that name
Returns: the bean being operated on by this map
Parameters: name the name of the property
Returns: the accessor method for the property, or null
Parameters: name the name of the property
Returns: null if the name is null; null if the name is not a String; null if no such property exists; or the accessor method for that property
Parameters: name the name of the property
Returns: the type of the property, or null
if no such
property exists
Parameters: aType the primitive type whose transformer to return
Returns: a transformer that will convert strings into that type, or null if the given type is not a primitive type
Parameters: name the name of the property
Returns: the mutator method for the property, or null
Parameters: name the name of the
Returns: null if the name is null; null if the name is not a String; null if no such property exists; null if the property is read-only; or the mutator method for that property
Write-only properties will not be returned in the iterator.
Returns: an iterator over the keys
Write-only properties are not included in the returned set of property names, although it is possible to set their value and to get their type.
Returns: BeanMap keys. The Set returned by this method is not modifiable.
System.out
. Used to display
warnings while accessing/mutating the bean.
Parameters: ex the exception to log
System.err
. Used to display
errors while accessing/mutating the bean.
Parameters: ex the exception to log
Parameters: name the name of the property to set value the value to set that property to
Returns: the previous value of that property
Throws: 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
Parameters: map the BeanMap whose properties to put
Parameters: newBean the new bean to operate on
Returns: the number of properties defined by the bean
Returns: an iterator over the values
Returns: values for the BeanMap. The returned collection is not modifiable.