public class JuffrouBeanWrapper extends Object
Allows access to the wrapped bean's properties and also to the properties of beans referenced by them. For example
the property path "pro1.prop2"
will access the property prop2 from the nested bean referenced by prop1.
This bean wrapper auto grows nested paths, so for each nested bean referenced in this manner, a nested bean wrapper
is automatically created. In the previous example, a bean wrapper would be created for the bean referenced by
property prop1. The nested bean wrappers can be obtained by calling the getNestesWrappers()
method.
You can reference nested properties as deep as you like as long as the bean path exists.
Constructor and Description |
---|
JuffrouBeanWrapper(BeanWrapperContext context)
Construct a bean wrapper using the metadata and preferences of an existing BeanWrapperContext.
Performance is better, because there is no need to do introspection. |
JuffrouBeanWrapper(BeanWrapperContext context,
JuffrouBeanWrapper parentBeanWrapper,
String parentBeanProperty) |
JuffrouBeanWrapper(BeanWrapperContext context,
Object instance)
Construct a bean wrapper using the metadata and preferences of an existing BeanWrapperContext and initializes it
with an instance value.
Performance is better, because there is no need to do introspection. |
JuffrouBeanWrapper(Class<?> clazz)
Construct a bean wrapper around a class.
|
JuffrouBeanWrapper(Object instance)
Construct a bean wrapper around an existing bean instance.
This constructor will have to create a BeanWrapperContext to get introspection metadata. |
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.
|
BeanWrapperContext |
getContext() |
BeanWrapperFactory |
getFactory() |
Field |
getField(String propertyName)
Gets the type of a property in the wrapped bean.
|
JuffrouBeanWrapper |
getLocalNestedWrapper(String thisProperty)
Obtains the BeanWrapper that corresponds to the bean instance of this property type.
|
JuffrouBeanWrapper |
getNestedWrapper(String propertyName)
Obtains the JuffrouBeanWrapper corresponding to the bean referred by propertyName.
|
Map<String,JuffrouBeanWrapper> |
getNestedWrappers()
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. |
protected String |
getParentBeanProperty() |
protected JuffrouBeanWrapper |
getParentBeanWrapper() |
String[] |
getPropertyNames()
Get the names of all properties found in this bean and base ascending hierarchy
|
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 |
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. |
String |
toString()
Returns the string representation of the wrapped bean instance, or and empty string if the instance is null.
|
public JuffrouBeanWrapper(BeanWrapperContext context)
context
- metadata information about the class to instantiate the wrapped beanpublic JuffrouBeanWrapper(BeanWrapperContext context, Object instance)
context
- metadata and preferences information about the classinstance
- bean instancepublic JuffrouBeanWrapper(BeanWrapperContext context, JuffrouBeanWrapper parentBeanWrapper, String parentBeanProperty)
public JuffrouBeanWrapper(Object instance)
#BeanWrapper(BeanWrapperContext, Object)
instead.instance
- public JuffrouBeanWrapper(Class<?> clazz)
#BeanWrapper(BeanWrapperContext, Object)
instead.clazz
- class to instantiate the wrapped beanpublic BeanWrapperContext getContext()
public BeanWrapperFactory getFactory()
public 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,JuffrouBeanWrapper> getNestedWrappers()
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 String[] getPropertyNames()
public String toString()
toString
in class Object
Object.toString()
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 setpublic JuffrouBeanWrapper getNestedWrapper(String propertyName)
getNestedWrapper("prop1.prop2")
will ask the bean wrapper on prop1 to return the bean
wrapper of prop2. If the value of prop1 was originally null, it would also be set to reference the new bean
holding the value of prop2propertyName
- property name in this bean wrapper or inside a nested bean. It must be of bean type.#getLocalNestedWrapper(String)} to obtain a bean wrapper corresponding to a non nested property.
public JuffrouBeanWrapper getLocalNestedWrapper(String thisProperty)
thisProperty
- property name in this bean wrapper. The property type must be another bean and nested properties are
not allowed.#getNestedWrapper(String)} to obtain nested wrappers of nested wrappers.
protected JuffrouBeanWrapper getParentBeanWrapper()
protected String getParentBeanProperty()
Copyright © 2011-2013. All Rights Reserved.