View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.jexl3;
19  
20  import java.util.concurrent.Callable;
21  
22  /**
23   * Represents a single JEXL expression.
24   * <p>
25   * This simple interface provides access to the underlying textual expression through
26   * {@link JexlExpression#getSourceText()}.
27   * </p>
28   *
29   * <p>
30   * An expression is different than a script - it is simply a reference to
31   * a single expression, not to multiple statements.
32   * This implies 'if','for','while','var' and blocks '{'... '}'are <em>not</em> allowed in expressions.
33   * </p>
34   * <p>Do <em>not</em> create classes that implement this interface; delegate or compose instead.</p>
35   *
36   * @since 1.0
37   */
38  public interface JexlExpression {
39      /**
40       * Evaluates the expression with the variables contained in the
41       * supplied {@link JexlContext}.
42       *
43       * @param context A JexlContext containing variables.
44       * @return The result of this evaluation
45       * @throws JexlException on any error
46       */
47      Object evaluate(JexlContext context);
48  
49      /**
50       * Returns the source text of this expression.
51       *
52       * @return the source text
53       */
54      String getSourceText();
55  
56      /**
57       * Recreates the source text of this expression from the internal syntactic tree.
58       *
59       * @return the source text
60       */
61      String getParsedText();
62  
63      /**
64       * Creates a Callable from this expression.
65       *
66       * <p>This allows to submit it to an executor pool and provides support for asynchronous calls.</p>
67       * <p>The interpreter will handle interruption/cancellation gracefully if needed.</p>
68       *
69       * @param context the context
70       * @return the callable
71       * @since 3.1
72       */
73      Callable<Object> callable(JexlContext context);
74  }