org.xins.common
Class BeanUtils

java.lang.Object
  extended byorg.xins.common.BeanUtils

public class BeanUtils
extends Object

This class contains some utility methods that fills an object with values from another object.

Since:
XINS 1.5.0.
Version:
$Revision: 1.46 $ $Date: 2008/10/09 08:47:54 $
Author:
Anthony Goubard

Constructor Summary
BeanUtils()
           
 
Method Summary
static Object convert(Object origValue, Class destClass)
          Converts the source object to an object of another class.
static Map getParameters(Object source)
          Gets the values returned by the get methods of the given POJO and put the values in a Map.
static Map getParametersAsObject(Object source)
          This method is similar to getParameters(Object) except that objects using classes of org.xins.common.type.* packages will be translated into standard Java object java.* packages.
static Map getParametersAsString(Object source)
          Gets the values returned by the get methods of the given POJO, transform it to a String object and put the values in a Map.
static Object populate(Object source, Object destination)
          Get the values returned by the get methods of the source object and call the set method of the destination object for the same property.
static Object populate(Object source, Object destination, Properties propertiesMapping)
          Get the values returned by the get methods of the source object and call the set method of the destination object for the same property.
static Object setParameters(Map properties, Object destination)
          Puts the values of the Map in the destination object (POJO).
static Object xmlToObject(Element element, Object result)
          Fills the result object with of the content of the XML element object.
static Object xmlToObject(Element element, Object result, Map elementMapping, Map attributeMapping)
          Fills the result object with of the content of the XML element object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

populate

public static Object populate(Object source,
                              Object destination)
                       throws IllegalArgumentException
Get the values returned by the get methods of the source object and call the set method of the destination object for the same property. e.g. String getFirstName() value of the source object will be used to invoke setFirstName(String) of the destination object. If the no matching set method exists or the set method parameter is not the same type as the object returned by the get method, the property is ignored.

Parameters:
source - the source object to get the values from. Cannot be null.
destination - the destination object to put the values in. Cannot be null.
Returns:
the populated object, never null.
Throws:
IllegalArgumentException - if source == null || destination == null.

populate

public static Object populate(Object source,
                              Object destination,
                              Properties propertiesMapping)
                       throws IllegalArgumentException
Get the values returned by the get methods of the source object and call the set method of the destination object for the same property. e.g. String getFirstName() value of the source object will be used to invoke setFirstName(String) of the destination object. If the no matching set method exists or the set method parameter is not the same type as the object returned by the get method, the property is ignored.

Parameters:
source - the source object to get the values from. Cannot be null.
destination - the destination object to put the values in. Cannot be null.
propertiesMapping - the mapping between properties which does not have the same name.
Returns:
the populated object, never null.
Throws:
IllegalArgumentException - if source == null || destination == null.

convert

public static Object convert(Object origValue,
                             Class destClass)
Converts the source object to an object of another class.

Parameters:
origValue - the original value of the object to be converted, if needed. Cannot be null.
destClass - the destination class in which the object should be converted, cannot be null.
Returns:
the converted object or null if the object cannot be converted.
Since:
XINS 2.0.

xmlToObject

public static Object xmlToObject(Element element,
                                 Object result,
                                 Map elementMapping,
                                 Map attributeMapping)
Fills the result object with of the content of the XML element object.

Parameters:
element - the XML element object, can be null.
result - the object to put the values in, cannot be null.
elementMapping - a Map<String, String> that maps the name of the source element to the name of the destination object, can be null.
attributeMapping - a Map<String, String> that maps the attributes of the elements, can be null.
Returns:
the result object filled with the values of the element object, never null.
Since:
XINS 2.0.

xmlToObject

public static Object xmlToObject(Element element,
                                 Object result)
Fills the result object with of the content of the XML element object.

Parameters:
element - the XML element object, can be null.
result - the object to put the values in, cannot be null.
Returns:
the result object filled with the values of the element object, never null.

getParameters

public static Map getParameters(Object source)
                         throws IllegalArgumentException
Gets the values returned by the get methods of the given POJO and put the values in a Map. The property names returned start with a lowercase.

Parameters:
source - the object from which the values are extracted and put in the Map, should not be null
Returns:
the property values of the source object. The key of the Map is the name of the property and the value is the value as returned by the get method. Never null.
Throws:
IllegalArgumentException - if source == null.
Since:
XINS 2.0.

getParametersAsString

public static Map getParametersAsString(Object source)
                                 throws IllegalArgumentException
Gets the values returned by the get methods of the given POJO, transform it to a String object and put the values in a Map. The property names returned start with a lowercase.

Parameters:
source - the object from which the values are extracted and put in the Map, should not be null
Returns:
the property values of the source object. The key of the Map is the name of the property and the value is the String representation of the value as returned by the get method. Never null.
Throws:
IllegalArgumentException - if source == null.
Since:
XINS 2.0.

getParametersAsObject

public static Map getParametersAsObject(Object source)
                                 throws IllegalArgumentException
This method is similar to getParameters(Object) except that objects using classes of org.xins.common.type.* packages will be translated into standard Java object java.* packages.

Parameters:
source - the object from which the values are extracted and put in the Map, should not be null
Returns:
the property values of the source object. The key of the Map is the name of the property and the value is a standard Java object representation of the value as returned by the get method. Never null.
Throws:
IllegalArgumentException - if source == null.
Since:
XINS 2.0.

setParameters

public static Object setParameters(Map properties,
                                   Object destination)
                            throws IllegalArgumentException
Puts the values of the Map in the destination object (POJO). If needed the property value is converted to the type needed for the set method. The property names can start with an uppercase or a lowercase.

Parameters:
properties - the map containing the values to fill the destination object, cannot be null The key of the Map should be the property name and will be used to find the set method of the destination object.
destination - the object which should be filled, cannot be null.
Returns:
the destination object filled, never null. This object will be the same as the input parameter.
Throws:
IllegalArgumentException - if properties == null || destination == null.
Since:
XINS 2.0.


See http://www.xins.org/.