com.sibvisions.util.type
Class BeanUtil

java.lang.Object
  extended by com.sibvisions.util.type.BeanUtil

public final class BeanUtil
extends Object

Implements the EL notation for a generic access to object methods or members.


Method Summary
static Object get(Object pBean, String pPropertyName)
          Gets the property value from the given bean or sub bean.
static void set(Object pBean, String pPropertyName, Object pValue)
          Sets the property value to the given bean or sub bean.
static
<T> T[]
toArray(Object[] pSource, T[] pDest, String pPropertyName)
          Returns an array containing all of the properties identified by pPropertyName from pSource in proper sequence.
static Hashtable<Object,Object> toHashtable(List<?> pObjects, String pKey, String pValue)
          Returns a hashtable with a specific property as key and a specific property as value.
static
<T> List<T>
toList(Object[] pSource, String pPropertyName)
          Returns a list containing all of the properties identified by pPropertyName from pSource in proper sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static Object get(Object pBean,
                         String pPropertyName)
Gets the property value from the given bean or sub bean. It can be an IBean, than get(String pPropertyName) is called, a POJO or an EJB. With a special dot notation is it possible to access properties from sub beans. An array or List access is possible with java like array notation. Object result = BeanUtil.get(bean, "orders[5].ordernumber"); If the property name is null, the bean is returned.

Parameters:
pBean - the bean.
pPropertyName - the property name.
Returns:
the value of the given property name.

set

public static void set(Object pBean,
                       String pPropertyName,
                       Object pValue)
Sets the property value to the given bean or sub bean. It can be an IBean, than set(String pPropertyName, Object pValue) is called, a POJO or an EJB. With a special dot notation is it possible to access properties from sub beans. An array or List access is possible with java like array notation. BeanUtil.set(bean, "orders[5].ordernumber", "4711");

Parameters:
pBean - the bean.
pPropertyName - the property name.
pValue - the value to set.

toArray

public static <T> T[] toArray(Object[] pSource,
                              T[] pDest,
                              String pPropertyName)
Returns an array containing all of the properties identified by pPropertyName from pSource in proper sequence. The runtime type of the returned array is that of the specified pDest array.

Type Parameters:
T - the type for the result array
Parameters:
pSource - the source object list
pDest - the result array
pPropertyName - the property name for getting the desired values
Returns:
an array with the size of pSource filled with values

toList

public static <T> List<T> toList(Object[] pSource,
                                 String pPropertyName)
Returns a list containing all of the properties identified by pPropertyName from pSource in proper sequence. The runtime type of the returned array is that of the specified pDest array.

Type Parameters:
T - the type for the result array
Parameters:
pSource - the source object list
pPropertyName - the property name for getting the desired values
Returns:
the list with the size of pSource filled with values

toHashtable

public static Hashtable<Object,Object> toHashtable(List<?> pObjects,
                                                   String pKey,
                                                   String pValue)
Returns a hashtable with a specific property as key and a specific property as value. If the key property is not unique then the last key overwrites all previous keys.

Parameters:
pObjects - a list of objects with properties for the hashtable
pKey - the key property name
pValue - the value property name
Returns:
the hashtable with key/value column mapping


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.