B
- the type of the bean this BeanAcessor is associated with.public interface BeanAccessor<B>
Modifier and Type | Method and Description |
---|---|
<V> V |
cast()
Tries to cast the bean wrapped by this
BeanAccessor an returns the result. |
B |
cloneBean()
Clones a bean based on the available property getters and setters, even if the bean class itself does not
implement Cloneable.
|
<T extends B> |
copyPropertiesTo(T target)
Copies property values from the bean wrapped by this
BeanAccessor to target for all cases where
the property names are the same. |
Map<String,Object> |
describe()
Return the entire set of properties for which the specified bean provides a read method.
|
B |
get()
Gets the bean wrapped by this
BeanAccessor . |
BeanAccessor<?> |
get(String propertyName)
Gets the value of the property with name
propertyName from the bean wrapped by this BeanAccessor. |
IndexedPropertyGetterAccessor<?> |
getIndexed(String propertyName)
Selects the indexed property with name
propertyName from the bean wrapped by this BeanAccessor . |
MappedPropertyGetterAccessor |
getMapped(String propertyName)
Selects the mapped property with name
propertyName from the bean wrapped by this BeanAccessor . |
ArgumentsAccessor |
invoke(String methodName)
Invokes the method with name
methodName . |
ArgumentsAccessor |
invokeExact(String methodName)
Invokes the method with name
methodName and the exact arguments. |
void |
populate(Map<String,Object> properties)
Populate
properties to the bean wrapped by this BeanAccessor . |
BeanPropertySetter<B> |
set(String propertyName)
Selects the property with name
propertyName for setting a new value. |
IndexedPropertySetterAccessor<B> |
setIndexed(String propertyName)
Selects the indexed property with name
propertyName for setting a new value. |
MappedPropertySetterAccessor<B> |
setMapped(String propertyName)
Selects the mapped property with name
propertyName for setting a new value. |
BeanAccessor<?> get(String propertyName)
propertyName
from the bean wrapped by this BeanAccessor. The
value will be wrapped in a BeanAccessor
to enable fluent calls.propertyName
- the name of the property to get the value from. Must not be null
!BeanAccessor
wrapping the properties value.IndexedPropertyGetterAccessor<?> getIndexed(String propertyName)
propertyName
from the bean wrapped by this BeanAccessor
. A
IndexedPropertyGetterAccessor
will be returned for specifying the index to return the value of.propertyName
- the name of the indexed property to select. Must not be null
!IndexedPropertyGetterAccessor
for specifying the index to return the value of.MappedPropertyGetterAccessor getMapped(String propertyName)
propertyName
from the bean wrapped by this BeanAccessor
. A
MappedPropertyGetterAccessor
will be returned for specifying the key to return the value of.propertyName
- the name of the mapped property to select. Must not be null
!MappedPropertyGetterAccessor
for specifying the key to return the value of.<V> V cast()
BeanAccessor
an returns the result.V
- the type to cast the wrapped bean to.V
.BeanPropertySetter<B> set(String propertyName)
propertyName
for setting a new value. A BeanPropertySetter
will be
returned for specifying the new value.propertyName
- the name of the property to select for setting a new value. Must not be null
.BeanPropertySetter
for setting a new value.IndexedPropertySetterAccessor<B> setIndexed(String propertyName)
propertyName
for setting a new value. A
IndexedPropertySetterAccessor
will be returned for specifying the index to set a new value to.propertyName
- the name of the indexed property to select for setting a new value. Must not be null
.IndexedPropertySetterAccessor
for setting a new value.MappedPropertySetterAccessor<B> setMapped(String propertyName)
propertyName
for setting a new value. A
MappedPropertySetterAccessor
will be returned for specifying the key to set a new value to.propertyName
- the name of the mapped property to select for setting a new value. Must not be null
.MappedPropertySetterAccessor
for setting a new value.B cloneBean()
Note: this method creates a shallow clone. In other words, any objects referred to by the bean are shared with the clone rather than being cloned in turn.
<T extends B> void copyPropertiesTo(T target)
BeanAccessor
to target
for all cases where
the property names are the same. For each property, a conversion is attempted as necessary.
Note that this method is intended to perform a "shallow copy" of the properties and so complex properties (for example, nested ones) will not be copied.
TODO should we implement something like the following?
If you know that no type conversions are required, the copyProperties()
method in
PropertyUtils
will execute faster than this method.
FIXME - Indexed and mapped properties that do not have getter and setter methods for the underlying array or Map are not copied by this method.
T
- the type of the bean to copy properties to.target
- the target to copy properties to from the wrapped beanMap<String,Object> describe()
This map can be fed back to a call to BeanAccessor.populate()
to reconstitute the same set of
properties, modulo differences for read-only and write-only properties, but only if there are no indexed
properties.
Warning: if any of the bean property implementations contain (directly or indirectly) a call to
this method then a stack overflow may result. For example:
will result in an infinite regression when
class MyBean
{
public Map<String, Object> getParameterMap()
{
on( this ).describe;
}
}
getParametersMap
is called. It is
recommended that such methods are given alternative names (for example, parametersMap
).
void populate(Map<String,Object> properties)
properties
to the bean wrapped by this BeanAccessor
. The map of properties passed to
this method has to specify names of properties to set and corresponding values as key-value-pairs.properties
- Map keyed by property name, with the corresponding value to be set.
Must not be null
.ArgumentsAccessor invoke(String methodName)
methodName
. An ArgumentsAccessor
will be returned to specify the
parameters for the method invocation.methodName
- the name of the method to invoke. Must not be null
!ArgumentsAccessor
to specify arguments for the method invocation.ArgumentsAccessor invokeExact(String methodName)
methodName
and the exact arguments. An ArgumentsAccessor
will be
returned to specify the parameters for the method invocation.methodName
- the name of the method to invoke. Must not be null
!ArgumentsAccessor
to specify any argumentsCopyright © 2012–2014 The Apache Software Foundation. All rights reserved.