1. /*
  2. * Copyright 2002,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.jexl;
  17. /**
  18. * <p>
  19. * Represents a single JEXL expression. This simple interface
  20. * provides access to the underlying expression through getExpression(),
  21. * and it provides hooks to add a pre- and post- expression resolver.
  22. * </p>
  23. *
  24. * <p>
  25. * An expression is different than a script - it is simply a reference of
  26. * an expression.
  27. * </p>
  28. *
  29. * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
  30. * @version $Id: Expression.java,v 1.7 2004/08/23 13:53:34 dion Exp $
  31. */
  32. public interface Expression
  33. {
  34. /**
  35. * Evaluates the expression with the variables contained in the
  36. * supplied {@link JexlContext}.
  37. *
  38. * @param context A JexlContext containing variables.
  39. * @return The result of this evaluation
  40. */
  41. Object evaluate(JexlContext context) throws Exception;
  42. /**
  43. * Returns the JEXL expression this Expression was created with.
  44. *
  45. * @return The JEXL expression to be evaluated
  46. */
  47. String getExpression();
  48. /**
  49. * allows addition of a resolver to allow custom interdiction of
  50. * expression evaluation
  51. *
  52. * @param resolver resolver to be called before Jexl expression evaluated
  53. */
  54. void addPreResolver(JexlExprResolver resolver);
  55. /**
  56. * allows addition of a resolver to allow custom interdiction of
  57. * expression evaluation
  58. *
  59. * @param resolver resolver to be called if Jexl expression evaluated to null
  60. */
  61. void addPostResolver(JexlExprResolver resolver);
  62. }