    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     * Evaluates the expression with the variables contained in the
    041     * supplied {@link JexlContext}.
    042     *
    043     * @param context A JexlContext containing variables.
    044     * @return The result of this evaluation
    045     * @throws JexlException on any error
    046     */
    047    Object evaluate(JexlContext context);
    048
    049    /**
    050     * Returns the source text of this expression.
    051     *
    052     * @return the source text
    053     */
    054    String getSourceText();
    055
    056    /**
    057     * Recreates the source text of this expression from the internal syntactic tree.
    058     *
    059     * @return the source text
    060     */
    061    String getParsedText();
    062
    063    /**
    064     * Creates a Callable from this expression.
    065     *
    066     * <p>This allows to submit it to an executor pool and provides support for asynchronous calls.</p>
    067     * <p>The interpreter will handle interruption/cancellation gracefully if needed.</p>
    068     *
    069     * @param context the context
    070     * @return the callable
    071     * @since 3.1
    072     */
    073    Callable<Object> callable(JexlContext context);
    074}