org.araneaframework.backend.util
Class BeanMapper

java.lang.Object
  extended byorg.araneaframework.backend.util.BeanMapper
All Implemented Interfaces:
Serializable

public class BeanMapper
extends Object
implements Serializable

This class provides a way to manipulate Bean fields. This class assumes that the class passed to constructor (BeanClass) implements the Bean pattern - that is to open it's fields using getters and setters (read-only fields are permitted). The only names permitted are those starting with "get", "is" and "set". Another requirement is that Beans must have a constructor that doesn't take any parameters.

Author:
Rein Raudjärv
See Also:
BeanUtil, Serialized Form

Constructor Summary
BeanMapper(Class beanClass)
          Initializes the BeanMapper.
BeanMapper(Class beanClass, boolean createMissingBeans)
          Initializes the BeanMapper.
 
Method Summary
 List getFields()
          Returns List<String>- the List of Bean field names.
 Class getFieldType(String fieldName)
          Returns type of Bean field identified by name field.
 Object getFieldValue(Object bean, String fieldName)
          Returns the value of Bean field identified with name field for object bean
 boolean isReadable(String fieldName)
          Checks that the field identified by fieldName is a readable Bean field.
 boolean isWritable(String fieldName)
          Checks that the field identified by fieldName is a writable Bean field.
 void setFieldValue(Object bean, String fieldName, Object value)
          Sets the value of Bean field identified by name field for object bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanMapper

public BeanMapper(Class beanClass)
Initializes the BeanMapper.

Parameters:
beanClass - the class implementing the Bean pattern.

BeanMapper

public BeanMapper(Class beanClass,
                  boolean createMissingBeans)
Initializes the BeanMapper.

Parameters:
beanClass - the class implementing the Bean pattern.
createMissingBeans - whetther to create missing beans during writing bean subfields (default is false).
Method Detail

getFields

public List getFields()
Returns List<String>- the List of Bean field names.

Returns:
List<String>- the List of Bean field names.

getFieldValue

public Object getFieldValue(Object bean,
                            String fieldName)
Returns the value of Bean field identified with name field for object bean

Parameters:
bean - Object, which value to return.
fieldName - The name of Bean field.
Returns:
The value of the field.

setFieldValue

public void setFieldValue(Object bean,
                          String fieldName,
                          Object value)
Sets the value of Bean field identified by name field for object bean.

Parameters:
bean - bean Object, which value to set.
fieldName - The name of Bean field.
value - The new value of the field.

getFieldType

public Class getFieldType(String fieldName)
Returns type of Bean field identified by name field.

Parameters:
fieldName - The name of Bean field.
Returns:
The type of the field.

isReadable

public boolean isReadable(String fieldName)
Checks that the field identified by fieldName is a readable Bean field.

Parameters:
fieldName - Bean field name.
Returns:
if this field is in Bean.

isWritable

public boolean isWritable(String fieldName)
Checks that the field identified by fieldName is a writable Bean field.

Parameters:
fieldName - Bean field name.
Returns:
if this field is in Bean.