Class ExpressionState

java.lang.Object
org.springframework.expression.spel.ExpressionState

public class ExpressionState extends Object
ExpressionState is for maintaining per-expression-evaluation state: any changes to it are not seen by other expressions, but it gives a place to hold local variables and for component expressions in a compound expression to communicate state. This is in contrast to the EvaluationContext, which is shared amongst expression evaluations, and any changes to it will be seen by other expressions or any code that chooses to ask questions of the context.

It also acts as a place to define common utility routines that the various AST nodes might need.

Since:
3.0
Author:
Andy Clement, Juergen Hoeller, Sam Brannen
  • Constructor Details

  • Method Details

    • getActiveContextObject

      public TypedValue getActiveContextObject()
      The active context object is what unqualified references to properties/etc are resolved against.
    • pushActiveContextObject

      public void pushActiveContextObject(TypedValue obj)
    • popActiveContextObject

      public void popActiveContextObject()
    • getRootContextObject

      public TypedValue getRootContextObject()
    • getScopeRootContextObject

      public TypedValue getScopeRootContextObject()
    • assignVariable

      public TypedValue assignVariable(String name, Supplier<TypedValue> valueSupplier)
      Assign the value created by the specified Supplier to a named variable within the evaluation context.

      In contrast to setVariable(String, Object), this method should only be invoked to support assignment within an expression.

      Parameters:
      name - the name of the variable to assign
      valueSupplier - the supplier of the value to be assigned to the variable
      Returns:
      a TypedValue wrapping the assigned value
      Since:
      5.2.24
      See Also:
    • setVariable

      public void setVariable(String name, @Nullable Object value)
      Set a named variable in the evaluation context to a specified value.

      In contrast to assignVariable(String, Supplier), this method should only be invoked programmatically.

      Parameters:
      name - the name of the variable to set
      value - the value to be placed in the variable
      See Also:
    • lookupVariable

      public TypedValue lookupVariable(String name)
      Look up a named global variable in the evaluation context.
      Parameters:
      name - the name of the variable to look up
      Returns:
      a TypedValue containing the value of the variable, or TypedValue.NULL if the variable does not exist
      See Also:
    • getTypeComparator

      public TypeComparator getTypeComparator()
    • findType

      public Class<?> findType(String type) throws EvaluationException
      Throws:
      EvaluationException
    • getTypeConverter

      public TypeConverter getTypeConverter()
    • convertValue

      public Object convertValue(Object value, org.springframework.core.convert.TypeDescriptor targetTypeDescriptor) throws EvaluationException
      Throws:
      EvaluationException
    • convertValue

      @Nullable public Object convertValue(TypedValue value, org.springframework.core.convert.TypeDescriptor targetTypeDescriptor) throws EvaluationException
      Throws:
      EvaluationException
    • enterScope

      public void enterScope()
      Enter a new scope with a new root context object and a new local variable scope.
    • enterScope

      @Deprecated(since="6.2", forRemoval=true) public void enterScope(String name, Object value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of 6.2 with no replacement; to be removed in 7.0
      Enter a new scope with a new root context object and a new local variable scope containing the supplied name/value pair.
      Parameters:
      name - the name of the local variable
      value - the value of the local variable
    • enterScope

      @Deprecated(since="6.2", forRemoval=true) public void enterScope(@Nullable Map<String,Object> variables)
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of 6.2 with no replacement; to be removed in 7.0
      Enter a new scope with a new root context object and a new local variable scope containing the supplied name/value pairs.
      Parameters:
      variables - a map containing name/value pairs for local variables
    • exitScope

      public void exitScope()
    • setLocalVariable

      @Deprecated(since="6.2", forRemoval=true) public void setLocalVariable(String name, Object value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of 6.2 with no replacement; to be removed in 7.0
      Set a local variable with the given name to the supplied value within the current scope.

      If a local variable with the given name already exists, it will be overwritten.

      Parameters:
      name - the name of the local variable
      value - the value of the local variable
    • lookupLocalVariable

      @Deprecated(since="6.2", forRemoval=true) @Nullable public Object lookupLocalVariable(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      as of 6.2 with no replacement; to be removed in 7.0
      Look up the value of the local variable with the given name.
      Parameters:
      name - the name of the local variable
      Returns:
      the value of the local variable, or null if the variable does not exist in the current scope
    • operate

      public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException
      Throws:
      EvaluationException
    • getPropertyAccessors

      public List<PropertyAccessor> getPropertyAccessors()
    • getEvaluationContext

      public EvaluationContext getEvaluationContext()
    • getConfiguration

      public SpelParserConfiguration getConfiguration()