1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jexl.resolver;
17
18 import org.apache.commons.jexl.JexlExprResolver;
19 import org.apache.commons.jexl.JexlContext;
20
21 /***
22 * Simple resolver to try the expression as-is from the context.
23 *
24 * For example, you could resolve ant-ish properties (foo.bar.woogie)
25 * using this...
26 *
27 * hint, hint...
28 *
29 * @since 1.0
30 * @author <a href="mailto:geirm@adeptra.com">Geir Magnusson Jr.</a>
31 * @version $Id: FlatResolver.java 397542 2006-04-27 13:43:47Z dion $
32 */
33 public class FlatResolver implements JexlExprResolver {
34 /***
35 * Flag to return NO_VALUE on null from context.
36 * this allows jexl to try to evaluate
37 */
38 protected boolean noValOnNull = true;
39
40 /***
41 * Default CTOR.
42 */
43 public FlatResolver() {
44 }
45
46 /***
47 * CTOR that lets you override the default behavior of
48 * noValOnNull, which is true. (jexl gets a shot after if null)
49 *
50 * @param valOnNull Whether NO_VALUE will be returned instead of null.
51 */
52 public FlatResolver(boolean valOnNull) {
53 noValOnNull = valOnNull;
54 }
55
56 /***
57 * Try to resolve expression as-is.
58 *
59 * @param context The context for resolution.
60 * @param expression The flat expression.
61 * @return The resolved value.
62 */
63 public Object evaluate(JexlContext context, String expression) {
64 Object val = context.getVars().get(expression);
65
66 if (val == null && noValOnNull) {
67 return JexlExprResolver.NO_VALUE;
68 }
69
70 return val;
71 }
72 }