Class LiteralExpression

java.lang.Object
org.springframework.expression.common.LiteralExpression
All Implemented Interfaces:
Expression

public class LiteralExpression extends Object implements Expression
A very simple hardcoded implementation of the Expression interface that represents a string literal. It is used with CompositeStringExpression when representing a template expression which is made up of pieces - some being real expressions to be handled by an EL implementation like SpEL, and some being just textual elements.
Since:
3.0
Author:
Andy Clement, Juergen Hoeller
  • Constructor Details

    • LiteralExpression

      public LiteralExpression(String literalValue)
  • Method Details

    • getExpressionString

      public final String getExpressionString()
      Description copied from interface: Expression
      Return the original string used to create this expression (unmodified).
      Specified by:
      getExpressionString in interface Expression
      Returns:
      the original expression string
    • getValueType

      public Class<?> getValueType(EvaluationContext context)
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
      Specified by:
      getValueType in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      Returns:
      the most general type of value that can be set on this context
    • getValue

      public String getValue()
      Description copied from interface: Expression
      Evaluate this expression in the default standard context.
      Specified by:
      getValue in interface Expression
      Returns:
      the evaluation result
    • getValue

      @Nullable public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException
      Description copied from interface: Expression
      Evaluate the expression in the default context. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be returned.
      Specified by:
      getValue in interface Expression
      Parameters:
      expectedResultType - the class the caller would like the result to be
      Returns:
      the evaluation result
      Throws:
      EvaluationException - if there is a problem during evaluation
    • getValue

      public String getValue(@Nullable Object rootObject)
      Description copied from interface: Expression
      Evaluate this expression against the specified root object.
      Specified by:
      getValue in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      Returns:
      the evaluation result
    • getValue

      @Nullable public <T> T getValue(@Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException
      Description copied from interface: Expression
      Evaluate the expression in the default context against the specified root object. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be returned.
      Specified by:
      getValue in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      desiredResultType - the class the caller would like the result to be
      Returns:
      the evaluation result
      Throws:
      EvaluationException - if there is a problem during evaluation
    • getValue

      public String getValue(EvaluationContext context)
      Description copied from interface: Expression
      Evaluate this expression in the provided context and return the result of evaluation.
      Specified by:
      getValue in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      Returns:
      the evaluation result
    • getValue

      @Nullable public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException
      Description copied from interface: Expression
      Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type.
      Specified by:
      getValue in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      expectedResultType - the class the caller would like the result to be
      Returns:
      the evaluation result
      Throws:
      EvaluationException - if there is a problem during evaluation
    • getValue

      public String getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Evaluate this expression in the provided context and return the result of evaluation, but use the supplied root context as an override for any default root object specified in the context.
      Specified by:
      getValue in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      rootObject - the root object against which to evaluate the expression
      Returns:
      the evaluation result
      Throws:
      EvaluationException - if there is a problem during evaluation
    • getValue

      @Nullable public <T> T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException
      Description copied from interface: Expression
      Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type. The supplied root object overrides any default specified on the supplied context.
      Specified by:
      getValue in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      rootObject - the root object against which to evaluate the expression
      desiredResultType - the class the caller would like the result to be
      Returns:
      the evaluation result
      Throws:
      EvaluationException - if there is a problem during evaluation
    • getValueType

      public Class<?> getValueType()
      Description copied from interface: Expression
      Return the most general type that can be passed to a Expression.setValue(java.lang.Object, java.lang.Object) method using the default context.
      Specified by:
      getValueType in interface Expression
      Returns:
      the most general type of value that can be set on this context
    • getValueType

      public Class<?> getValueType(@Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(Object, Object) method using the default context.
      Specified by:
      getValueType in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      Returns:
      the most general type of value that can be set on this context
      Throws:
      EvaluationException - if there is a problem determining the type
    • getValueType

      public Class<?> getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(EvaluationContext, Object, Object) method for the given context. The supplied root object overrides any specified in the context.
      Specified by:
      getValueType in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      rootObject - the root object against which to evaluate the expression
      Returns:
      the most general type of value that can be set on this context
      Throws:
      EvaluationException - if there is a problem determining the type
    • getValueTypeDescriptor

      public TypeDescriptor getValueTypeDescriptor()
      Description copied from interface: Expression
      Return the most general type that can be passed to a Expression.setValue(java.lang.Object, java.lang.Object) method using the default context.
      Specified by:
      getValueTypeDescriptor in interface Expression
      Returns:
      a type descriptor for values that can be set on this context
    • getValueTypeDescriptor

      public TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(Object, Object) method using the default context.
      Specified by:
      getValueTypeDescriptor in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      Returns:
      a type descriptor for values that can be set on this context
      Throws:
      EvaluationException - if there is a problem determining the type
    • getValueTypeDescriptor

      public TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
      Specified by:
      getValueTypeDescriptor in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      Returns:
      a type descriptor for values that can be set on this context
    • getValueTypeDescriptor

      public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Return the most general type that can be passed to the Expression.setValue(EvaluationContext, Object, Object) method for the given context. The supplied root object overrides any specified in the context.
      Specified by:
      getValueTypeDescriptor in interface Expression
      Parameters:
      context - the context in which to evaluate the expression
      rootObject - the root object against which to evaluate the expression
      Returns:
      a type descriptor for values that can be set on this context
      Throws:
      EvaluationException - if there is a problem determining the type
    • isWritable

      public boolean isWritable(@Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Determine if an expression can be written to, i.e. setValue() can be called.
      Specified by:
      isWritable in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      Returns:
      true if the expression is writable; false otherwise
      Throws:
      EvaluationException - if there is a problem determining if it is writable
    • isWritable

      public boolean isWritable(EvaluationContext context)
      Description copied from interface: Expression
      Determine if an expression can be written to, i.e. setValue() can be called.
      Specified by:
      isWritable in interface Expression
      Parameters:
      context - the context in which the expression should be checked
      Returns:
      true if the expression is writable; false otherwise
    • isWritable

      public boolean isWritable(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException
      Description copied from interface: Expression
      Determine if an expression can be written to, i.e. setValue() can be called. The supplied root object overrides any specified in the context.
      Specified by:
      isWritable in interface Expression
      Parameters:
      context - the context in which the expression should be checked
      rootObject - the root object against which to evaluate the expression
      Returns:
      true if the expression is writable; false otherwise
      Throws:
      EvaluationException - if there is a problem determining if it is writable
    • setValue

      public void setValue(@Nullable Object rootObject, @Nullable Object value) throws EvaluationException
      Description copied from interface: Expression
      Set this expression in the provided context to the value provided.
      Specified by:
      setValue in interface Expression
      Parameters:
      rootObject - the root object against which to evaluate the expression
      value - the new value
      Throws:
      EvaluationException - if there is a problem during evaluation
    • setValue

      public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException
      Description copied from interface: Expression
      Set this expression in the provided context to the value provided.
      Specified by:
      setValue in interface Expression
      Parameters:
      context - the context in which to set the value of the expression
      value - the new value
      Throws:
      EvaluationException - if there is a problem during evaluation
    • setValue

      public void setValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Object value) throws EvaluationException
      Description copied from interface: Expression
      Set this expression in the provided context to the value provided. The supplied root object overrides any specified in the context.
      Specified by:
      setValue in interface Expression
      Parameters:
      context - the context in which to set the value of the expression
      rootObject - the root object against which to evaluate the expression
      value - the new value
      Throws:
      EvaluationException - if there is a problem during evaluation