public final class PropertyResolver extends Object
This class parses expressions to lookup or set a value on the object that is given.
The supported expressions are:
"property": This can can then 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 lookup as written 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 then 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.
Modifier and Type | Class and Description |
---|---|
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 |
Modifier and Type | Method and Description |
---|---|
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.
|
public static Object getValue(String expression, Object object)
expression
- The expression string with the property to be lookup.object
- The object which is evaluated.public static void setValue(String expression, Object object, Object value, PropertyResolverConverter converter)
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.WicketRuntimeException
public static Class<?> getPropertyClass(String expression, Object object)
expression
- object
- WicketRuntimeException
- if the cannot be resolvedpublic static <T> Class<T> getPropertyClass(String expression, Class<?> clz)
T
- expression
- clz
- WicketRuntimeException
- if class cannot be resolvedpublic static Field getPropertyField(String expression, Object object)
expression
- object
- WicketRuntimeException
- if there is no such fieldpublic static Method getPropertyGetter(String expression, Object object)
expression
- object
- WicketRuntimeException
- if there is no getter methodpublic static Method getPropertySetter(String expression, Object object)
expression
- object
- WicketRuntimeException
- if there is no setter methodpublic static void destroy(Application application)
application
- public static void setClassCache(Application application, PropertyResolver.IClassCache classCache)
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.application
- to use or null if the default must be set.classCache
- Copyright © 2006–2014 Apache Software Foundation. All rights reserved.