Class FunctionExpression<S>

java.lang.Object
org.springframework.integration.expression.FunctionExpression<S>
Type Parameters:
S - The evaluation context root object type.
All Implemented Interfaces:
org.springframework.expression.Expression

public class FunctionExpression<S> extends Object implements org.springframework.expression.Expression
An Expression that simply invokes Function.apply(Object) on its provided Function.

This is a powerful alternative to the SpEL, when Java 8 and its Lambda support is in use.

If the target component has support for an Expression property, a FunctionExpression can be specified instead of a SpelExpression as an alternative to evaluate the value from the Lambda, rather than runtime SpEL resolution.

The FunctionExpression is 'read-only', hence only getValue() operations are allowed. Any setValue(org.springframework.expression.EvaluationContext, java.lang.Object) operations and getValueType() related operations throw EvaluationException.

Since:
5.0
  • Constructor Details

    • FunctionExpression

      public FunctionExpression(Function<S,?> function)
  • Method Details

    • getValue

      @Nullable public Object getValue() throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public Object getValue(@Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public <T> T getValue(@Nullable Class<T> desiredResultType) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public <T> T getValue(@Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public Object getValue(org.springframework.expression.EvaluationContext context) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public Object getValue(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public <T> T getValue(org.springframework.expression.EvaluationContext context, @Nullable Class<T> desiredResultType) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValue

      @Nullable public <T> T getValue(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws org.springframework.expression.EvaluationException
      Specified by:
      getValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueType

      public Class<?> getValueType() throws org.springframework.expression.EvaluationException
      Specified by:
      getValueType in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueType

      public Class<?> getValueType(@Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueType in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueType

      public Class<?> getValueType(org.springframework.expression.EvaluationContext context) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueType in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueType

      public Class<?> getValueType(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueType in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueTypeDescriptor

      public org.springframework.core.convert.TypeDescriptor getValueTypeDescriptor() throws org.springframework.expression.EvaluationException
      Specified by:
      getValueTypeDescriptor in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueTypeDescriptor

      public org.springframework.core.convert.TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueTypeDescriptor in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueTypeDescriptor

      public org.springframework.core.convert.TypeDescriptor getValueTypeDescriptor(org.springframework.expression.EvaluationContext context) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueTypeDescriptor in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getValueTypeDescriptor

      public org.springframework.core.convert.TypeDescriptor getValueTypeDescriptor(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      getValueTypeDescriptor in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • setValue

      public void setValue(org.springframework.expression.EvaluationContext context, @Nullable Object value) throws org.springframework.expression.EvaluationException
      Specified by:
      setValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • setValue

      public void setValue(@Nullable Object rootObject, @Nullable Object value) throws org.springframework.expression.EvaluationException
      Specified by:
      setValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • setValue

      public void setValue(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject, @Nullable Object value) throws org.springframework.expression.EvaluationException
      Specified by:
      setValue in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • isWritable

      public boolean isWritable(org.springframework.expression.EvaluationContext context) throws org.springframework.expression.EvaluationException
      Specified by:
      isWritable in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • isWritable

      public boolean isWritable(org.springframework.expression.EvaluationContext context, @Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      isWritable in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • isWritable

      public boolean isWritable(@Nullable Object rootObject) throws org.springframework.expression.EvaluationException
      Specified by:
      isWritable in interface org.springframework.expression.Expression
      Throws:
      org.springframework.expression.EvaluationException
    • getExpressionString

      public final String getExpressionString()
      Specified by:
      getExpressionString in interface org.springframework.expression.Expression