com.atomikos.beans
Class PropertyUtils

java.lang.Object
  extended by com.atomikos.beans.PropertyUtils

public class PropertyUtils
extends Object

Smart reflection helper without the need for GUI classes (works on headless servers too).

Extracted from the BTM project and re-licensed under Apache 2.0 license.
© Bitronix 2005, 2006, 2007

Author:
lorban

Constructor Summary
PropertyUtils()
           
 
Method Summary
static Set getAllImplementedInterfaces(Class clazz)
          Gets all implemented interfaces of a class.
static Map getProperties(Object target)
          Builds a map of direct javabeans properties of the target object.
static Object getProperty(Object target, String propertyName)
          Gets a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object.
static void setProperties(Object target, Map properties)
          Sets a map of properties on the target object.
static void setProperty(Object target, String propertyName, Object propertyValue)
          Sets a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyUtils

public PropertyUtils()
Method Detail

getAllImplementedInterfaces

public static Set getAllImplementedInterfaces(Class clazz)
Gets all implemented interfaces of a class.


setProperty

public static void setProperty(Object target,
                               String propertyName,
                               Object propertyValue)
                        throws PropertyException
Sets a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object. This method tries to be smart in the way that intermediate properties currently set to null are set if it is possible to create and set an object. Conversions from propertyValue to the proper destination type are performed when possible.

Parameters:
target - the target object on which to set the property.
propertyName - the name of the property to set.
propertyValue - the value of the property to set.
Throws:
PropertyException - if an error happened while trying to set the property.

getProperties

public static Map getProperties(Object target)
                         throws PropertyException
Builds a map of direct javabeans properties of the target object. Only read/write properties (ie: those who have both a getter and a setter) are returned.

Parameters:
target - the target object from which to get properties names.
Returns:
a Map of String with properties names as key and their values
Throws:
PropertyException - if an error happened while trying to get a property.

getProperty

public static Object getProperty(Object target,
                                 String propertyName)
                          throws PropertyException
Gets a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object.

Parameters:
target - the target object from which to get the property.
propertyName - the name of the property to get.
Returns:
the value of the specified property.
Throws:
PropertyException - if an error happened while trying to get the property.

setProperties

public static void setProperties(Object target,
                                 Map properties)
                          throws PropertyException
Sets a map of properties on the target object.

Parameters:
target - the target object on which to set the properties.
properties - a map of String/Object pairs.
Throws:
PropertyException - if an error happened while trying to set a property.


Copyright © 2011. All Rights Reserved.