java.lang.Object | ||
↳ | java.util.AbstractMap<K, V> | |
↳ | org.apache.commons.collections.BeanMap |
This class is 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
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BeanMap.MyMapEntry | Map entry used by BeanMap . |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
NULL_ARGUMENTS | An empty array. | ||||||||||
defaultTransformers | Maps primitive Class types to transformers. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new empty
BeanMap . | |||||||||||
Constructs a new
BeanMap that operates on the
specified bean. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method reinitializes the bean map to have default values for the
bean's properties.
| |||||||||||
Clone this bean map using the following process:
| |||||||||||
Returns true if the bean defines a property with the given name.
| |||||||||||
Returns true if the bean defines a property whose current value is
the given object.
| |||||||||||
Convenience method for getting an iterator over the entries.
| |||||||||||
Gets a Set of MapEntry objects that are the mappings for this BeanMap.
| |||||||||||
Returns the value of the bean's property with the given name.
| |||||||||||
Returns the bean currently being operated on.
| |||||||||||
Returns the accessor for the property with the given name.
| |||||||||||
Returns the type of the property with the given name.
| |||||||||||
Returns the mutator for the property with the given name.
| |||||||||||
Convenience method for getting an iterator over the keys.
| |||||||||||
Get the keys for this BeanMap.
| |||||||||||
Sets the bean property with the given name to the given value.
| |||||||||||
Puts all of the writable properties from the given BeanMap into this
BeanMap.
| |||||||||||
Sets the bean to be operated on by this map.
| |||||||||||
Returns the number of properties defined by the bean.
| |||||||||||
Convenience method for getting an iterator over the values.
| |||||||||||
Returns the values for the BeanMap.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts the given value to the given type.
| |||||||||||
Creates an array of parameters to pass to the given mutator method.
| |||||||||||
Called during a successful
put(Object, Object) operation. | |||||||||||
Returns the accessor for the property with the given name.
| |||||||||||
Returns a transformer for the given primitive type.
| |||||||||||
Returns the mutator for the property with the given name.
| |||||||||||
Logs the given exception to
System.out . | |||||||||||
Logs the given exception to
System.err . | |||||||||||
Reinitializes this bean.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
|
An empty array. Used to invoke accessors via reflection.
Maps primitive Class types to transformers. The transformer transform strings into the appropriate primitive wrapper.
Constructs a new empty BeanMap
.
Constructs a new 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 on |
---|
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).
Clone this bean map using the following process:
CloneNotSupportedException |
---|
Returns true if the bean defines a property with the given name.
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.
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 name
Returns true if the bean defines a property whose current value is the given object.
value | the value to check |
---|
Convenience method for getting an iterator over the entries.
Gets a Set of MapEntry objects that are the mappings for this BeanMap.
Each MapEntry can be set but not removed.
Returns the value of the bean's property with the given name.
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.
name | the name of the property whose value to return |
---|
Returns the bean currently being operated on. The return value may be null if this map is empty.
Returns the accessor for the property with the given name.
name | the name of the property |
---|
Returns the type of the property with the given name.
name | the name of the property |
---|
null
if no such
property exists
Returns the mutator for the property with the given name.
name | the name of the property |
---|
Convenience method for getting an iterator over the keys.
Write-only properties will not be returned in the iterator.
Get the keys for this BeanMap.
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.
Sets the bean property with the given name to the given value.
name | the name of the property to set |
---|---|
value | 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 |
Puts all of the writable properties from the given BeanMap into this BeanMap. Read-only and Write-only properties will be ignored.
map | the BeanMap whose properties to put |
---|
Sets the bean to be operated on by this map. The given value may be null, in which case this map will be empty.
newBean | the new bean to operate on |
---|
Returns the number of properties defined by the bean.
Convenience method for getting an iterator over the values.
Returns the values for the BeanMap.
Converts the given value to the given type. First, reflection is is used to find a public constructor declared by the given class that takes one argument, which must be the precise type of the given value. If such a constructor is found, a new object is created by passing the given value to that constructor, and the newly constructed object is returned.
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 primitive type using, for instance,
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 to |
---|---|
value | the value to convert |
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 |
Creates an array of parameters to pass to the given mutator method.
If the given object is not the right type to pass to the method
directly, it will be converted using convertType(Class, Object)
.
method | the mutator method |
---|---|
value | 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 |
Called during a successful 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 changed |
---|---|
oldValue | the old value for that property |
newValue | the new value for that property |
Returns the accessor for the property with the given name.
name | the name of the property |
---|
String
; null if no such property exists; or the accessor
method for that property
Returns a transformer for the given primitive type.
aType | the primitive type whose transformer to return |
---|
Returns the mutator for the property with the given 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 property
Logs the given exception to System.out
. Used to display
warnings while accessing/mutating the bean.
ex | the exception to log |
---|
Logs the given exception to System.err
. Used to display
errors while accessing/mutating the bean.
ex | the exception to log |
---|
Reinitializes this bean. Called during setBean(Object)
.
Does introspection to find properties.