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 protected boolean noValOnNull = true; 24 25 /*** 26 * default CTOR 27 */ 28 public FlatResolver() 29 { 30 } 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 public FlatResolver(boolean noValOnNull) 37 { 38 this.noValOnNull = noValOnNull; 39 } 40 41 public Object evaluate(JexlContext context, String expression) 42 { 43 Object val = context.getVars().get(expression); 44 45 if (val == null && noValOnNull) 46 { 47 return JexlExprResolver.NO_VALUE; 48 } 49 50 return val; 51 } 52 }