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 * https://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 /**
41 * Creates a Callable from this expression.
42 *
43 * <p>This allows to submit it to an executor pool and provides support for asynchronous calls.</p>
44 * <p>The interpreter will handle interruption/cancellation gracefully if needed.</p>
45 *
46 * @param context the context
47 * @return the callable
48 * @since 3.1
49 */
50 Callable<Object> callable(JexlContext context);
51
52 /**
53 * Evaluates the expression with the variables contained in the
54 * supplied {@link JexlContext}.
55 *
56 * @param context A JexlContext containing variables.
57 * @return The result of this evaluation
58 * @throws JexlException on any error
59 */
60 Object evaluate(JexlContext context);
61
62 /**
63 * Recreates the source text of this expression from the internal syntactic tree.
64 *
65 * @return the source text
66 */
67 String getParsedText();
68
69 /**
70 * Returns the source text of this expression.
71 *
72 * @return the source text
73 */
74 String getSourceText();
75 }