View Javadoc

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  
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   * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
33   * @version $Id: Expression.java,v 1.7 2004/08/23 13:53:34 dion Exp $
34   */
35  public interface Expression
36  {
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       */
44      Object evaluate(JexlContext context) throws Exception;
45  
46      /***
47       * Returns the JEXL expression this Expression was created with.
48       * 
49       * @return The JEXL expression to be evaluated
50       */
51      String getExpression();
52  
53      /***
54       *  allows addition of a resolver to allow custom interdiction of
55       *  expression evaluation
56       *
57       *  @param resolver resolver to be called before Jexl expression evaluated
58       */
59      void addPreResolver(JexlExprResolver resolver);
60  
61      /***
62       *  allows addition of a resolver to allow custom interdiction of
63       *  expression evaluation
64       *
65       *  @param resolver resolver to be called if Jexl expression evaluated to null
66       */
67      void addPostResolver(JexlExprResolver resolver);
68  }