| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jexl.resolver.FlatResolver |
|
|
| 1 | package org.apache.commons.jexl.resolver; |
|
| 2 | ||
| 3 | import org.apache.commons.jexl.JexlExprResolver; |
|
| 4 | import org.apache.commons.jexl.JexlContext; |
|
| 5 | ||
| 6 | /** |
|
| 7 | * Simple resolver to try the expression as-is from the context. |
|
| 8 | * |
|
| 9 | * For example, you could resolve ant-ish properties (foo.bar.woogie) |
|
| 10 | * using this... |
|
| 11 | * |
|
| 12 | * hint, hint... |
|
| 13 | * |
|
| 14 | * @author <a href="mailto:geirm@adeptra.com">Geir Magnusson Jr.</a> |
|
| 15 | * @version $Id: FlatResolver.java,v 1.1 2002/06/13 16:10:44 geirm Exp $ |
|
| 16 | */ |
|
| 17 | public class FlatResolver implements JexlExprResolver |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * flag to return NO_VALUE on null from context |
|
| 21 | * this allows jexl to try to evaluate |
|
| 22 | */ |
|
| 23 | 54 | protected boolean noValOnNull = true; |
| 24 | ||
| 25 | /** |
|
| 26 | * default CTOR |
|
| 27 | */ |
|
| 28 | 2 | public FlatResolver() |
| 29 | 37 | { |
| 30 | 39 | } |
| 31 | ||
| 32 | /** |
|
| 33 | * CTOR that lets you override the default behavior of |
|
| 34 | * noValOnNull, which is true (jexl gets a shot after if null) |
|
| 35 | */ |
|
| 36 | 1 | public FlatResolver(boolean noValOnNull) |
| 37 | 14 | { |
| 38 | 15 | this.noValOnNull = noValOnNull; |
| 39 | 15 | } |
| 40 | ||
| 41 | public Object evaluate(JexlContext context, String expression) |
|
| 42 | { |
|
| 43 | 54 | Object val = context.getVars().get(expression); |
| 44 | ||
| 45 | 54 | if (val == null && noValOnNull) |
| 46 | { |
|
| 47 | 15 | return JexlExprResolver.NO_VALUE; |
| 48 | } |
|
| 49 | ||
| 50 | 39 | return val; |
| 51 | } |
|
| 52 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |