org.apache.wicket.core.util.lang
Class PropertyResolver

java.lang.Object
  extended by org.apache.wicket.core.util.lang.PropertyResolver

public final class PropertyResolver
extends Object

NOTE: THIS CLASS IS NOT PART OF THE WICKET PUBLIC API, DO NOT USE IT UNLESS YOU KNOW WHAT YOU ARE DOING.

This class parses expressions to lookup or set a value on the object that is given.
The supported expressions are:

"property": This could be a bean property with get and set method. Or if a map is given as an object it will be lookup with the property as a key when there is not get method for that property.

"property1.property2": Both properties are looked up as described above. If property1 evaluates to null then if there is a setMethod (or if it is a map) and the Class of the property has a default constructor then the object will be constructed and set on the object.

"property.index": If the property is a List or Array then the second property can be a index on that list like: 'mylist.0' this expression will also map on a getProperty(index) or setProperty(index,value) methods. If the object is a List then the list will grow automatically if the index is greater than the size

Index or map properties can also be written as: "property[index]" or "property[key]"

Note that the property resolver by default provides access to private members and methods. If guaranteeing encapsulation of the target objects is a big concern, you should consider using an alternative implementation.

Note: If a property evaluates to an instance of IModel then the expression should use '.object' to work with its value.

Author:
jcompagner

Nested Class Summary
static interface PropertyResolver.IClassCache
          An implementation of the class can be set on the setClassCache(org.apache.wicket.Application, org.apache.wicket.core.util.lang.PropertyResolver.IClassCache) method for a specific application.
static interface PropertyResolver.IGetAndSet
           
 
Method Summary
static void destroy(Application application)
          Clean up cache for this app.
static
<T> Class<T>
getPropertyClass(String expression, Class<?> clz)
           
static Class<?> getPropertyClass(String expression, Object object)
           
static Field getPropertyField(String expression, Object object)
           
static Method getPropertyGetter(String expression, Object object)
           
static Method getPropertySetter(String expression, Object object)
           
static Object getValue(String expression, Object object)
          Looks up the value from the object with the given expression.
static void setClassCache(Application application, PropertyResolver.IClassCache classCache)
          Sets the PropertyResolver.IClassCache for the given application.
static void setValue(String expression, Object object, Object value, PropertyResolverConverter converter)
          Set the value on the object with the given expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getValue

public static final Object getValue(String expression,
                                    Object object)
Looks up the value from the object with the given expression. If the expression, the object itself or one property evaluates to null then a null will be returned.

Parameters:
expression - The expression string with the property to be lookup.
object - The object which is evaluated.
Returns:
The value that is evaluated. Null something in the expression evaluated to null.

setValue

public static final void setValue(String expression,
                                  Object object,
                                  Object value,
                                  PropertyResolverConverter converter)
Set the value on the object with the given expression. If the expression can't be evaluated then a WicketRuntimeException will be thrown. If a null object is encountered then it will try to generate it by calling the default constructor and set it on the object. The value will be tried to convert to the right type with the given converter.

Parameters:
expression - The expression string with the property to be set.
object - The object which is evaluated to set the value on.
value - The value to set.
converter - The converter to convert the value if needed to the right type.
Throws:
WicketRuntimeException

getPropertyClass

public static final Class<?> getPropertyClass(String expression,
                                              Object object)
Parameters:
expression -
object -
Returns:
class of the target property object
Throws:
WicketRuntimeException - if the cannot be resolved

getPropertyClass

public static <T> Class<T> getPropertyClass(String expression,
                                            Class<?> clz)
Type Parameters:
T -
Parameters:
expression -
clz -
Returns:
class of the target Class property expression
Throws:
WicketRuntimeException - if class cannot be resolved

getPropertyField

public static final Field getPropertyField(String expression,
                                           Object object)
Parameters:
expression -
object -
Returns:
Field for the property expression
Throws:
WicketRuntimeException - if there is no such field

getPropertyGetter

public static final Method getPropertyGetter(String expression,
                                             Object object)
Parameters:
expression -
object -
Returns:
Getter method for the property expression
Throws:
WicketRuntimeException - if there is no getter method

getPropertySetter

public static final Method getPropertySetter(String expression,
                                             Object object)
Parameters:
expression -
object -
Returns:
Setter method for the property expression
Throws:
WicketRuntimeException - if there is no setter method

destroy

public static void destroy(Application application)
Clean up cache for this app.

Parameters:
application -

setClassCache

public static void setClassCache(Application application,
                                 PropertyResolver.IClassCache classCache)
Sets the PropertyResolver.IClassCache for the given application. If the Application is null then it will be the default if no application is found. So if you want to be sure that your PropertyResolver.IClassCache is handled in all situations then call this method twice with your implementations. One time for the application and the second time with null.

Parameters:
application - to use or null if the default must be set.
classCache -


Copyright © 2006–2015 Apache Software Foundation. All rights reserved.