Source code
Description: source: package: org.apache.commons.jexl3, interface: JexlExpression

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