|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.pentaho.platform.util.beans.BeanUtil
public class BeanUtil
Utility methods for processing Java Beans in a consistent manner across all Pentaho projects. This is not an attempt to duplicate the behavior of commons-beanutils, rather, a central spot for common operations on beans so we can ensure that same bean property binding functionality and logic anytime we need to work with Java Beans.
This utility is especially important
in dealing with Pentaho Action beans IAction
s. See ActionHarness
for an IAction-specific
flavor of this utility.
ActionHarness
Nested Class Summary | |
---|---|
static class |
BeanUtil.EagerFailingCallback
|
static class |
BeanUtil.FeedbackValueGenerator
|
Constructor Summary | |
---|---|
BeanUtil(Object targetBean)
Setup a new bean util for operating on the given bean |
Method Summary | |
---|---|
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,
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,
ValueSetErrorCallback callback)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanUtil(Object targetBean)
targetBean
- the bean on which to operateMethod Detail |
---|
public void setDefaultCallback(ValueSetErrorCallback defaultCallback)
public boolean isReadable(String propertyName)
public Object getValue(String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
public Class<?> getPropertyType(String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
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-ability
true
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 BeanUtil.FeedbackValueGenerator
,
then the value will be derived by calling getValue(String)
Exception
- if there was a problem setting the value on the beanBeanUtil.FeedbackValueGenerator
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 BeanUtil.FeedbackValueGenerator
,
then the value will be derived by calling getValue(String)
callback
- a structure that alerts the caller of any error states and enables the caller
to fail, log, proceed, etc
Exception
- if there was a problem setting the value on the beanBeanUtil.FeedbackValueGenerator
,
ValueSetErrorCallback
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 BeanUtil.FeedbackValueGenerator
,
then the value will be derived by calling 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 setting
Exception
- when something goes wrong (controlled by the callback object)BeanUtil.FeedbackValueGenerator
,
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 bean
Exception
- if there was a problem setting the value on the beanpublic void setValues(Map<String,Object> propValueMap, ValueSetErrorCallback callback) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |