org.apache.commons.beanutils.expression
Interface Resolver
- DefaultResolver
public interface Resolver
Property Name Expression Resolver.
Methods such as PropertyUtilsBean's
setNestedProperty()
method
use a
Resolver
to process a
property name
expression and resolve
nested,
indexed and
mapped
property names. The following code provides an example usage
demonstrating all the methods:
// Iterate through a nested property expression
while (resolver.hasNested(name)) {
// isolate a single property from a nested expresion
String next = resolver.next(name);
// Process...
String property = resolver.getProperty(next);
if (resolver.isIndexed(next)) {
int index = resolver.getIndex(next);
bean = getIndexedProperty(bean, property, index);
} else if (resolver.isMapped(next)) {
String key = resolver.getKey(next);
bean = getMappedProperty(bean, property, key);
} else {
bean = getSimpleProperty(bean, property);
}
// remove the processed property from the expression
name = resolver.remove(name);
}
In order to create an implementation, it is important to understand how
BeanUtils/PropertyUtils uses the
resolver
. The following are
the main methods that use it:
PropertyUtilsBean.getIndexedProperty(Object,String)
PropertyUtilsBean.getMappedProperty(Object,String)
PropertyUtilsBean.getNestedProperty(Object,String)
PropertyUtilsBean.getPropertyDescriptor(Object,String)
PropertyUtilsBean.getSimpleProperty(Object,String)
PropertyUtilsBean.setIndexedProperty(Object,String,Object)
PropertyUtilsBean.setMappedProperty(Object,String,Object)
PropertyUtilsBean.setNestedProperty(Object,String,Object)
PropertyUtilsBean.setSimpleProperty(Object,String,Object)
BeanUtilsBean
LocaleBeanUtilsBean
$Revision: 555845 $ $Date: 2007-07-13 03:52:05 +0100 (Fri, 13 Jul 2007) $ int | getIndex(String expression) - Extract the index value from the property expression or -1.
|
String | getKey(String expression) - Extract the map key from the property expression or
null .
|
String | getProperty(String expression) - Return the property name from the property expression.
|
boolean | hasNested(String expression) - Indicates whether or not the expression
contains nested property expressions or not.
|
boolean | isIndexed(String expression) - Indicate whether the expression is for an indexed property or not.
|
boolean | isMapped(String expression) - Indicate whether the expression is for a mapped property or not.
|
String | next(String expression) - Extract the next property expression from the
current expression.
|
String | remove(String expression) - Remove the last property expresson from the
current expression.
|
getIndex
public int getIndex(String expression)
Extract the index value from the property expression or -1.
expression
- The property expression
- The index value or -1 if the property is not indexed
getKey
public String getKey(String expression)
Extract the map key from the property expression or null
.
expression
- The property expression
getProperty
public String getProperty(String expression)
Return the property name from the property expression.
expression
- The property expression
hasNested
public boolean hasNested(String expression)
Indicates whether or not the expression
contains nested property expressions or not.
expression
- The property expression
- The next property expression
isIndexed
public boolean isIndexed(String expression)
Indicate whether the expression is for an indexed property or not.
expression
- The property expression
true
if the expresion is indexed,
otherwise false
isMapped
public boolean isMapped(String expression)
Indicate whether the expression is for a mapped property or not.
expression
- The property expression
true
if the expresion is mapped,
otherwise false
next
public String next(String expression)
Extract the next property expression from the
current expression.
expression
- The property expression
- The next property expression
remove
public String remove(String expression)
Remove the last property expresson from the
current expression.
expression
- The property expression
- The new expression value, with first property
expression removed - null if there are no more expressions
Copyright (c) 2001-2007 - Apache Software Foundation