public class BeanWrapper extends Object
"pro1.prop2" will access the property prop2 from the nested bean referenced by prop1.getNestesWrappers() method.| Constructor and Description |
|---|
BeanWrapper(Class clazz)
Construct a bean wrapper around an object that is an instance of the class
|
BeanWrapper(Object instance)
Construct a bean wrapper around an existing bean object
|
| Modifier and Type | Method and Description |
|---|---|
Object |
getBean()
Get the wrapped bean
|
Class<?> |
getBeanClass()
Get the wrapped bean class
|
Class<?> |
getClazz(String propertyName)
Gets the class of a property in the wrapped bean.
|
Field |
getField(String propertyName)
Gets the type of a property in the wrapped bean.
|
Map<String,BeanWrapper> |
getNestesWrappers()
Returns all the nested bean wrappers that have been created inside this bean wrapper.
Nested bean wrappers are created when you access a nested property (i.e. |
Type |
getType(String propertyName)
Gets the type of a property in the wrapped bean.
|
Type[] |
getTypeArguments(String propertyName)
Gets the type of a property in the wrapped bean.
|
Object |
getValue(String propertyName)
Gets the value of a property in the wrapped bean.
|
boolean |
hasProperty(String propertyName)
Checks whether a property exists in the wrapped bean.
|
void |
reset()
sets all properties to null in this instance and in all nested bean instances
|
void |
setBean(Object bean)
Replaces the wrapped bean with another instance of the same type
|
void |
setValue(String propertyName,
Object value)
Sets the value of a property in the wrapped bean.
|
void |
setValueOfString(String propertyName,
String value)
Same as
setValue(String propertyName, Object value) but the value will be converted from String to
whatever type the property referenced by propertyName is. |
public BeanWrapper(Object instance)
instance - public BeanWrapper(Class clazz)
clazz - class to instantiate the wrapped beanpublic Object getBean()
public void setBean(Object bean)
bean - instance of the new bean to wrapInvalidParameterException - if the new bean is not of the same type of the initially wrapped bean.public Class<?> getBeanClass()
public Map<String,BeanWrapper> getNestesWrappers()
public void reset()
public boolean hasProperty(String propertyName)
hasProperty("pro1.prop2") returns true only if prop1 exists is this bean and prop2 exists in the bean referenced by prop1.propertyName - public Object getValue(String propertyName)
getValue("pro1.prop2") will get the value of prop2 from the nested bean referenced by
prop1.propertyName - public Class<?> getClazz(String propertyName)
getType("pro1.prop2") will get the type of prop2 from the nested bean referenced by
prop1.propertyName - public Type getType(String propertyName)
getType("pro1.prop2") will get the type of prop2 from the nested bean referenced by
prop1.propertyName - public Type[] getTypeArguments(String propertyName)
getType("pro1.prop2") will get the type of prop2 from the nested bean referenced by
prop1.propertyName - public Field getField(String propertyName)
getType("pro1.prop2") will get the type of prop2 from the nested bean referenced by
prop1.propertyName - public void setValueOfString(String propertyName, String value)
setValue(String propertyName, Object value) but the value will be converted from String to
whatever type the property referenced by propertyName is.propertyName - value - String representation of the value to be setpublic void setValue(String propertyName, Object value)
setValue("pro1.prop2", Boolean.TRUE) will set the value of prop2 from the nested bean
referenced by prop1. If the value of prop1 was originally null, it would also be set to reference the new bean
holding the value of prop2propertyName - value - value to be setCopyright © 2012. All Rights Reserved.