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
021import org.springframework.lang.Nullable;
022
023/**
024 * Expressions are executed in an evaluation context. It is in this context that
025 * references are resolved when encountered during expression evaluation.
026 *
027 * <p>There is a default implementation of this EvaluationContext interface:
028 * {@link org.springframework.expression.spel.support.StandardEvaluationContext}
029 * which can be extended, rather than having to implement everything manually.
030 *
031 * @author Andy Clement
032 * @author Juergen Hoeller
033 * @since 3.0
034 */
035public interface EvaluationContext {
036
037        /**
038         * Return the default root context object against which unqualified
039         * properties/methods/etc should be resolved. This can be overridden
040         * when evaluating an expression.
041         */
042        TypedValue getRootObject();
043
044        /**
045         * Return a list of accessors that will be asked in turn to read/write a property.
046         */
047        List<PropertyAccessor> getPropertyAccessors();
048
049        /**
050         * Return a list of resolvers that will be asked in turn to locate a constructor.
051         */
052        List<ConstructorResolver> getConstructorResolvers();
053
054        /**
055         * Return a list of resolvers that will be asked in turn to locate a method.
056         */
057        List<MethodResolver> getMethodResolvers();
058
059        /**
060         * Return a bean resolver that can look up beans by name.
061         */
062        @Nullable
063        BeanResolver getBeanResolver();
064
065        /**
066         * Return a type locator that can be used to find types, either by short or
067         * fully qualified name.
068         */
069        TypeLocator getTypeLocator();
070
071        /**
072         * Return a type converter that can convert (or coerce) a value from one type to another.
073         */
074        TypeConverter getTypeConverter();
075
076        /**
077         * Return a type comparator for comparing pairs of objects for equality.
078         */
079        TypeComparator getTypeComparator();
080
081        /**
082         * Return an operator overloader that may support mathematical operations
083         * between more than the standard set of types.
084         */
085        OperatorOverloader getOperatorOverloader();
086
087        /**
088         * Set a named variable within this evaluation context to a specified value.
089         * @param name the name of the variable to set
090         * @param value the value to be placed in the variable
091         */
092        void setVariable(String name, @Nullable Object value);
093
094        /**
095         * Look up a named variable within this evaluation context.
096         * @param name variable to lookup
097         * @return the value of the variable, or {@code null} if not found
098         */
099        @Nullable
100        Object lookupVariable(String name);
101
102}