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