public class BeanMap extends AbstractMap implements Cloneable
If an exception occurs during attempts to get or set a property then the property is considered non existent in the Map
Modifier and Type | Class and Description |
---|---|
protected static class |
BeanMap.MyMapEntry
Deprecated.
Map entry used by
BeanMap . |
AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry
Modifier and Type | Field and Description |
---|---|
static HashMap |
defaultTransformers
Deprecated.
Maps primitive Class types to transformers.
|
static Object[] |
NULL_ARGUMENTS
Deprecated.
An empty array.
|
Constructor and Description |
---|
BeanMap()
Deprecated.
Constructs a new empty
BeanMap . |
BeanMap(Object bean)
Deprecated.
Constructs a new
BeanMap that operates on the
specified bean. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Deprecated.
This method reinitializes the bean map to have default values for the
bean's properties.
|
Object |
clone()
Deprecated.
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)
Deprecated.
Returns true if the bean defines a property with the given name.
|
boolean |
containsValue(Object value)
Deprecated.
Returns true if the bean defines a property whose current value is
the given object.
|
protected Object |
convertType(Class newType,
Object value)
Deprecated.
Converts the given value to the given type.
|
protected Object[] |
createWriteMethodArguments(Method method,
Object value)
Deprecated.
Creates an array of parameters to pass to the given mutator method.
|
Iterator |
entryIterator()
Deprecated.
Convenience method for getting an iterator over the entries.
|
Set |
entrySet()
Deprecated.
Gets a Set of MapEntry objects that are the mappings for this BeanMap.
|
protected void |
firePropertyChange(Object key,
Object oldValue,
Object newValue)
Deprecated.
Called during a successful
put(Object,Object) operation. |
Object |
get(Object name)
Deprecated.
Returns the value of the bean's property with the given name.
|
Object |
getBean()
Deprecated.
Returns the bean currently being operated on.
|
protected Method |
getReadMethod(Object name)
Deprecated.
Returns the accessor for the property with the given name.
|
Method |
getReadMethod(String name)
Deprecated.
Returns the accessor for the property with the given name.
|
Class |
getType(String name)
Deprecated.
Returns the type of the property with the given name.
|
protected Transformer |
getTypeTransformer(Class aType)
Deprecated.
Returns a transformer for the given primitive type.
|
protected Method |
getWriteMethod(Object name)
Deprecated.
Returns the mutator for the property with the given name.
|
Method |
getWriteMethod(String name)
Deprecated.
Returns the mutator for the property with the given name.
|
Iterator |
keyIterator()
Deprecated.
Convenience method for getting an iterator over the keys.
|
Set |
keySet()
Deprecated.
Get the keys for this BeanMap.
|
protected void |
logInfo(Exception ex)
Deprecated.
Logs the given exception to
System.out . |
protected void |
logWarn(Exception ex)
Deprecated.
Logs the given exception to
System.err . |
Object |
put(Object name,
Object value)
Deprecated.
Sets the bean property with the given name to the given value.
|
void |
putAllWriteable(BeanMap map)
Deprecated.
Puts all of the writable properties from the given BeanMap into this
BeanMap.
|
protected void |
reinitialise()
Deprecated.
Reinitializes this bean.
|
void |
setBean(Object newBean)
Deprecated.
Sets the bean to be operated on by this map.
|
int |
size()
Deprecated.
Returns the number of properties defined by the bean.
|
String |
toString()
Deprecated.
|
Iterator |
valueIterator()
Deprecated.
Convenience method for getting an iterator over the values.
|
Collection |
values()
Deprecated.
Returns the values for the BeanMap.
|
public static final Object[] NULL_ARGUMENTS
public static HashMap defaultTransformers
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 onpublic String toString()
toString
in class AbstractMap
public Object clone() throws CloneNotSupportedException
clone
in class AbstractMap
CloneNotSupportedException
public void putAllWriteable(BeanMap map)
map
- the BeanMap whose properties to putpublic 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 boolean containsKey(Object 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.
containsKey
in interface Map
containsKey
in class AbstractMap
name
- the name of the property to checkString
;
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 checkpublic Object get(Object 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.
get
in interface Map
get
in class AbstractMap
name
- the name of the property whose value to returnpublic 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 toIllegalArgumentException
- 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-onlyClassCastException
public int size()
size
in interface Map
size
in class AbstractMap
public Set keySet()
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.
keySet
in interface Map
keySet
in class AbstractMap
public Set entrySet()
Each MapEntry can be set but not removed.
entrySet
in interface Map
entrySet
in class AbstractMap
public Collection values()
values
in interface Map
values
in class AbstractMap
public Class getType(String name)
name
- the name of the propertynull
if no such
property existspublic Iterator keyIterator()
Write-only properties will not be returned in the iterator.
public Iterator valueIterator()
public Iterator entryIterator()
public Object getBean()
public void setBean(Object newBean)
newBean
- the new bean to operate onpublic Method getReadMethod(String name)
name
- the name of the propertypublic Method getWriteMethod(String name)
name
- the name of the propertyprotected Method getReadMethod(Object name)
name
- the name of the propertyString
; null if no such property exists; or the accessor
method for that propertyprotected Method getWriteMethod(Object name)
name
- the name of theString
; null if no such property exists; null if the
property is read-only; or the mutator method for that propertyprotected void reinitialise()
setBean(Object)
.
Does introspection to find properties.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 propertyprotected Object[] createWriteMethodArguments(Method method, Object value) throws IllegalAccessException, ClassCastException
convertType(Class,Object)
.method
- the mutator methodvalue
- the value to pass to the mutator methodIllegalAccessException
- if convertType(Class,Object)
raises itIllegalArgumentException
- if any other exception is raised
by convertType(Class,Object)
ClassCastException
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 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.
newType
- the type to convert the value tovalue
- the value to convertNumberFormatException
- if newType is a primitive type, and
the string representation of the given value cannot be converted
to that typeInstantiationException
- if the constructor found with
reflection raises itInvocationTargetException
- if the constructor found with
reflection raises itIllegalAccessException
- neverIllegalArgumentException
- neverprotected Transformer getTypeTransformer(Class aType)
aType
- the primitive type whose transformer to returnprotected void logInfo(Exception ex)
System.out
. Used to display
warnings while accessing/mutating the bean.ex
- the exception to logprotected void logWarn(Exception ex)
System.err
. Used to display
errors while accessing/mutating the bean.ex
- the exception to logCopyright © 2001–2015 The Apache Software Foundation. All rights reserved.