|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.beanutils
Class BeanMap

java.lang.Objectjava.util.AbstractMap
org.apache.commons.beanutils.BeanMap
- All Implemented Interfaces:
- java.lang.Cloneable, java.util.Map
- public class BeanMap
- extends java.util.AbstractMap
- implements java.lang.Cloneable
- extends java.util.AbstractMap
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
- Version:
- $Revision: 1.2.2.2 $ $Date: 2004/06/22 21:07:02 $
| Nested Class Summary | |
protected static class |
BeanMap.Entry
Map entry used by BeanMap. |
| Nested classes inherited from class java.util.AbstractMap |
|
| Field Summary | |
private java.lang.Object |
bean
|
static java.util.HashMap |
defaultTransformers
Maps primitive Class types to transformers. |
static java.lang.Object[] |
NULL_ARGUMENTS
An empty array. |
private java.util.HashMap |
readMethods
|
private java.util.HashMap |
types
|
private java.util.HashMap |
writeMethods
|
| Fields inherited from class java.util.AbstractMap |
|
| Constructor Summary | |
BeanMap()
Constructs a new empty BeanMap. |
|
BeanMap(java.lang.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. |
java.lang.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(java.lang.Object name)
Returns true if the bean defines a property with the given name. |
boolean |
containsValue(java.lang.Object value)
Returns true if the bean defines a property whose current value is the given object. |
protected java.lang.Object |
convertType(java.lang.Class newType,
java.lang.Object value)
Converts the given value to the given type. |
protected java.lang.Object[] |
createWriteMethodArguments(java.lang.reflect.Method method,
java.lang.Object value)
Creates an array of parameters to pass to the given mutator method. |
java.util.Iterator |
entryIterator()
Convenience method for getting an iterator over the entries. |
java.util.Set |
entrySet()
Gets a Set of MapEntry objects that are the mappings for this BeanMap. |
protected void |
firePropertyChange(java.lang.Object key,
java.lang.Object oldValue,
java.lang.Object newValue)
Called during a successful put(Object,Object) 55 operation. |
java.lang.Object |
get(java.lang.Object name)
Returns the value of the bean's property with the given name. |
java.lang.Object |
getBean()
Returns the bean currently being operated on. |
protected java.lang.reflect.Method |
getReadMethod(java.lang.Object name)
Returns the accessor for the property with the given name. |
java.lang.reflect.Method |
getReadMethod(java.lang.String name)
Returns the accessor for the property with the given name. |
java.lang.Class |
getType(java.lang.String name)
Returns the type of the property with the given name. |
protected org.apache.commons.collections.Transformer |
getTypeTransformer(java.lang.Class aType)
Returns a transformer for the given primitive type. |
protected java.lang.reflect.Method |
getWriteMethod(java.lang.Object name)
Returns the mutator for the property with the given name. |
java.lang.reflect.Method |
getWriteMethod(java.lang.String name)
Returns the mutator for the property with the given name. |
private void |
initialise()
|
java.util.Iterator |
keyIterator()
Convenience method for getting an iterator over the keys. |
java.util.Set |
keySet()
Get the keys for this BeanMap. |
protected void |
logInfo(java.lang.Exception ex)
Logs the given exception to System.out. |
protected void |
logWarn(java.lang.Exception ex)
Logs the given exception to System.err. |
java.lang.Object |
put(java.lang.Object name,
java.lang.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(java.lang.Object newBean)
Sets the bean to be operated on by this map. |
int |
size()
Returns the number of properties defined by the bean. |
java.lang.String |
toString()
Renders a string representation of this object. |
java.util.Iterator |
valueIterator()
Convenience method for getting an iterator over the values. |
java.util.Collection |
values()
Returns the values for the BeanMap. |
| Methods inherited from class java.util.AbstractMap |
equals, hashCode, isEmpty, putAll, remove |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
bean
private transient java.lang.Object bean
readMethods
private transient java.util.HashMap readMethods
writeMethods
private transient java.util.HashMap writeMethods
types
private transient java.util.HashMap types
NULL_ARGUMENTS
public static final java.lang.Object[] NULL_ARGUMENTS
- An empty array. Used to invoke accessors via reflection.
defaultTransformers
public static java.util.HashMap defaultTransformers
- Maps primitive Class types to transformers. The transformer
transform strings into the appropriate primitive wrapper.
| Constructor Detail |
BeanMap
public BeanMap()
- Constructs a new empty
BeanMap.
BeanMap
public BeanMap(java.lang.Object bean)
- Constructs a new
BeanMapthat operates on the specified bean. If the given bean isnull, then this map will be empty.
| Method Detail |
toString
public java.lang.String toString()
- Renders a string representation of this object.
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Clone this bean map using the following process:
- If there is no underlying bean, return a cloned BeanMap without a bean.
- Since there is an underlying bean, try to instantiate a new bean of the same type using Class.newInstance().
- If the instantiation fails, throw a CloneNotSupportedException
- Clone the bean map and set the newly instantiated bean as the underlying bean for the bean map.
- Copy each property that is both readable and writable from the existing object to a cloned bean map.
- If anything fails along the way, throw a
CloneNotSupportedException.
putAllWriteable
public void putAllWriteable(BeanMap map)
- Puts all of the writable properties from the given BeanMap into this
BeanMap. Read-only and Write-only properties will be ignored.
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).- Specified by:
clearin interfacejava.util.Map
containsKey
public boolean containsKey(java.lang.Object name)
- 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.
- Specified by:
containsKeyin interfacejava.util.Map
containsValue
public boolean containsValue(java.lang.Object value)
- Returns true if the bean defines a property whose current value is
the given object.
- Specified by:
containsValuein interfacejava.util.Map
get
public java.lang.Object get(java.lang.Object name)
- Returns the value of the bean's property with the given name.
The given name must be a java.lang.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,nullis returned.Write-only properties will not be matched as the test operates against property read methods.
- Specified by:
getin interfacejava.util.Map
put
public java.lang.Object put(java.lang.Object name, java.lang.Object value) throws java.lang.IllegalArgumentException, java.lang.ClassCastException
- Sets the bean property with the given name to the given value.
- Specified by:
putin interfacejava.util.Map
size
public int size()
- Returns the number of properties defined by the bean.
- Specified by:
sizein interfacejava.util.Map
keySet
public java.util.Set keySet()
- 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.
- Specified by:
keySetin interfacejava.util.Map
entrySet
public java.util.Set entrySet()
- Gets a Set of MapEntry objects that are the mappings for this BeanMap.
Each MapEntry can be set but not removed.
- Specified by:
entrySetin interfacejava.util.Map
values
public java.util.Collection values()
- Returns the values for the BeanMap.
- Specified by:
valuesin interfacejava.util.Map
getType
public java.lang.Class getType(java.lang.String name)
- Returns the type of the property with the given name.
keyIterator
public java.util.Iterator keyIterator()
- Convenience method for getting an iterator over the keys.
Write-only properties will not be returned in the iterator.
valueIterator
public java.util.Iterator valueIterator()
- Convenience method for getting an iterator over the values.
entryIterator
public java.util.Iterator entryIterator()
- Convenience method for getting an iterator over the entries.
getBean
public java.lang.Object getBean()
- Returns the bean currently being operated on. The return value may
be null if this map is empty.
setBean
public void setBean(java.lang.Object newBean)
- Sets the bean to be operated on by this map. The given value may
be null, in which case this map will be empty.
getReadMethod
public java.lang.reflect.Method getReadMethod(java.lang.String name)
- Returns the accessor for the property with the given name.
getWriteMethod
public java.lang.reflect.Method getWriteMethod(java.lang.String name)
- Returns the mutator for the property with the given name.
getReadMethod
protected java.lang.reflect.Method getReadMethod(java.lang.Object name)
- Returns the accessor for the property with the given name.
getWriteMethod
protected java.lang.reflect.Method getWriteMethod(java.lang.Object name)
- Returns the mutator for the property with the given name.
reinitialise
protected void reinitialise()
- Reinitializes this bean. Called during
setBean(Object)55 . Does introspection to find properties.
initialise
private void initialise()
firePropertyChange
protected void firePropertyChange(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
- Called during a successful
put(Object,Object)55 operation. Default implementation does nothing. Override to be notified of property changes in the bean caused by this map.
createWriteMethodArguments
protected java.lang.Object[] createWriteMethodArguments(java.lang.reflect.Method method, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.ClassCastException
- 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)55 .
convertType
protected java.lang.Object convertType(java.lang.Class newType, java.lang.Object value) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
- 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() 55 method, and that string is parsed into the correct primitive type using, for instance, Integer.valueOf(String)>
Integer.valueOf(String)55 to convert the string into anint.If no special constructor exists and the given type is not a primitive type, this method returns the original value.
getTypeTransformer
protected org.apache.commons.collections.Transformer getTypeTransformer(java.lang.Class aType)
- Returns a transformer for the given primitive type.
logInfo
protected void logInfo(java.lang.Exception ex)
- Logs the given exception to
System.out. Used to display warnings while accessing/mutating the bean.
logWarn
protected void logWarn(java.lang.Exception ex)
- Logs the given exception to
System.err. Used to display errors while accessing/mutating the bean.
|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC