001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.jexl3;
019
020import java.util.concurrent.Callable;
021
022/**
023 * Represents a single JEXL expression.
024 * <p>
025 * This simple interface provides access to the underlying textual expression through
026 * {@link JexlExpression#getSourceText()}.
027 * </p>
028 *
029 * <p>
030 * An expression is different than a script - it is simply a reference to
031 * a single expression, not to multiple statements.
032 * This implies 'if','for','while','var' and blocks '{'... '}'are <em>not</em> allowed in expressions.
033 * </p>
034 * <p>Do <em>not</em> create classes that implement this interface; delegate or compose instead.</p>
035 *
036 * @since 1.0
037 */
038public interface JexlExpression {
039    /**
040     * Creates a Callable from this expression.
041     *
042     * <p>This allows to submit it to an executor pool and provides support for asynchronous calls.</p>
043     * <p>The interpreter will handle interruption/cancellation gracefully if needed.</p>
044     *
045     * @param context the context
046     * @return the callable
047     * @since 3.1
048     */
049    Callable<Object> callable(JexlContext context);
050
051    /**
052     * Evaluates the expression with the variables contained in the
053     * supplied {@link JexlContext}.
054     *
055     * @param context A JexlContext containing variables.
056     * @return The result of this evaluation
057     * @throws JexlException on any error
058     */
059    Object evaluate(JexlContext context);
060
061    /**
062     * Recreates the source text of this expression from the internal syntactic tree.
063     *
064     * @return the source text
065     */
066    String getParsedText();
067
068    /**
069     * Returns the source text of this expression.
070     *
071     * @return the source text
072     */
073    String getSourceText();
074}