View Javadoc

    1   /*
    2    * Copyright 2002-2006 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
    17  package org.apache.commons.jexl;
    18
    19
    20  /***
    21   * <p>
    22   * Represents a single JEXL expression.  This simple interface
    23   * provides access to the underlying expression through getExpression(),
    24   * and it provides hooks to add a pre- and post- expression resolver.
    25   * </p>
    26   *
    27   * <p>
    28   * An expression is different than a script - it is simply a reference of
    29   * an expression.
    30   * </p>
    31   *
    32   * @since 1.0
    33   * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
    34   * @version $Id: Expression.java 397092 2006-04-26 05:11:28Z dion $
    35   */
    36  public interface Expression {
    37      /***
    38       * Evaluates the expression with the variables contained in the
    39       * supplied {@link JexlContext}.
    40       *
    41       * @param context A JexlContext containing variables.
    42       * @return The result of this evaluation
    43       * @throws Exception on any error
    44       */
    45      Object evaluate(JexlContext context) throws Exception;
    46
    47      /***
    48       * Returns the JEXL expression this Expression was created with.
    49       *
    50       * @return The JEXL expression to be evaluated
    51       */
    52      String getExpression();
    53
    54      /***
    55       * Allows addition of a resolver to allow custom interdiction of
    56       * expression evaluation.
    57       *
    58       * @param resolver resolver to be called before Jexl expression evaluated
    59       */
    60      void addPreResolver(JexlExprResolver resolver);
    61
    62      /***
    63       * Allows addition of a resolver to allow custom interdiction of
    64       * expression evaluation.
    65       *
    66       * @param resolver resolver to be called if Jexl expression
    67       *  evaluated to null.
    68       */
    69      void addPostResolver(JexlExprResolver resolver);
    70  }