net.sf.click.util
Class PropertyUtils

java.lang.Object
  extended bynet.sf.click.util.PropertyUtils

public class PropertyUtils
extends Object

Provide property getter and setter utility methods.

Author:
Malcolm Edgar

Constructor Summary
PropertyUtils()
           
 
Method Summary
static Object getValue(Object source, String name)
          Return the property value for the given object and property name.
static Object getValue(Object source, String name, Map cache)
          Return the property value for the given object and property name.
static Object getValueOgnl(Object source, String name, Map context)
          Return the property value for the given object and property name using the OGNL library.
static void setValueOgnl(Object target, String name, Object value, Map context)
          Return the property value for the given object and property name using the OGNL library.
 
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

getValue

public static Object getValue(Object source,
                              String name)
Return the property value for the given object and property name. This method uses reflection internally to get the property value.

This method is thread-safe, and caches reflected accessor methods in an internal synchronized cache.

If the given source object is a Map this method will simply return the value for the given key name.

Parameters:
source - the source object
name - the name of the property
Returns:
the property value for the given source object and property name

getValue

public static Object getValue(Object source,
                              String name,
                              Map cache)
Return the property value for the given object and property name. This method uses reflection internally to get the property value.

This method caches the reflected property methods in the given Map cache. You must NOT modify the cache. Also note cache is ONLY valid for the current thread, as access to the cache is not synchronized. If you need multi-threaded access to shared cache use a thread-safe Map object, such as Collections.synchronizedMap(new HashMap()).

If the given source object is a Map this method will simply return the value for the given key name.

Parameters:
source - the source object
name - the name of the property
cache - the cache of reflected property Method objects, do NOT modify this cache
Returns:
the property value for the given source object and property name

getValueOgnl

public static Object getValueOgnl(Object source,
                                  String name,
                                  Map context)
                           throws ognl.OgnlException
Return the property value for the given object and property name using the OGNL library.

This method is thread-safe, and caches parsed OGNL expressions in an internal synchronized cache.

Parameters:
source - the source object
name - the name of the property
context - the OGNL context, do NOT modify this object
Returns:
the property value for the given source object and property name
Throws:
ognl.OgnlException - if an OGN error occurs

setValueOgnl

public static void setValueOgnl(Object target,
                                String name,
                                Object value,
                                Map context)
                         throws ognl.OgnlException
Return the property value for the given object and property name using the OGNL library.

This method is thread-safe, and caches parsed OGNL expressions in an internal synchronized cache.

Parameters:
target - the target object to set the property of
name - the name of the property to set
value - the property value to set
context - the OGNL context, do NOT modify this object
Throws:
ognl.OgnlException - if an OGN error occurs