public class BeanUtil extends Object
This utility is especially important in dealing with Hitachi Vantara Action beans IAction
s. See
ActionHarness
for an IAction-specific flavor of this utility.
ActionHarness
Modifier and Type | Class and Description |
---|---|
static class |
BeanUtil.EagerFailingCallback |
static class |
BeanUtil.FeedbackValueGenerator |
Modifier and Type | Field and Description |
---|---|
protected Object |
bean |
protected ValueSetErrorCallback |
defaultCallback |
Constructor and Description |
---|
BeanUtil(Object targetBean)
Setup a new bean util for operating on the given bean
|
Modifier and Type | Method and Description |
---|---|
Class<?> |
getPropertyType(String propertyName) |
Object |
getValue(String propertyName) |
boolean |
isReadable(String propertyName) |
boolean |
isWriteable(String propertyName)
Returns
true if a bean property can be written to (i.e. |
void |
setDefaultCallback(ValueSetErrorCallback defaultCallback) |
void |
setValue(String propertyName,
Object value)
Set a bean property with a given value.
|
void |
setValue(String propertyName,
Object value,
PropertyNameFormatter... formatters)
Set a bean property with a given value, allowing the caller to respond to various error states that may be
encountered during the attempt to set the value on the bean.
|
void |
setValue(String propertyName,
Object value,
ValueSetErrorCallback callback)
Set a bean property with a given value, allowing the caller to respond to various error states that may be
encountered during the attempt to set the value on the bean.
|
void |
setValue(String propertyName,
Object value,
ValueSetErrorCallback callback,
PropertyNameFormatter... formatters)
Set a bean property with a given value, allowing the caller to respond to various error states that may be
encountered during the attempt to set the value on the bean.
|
void |
setValues(Map<String,Object> propValueMap)
Sets a number of bean properties based on given property-value map, where the key of the map is the bean
property and the value is the value to which to set that property.
|
void |
setValues(Map<String,Object> propValueMap,
PropertyNameFormatter... formatters) |
void |
setValues(Map<String,Object> propValueMap,
ValueSetErrorCallback callback) |
protected Object bean
protected ValueSetErrorCallback defaultCallback
public BeanUtil(Object targetBean)
targetBean
- the bean on which to operatepublic void setDefaultCallback(ValueSetErrorCallback defaultCallback)
public boolean isReadable(String propertyName)
public Object getValue(String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
public Class<?> getPropertyType(String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
public boolean isWriteable(String propertyName)
true
if a bean property can be written to (i.e. there is an accessible and appropriately
typed setter method on the bean). Note: this method will check for both scalar (normal) and indexed properties
before returning false
.propertyName
- the name of the bean property to check for write-abilitytrue
if the bean property can be written topublic void setValue(String propertyName, Object value) throws Exception
propertyName
- the bean property to setvalue
- the value to set on the bean. If value is an instance of ValueGenerator
, then the value will
be derived by calling ValueGenerator.getValue(String)
Exception
- if there was a problem setting the value on the beanValueGenerator
public void setValue(String propertyName, Object value, ValueSetErrorCallback callback) throws Exception
propertyName
- the bean property to setvalue
- the value to set on the bean. If value is an instance of ValueGenerator
, then the value will
be derived by calling ValueGenerator.getValue(String)
callback
- a structure that alerts the caller of any error states and enables the caller to fail, log, proceed,
etcException
- if there was a problem setting the value on the beanValueGenerator
,
ValueSetErrorCallback
public void setValue(String propertyName, Object value, PropertyNameFormatter... formatters) throws Exception
propertyName
- the bean property to setvalue
- the value to set on the bean. If value is an instance of ValueGenerator
, then the value will
be derived by calling ValueGenerator.getValue(String)
. Note: if value is null
,
we consciously bypass the set operation altogether since it leads to indeterminate behavior, i.e. it
may fail or succeed.callback
- a structure that alerts the caller of any error states and enables the caller to fail, log, proceed,
etcformatters
- a list of objects that can be used to modify the given property name prior to performing any
operations on the bean itself. This new formatted property name will be used to identify the bean
property. bean lookup and value settingException
- when something goes wrong (controlled by the callback object)ValueGenerator
,
ValueSetErrorCallback
,
PropertyNameFormatter
public void setValue(String propertyName, Object value, ValueSetErrorCallback callback, PropertyNameFormatter... formatters) throws Exception
propertyName
- the bean property to setvalue
- the value to set on the bean. If value is an instance of ValueGenerator
, then the value will
be derived by calling ValueGenerator.getValue(String)
. Note: if value is null
,
we consciously bypass the set operation altogether since it leads to indeterminate behavior, i.e. it
may fail or succeed.callback
- a structure that alerts the caller of any error states and enables the caller to fail, log, proceed,
etcformatters
- a list of objects that can be used to modify the given property name prior to performing any
operations on the bean itself. This new formatted property name will be used to identify the bean
property. bean lookup and value settingException
- when something goes wrong (controlled by the callback object)ValueGenerator
,
ValueSetErrorCallback
,
PropertyNameFormatter
public void setValues(Map<String,Object> propValueMap) throws Exception
propValueMap
- a map whose keys are property names and whose values are to be set on the associated property of the
beanException
- if there was a problem setting the value on the beanpublic void setValues(Map<String,Object> propValueMap, ValueSetErrorCallback callback) throws Exception
Exception
Copyright © 2017 Hitachi Vantara. All rights reserved.