|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
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
BeanUtilsBean.copyProperty(Object, String, Object)
BeanUtilsBean.setProperty(Object, String, Object)
LocaleBeanUtilsBean
PropertyUtilsBean.setResolver(Resolver)
Method Summary | |
int |
getIndex(java.lang.String expression)
Extract the index value from the property expression or -1. |
java.lang.String |
getKey(java.lang.String expression)
Extract the map key from the property expression or null . |
java.lang.String |
getProperty(java.lang.String expression)
Return the property name from the property expression. |
boolean |
hasNested(java.lang.String expression)
Indicates whether or not the expression contains nested property expressions or not. |
boolean |
isIndexed(java.lang.String expression)
Indicate whether the expression is for an indexed property or not. |
boolean |
isMapped(java.lang.String expression)
Indicate whether the expression is for a mapped property or not. |
java.lang.String |
next(java.lang.String expression)
Extract the next property expression from the current expression. |
java.lang.String |
remove(java.lang.String expression)
Remove the last property expresson from the current expression. |
Method Detail |
public int getIndex(java.lang.String expression)
expression
- The property expressionjava.lang.IllegalArgumentException
- If the indexed property is illegally
formed or has an invalid (non-numeric) valuepublic java.lang.String getKey(java.lang.String expression)
null
.expression
- The property expressionjava.lang.IllegalArgumentException
- If the mapped property is illegally formedpublic java.lang.String getProperty(java.lang.String expression)
expression
- The property expressionpublic boolean hasNested(java.lang.String expression)
expression
- The property expressionpublic boolean isIndexed(java.lang.String expression)
expression
- The property expressiontrue
if the expresion is indexed,
otherwise false
public boolean isMapped(java.lang.String expression)
expression
- The property expressiontrue
if the expresion is mapped,
otherwise false
public java.lang.String next(java.lang.String expression)
expression
- The property expressionpublic java.lang.String remove(java.lang.String expression)
expression
- The property expression
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |