001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.expression;
018
019import java.util.List;
020
021/**
022 * Expressions are executed in an evaluation context. It is in this context that
023 * references are resolved when encountered during expression evaluation.
024 *
025 * <p>There is a default implementation of this EvaluationContext interface:
026 * {@link org.springframework.expression.spel.support.StandardEvaluationContext}
027 * which can be extended, rather than having to implement everything manually.
028 *
029 * @author Andy Clement
030 * @author Juergen Hoeller
031 * @since 3.0
032 */
033public interface EvaluationContext {
034
035        /**
036         * Return the default root context object against which unqualified
037         * properties/methods/etc should be resolved. This can be overridden
038         * when evaluating an expression.
039         */
040        TypedValue getRootObject();
041
042        /**
043         * Return a list of accessors that will be asked in turn to read/write a property.
044         */
045        List<PropertyAccessor> getPropertyAccessors();
046
047        /**
048         * Return a list of resolvers that will be asked in turn to locate a constructor.
049         */
050        List<ConstructorResolver> getConstructorResolvers();
051
052        /**
053         * Return a list of resolvers that will be asked in turn to locate a method.
054         */
055        List<MethodResolver> getMethodResolvers();
056
057        /**
058         * Return a bean resolver that can look up beans by name.
059         */
060        BeanResolver getBeanResolver();
061
062        /**
063         * Return a type locator that can be used to find types, either by short or
064         * fully qualified name.
065         */
066        TypeLocator getTypeLocator();
067
068        /**
069         * Return a type converter that can convert (or coerce) a value from one type to another.
070         */
071        TypeConverter getTypeConverter();
072
073        /**
074         * Return a type comparator for comparing pairs of objects for equality.
075         */
076        TypeComparator getTypeComparator();
077
078        /**
079         * Return an operator overloader that may support mathematical operations
080         * between more than the standard set of types.
081         */
082        OperatorOverloader getOperatorOverloader();
083
084        /**
085         * Set a named variable within this evaluation context to a specified value.
086         * @param name variable to set
087         * @param value value to be placed in the variable
088         */
089        void setVariable(String name, Object value);
090
091        /**
092         * Look up a named variable within this evaluation context.
093         * @param name variable to lookup
094         * @return the value of the variable, or {@code null} if not found
095         */
096        Object lookupVariable(String name);
097
098}