1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springmodules.validation.util.fel.parser;
18
19 import org.springframework.beans.BeanWrapperImpl;
20 import org.springmodules.validation.util.fel.FelEvaluationException;
21 import org.springmodules.validation.util.fel.Function;
22 import org.springmodules.validation.util.fel.FunctionExpressionParser;
23
24
25
26
27
28
29
30 public class PropertyPathFunctionExpressionParser implements FunctionExpressionParser {
31
32 public Function parse(String expression) {
33 return new PropertyPathFunction(expression);
34 }
35
36
37
38
39
40 protected class PropertyPathFunction implements Function {
41
42 private String propertyPath;
43
44 public PropertyPathFunction(String propertyPath) {
45 this.propertyPath = propertyPath;
46 }
47
48 public Object evaluate(Object argument) {
49 try {
50 return new BeanWrapperImpl(argument).getPropertyValue(propertyPath);
51 } catch (Throwable t) {
52 throw new FelEvaluationException("Could not evaluate path '" + propertyPath +
53 "' on bean '" + String.valueOf(argument) + "'", t);
54 }
55 }
56 }
57
58 }