1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springmodules.validation.bean.rule.resolver;
18
19 import org.springmodules.validation.util.fel.Function;
20 import org.springmodules.validation.util.fel.FunctionExpressionParser;
21
22 /**
23 * Resolves error arguments based on valang expressions.
24 *
25 * @author Uri Boness
26 */
27 public class FunctionErrorArgumentsResolver implements ErrorArgumentsResolver {
28
29 private Function[] functions;
30
31 public FunctionErrorArgumentsResolver(Function[] functions) {
32 this.functions = functions;
33 }
34
35 public FunctionErrorArgumentsResolver(String[] expressions, FunctionExpressionParser functionExpressionParser) {
36 this(parseFunctionExpressions(expressions, functionExpressionParser));
37 }
38
39 /**
40 * Returns the error arguments that are resolved by the configured function expressions.
41 *
42 * @see org.springmodules.validation.bean.rule.resolver.ErrorArgumentsResolver#resolveArguments(Object)
43 */
44 public Object[] resolveArguments(Object obj) {
45 Object[] args = new Object[functions.length];
46 for (int i = 0; i < args.length; i++) {
47 args[i] = functions[i].evaluate(obj);
48 }
49 return args;
50 }
51
52
53
54 protected static Function[] parseFunctionExpressions(String[] expressions, FunctionExpressionParser parser) {
55 Function[] functions = new Function[expressions.length];
56 for (int i = 0; i < expressions.length; i++) {
57 functions[i] = parser.parse(expressions[i]);
58 }
59 return functions;
60 }
61
62 }