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