Class AbstractSpringExpressionEvaluator<T,​U>

  • Type Parameters:
    T - type of input
    U - type of output
    Direct Known Subclasses:
    SpringExpressionFunction, SpringExpressionPredicate

    public abstract class AbstractSpringExpressionEvaluator<T,​U>
    extends Object
    A component that evaluates a Spring EL expression against a set of inputs and returns the result.
    Since:
    5.4.0
    • Field Detail

      • log

        @Nonnull
        private final org.slf4j.Logger log
        Class logger.
      • springExpression

        @Nullable
        private String springExpression
        SpEL expression to evaluate.
      • customObject

        @Nullable
        private Object customObject
        A custom object to inject into the expression context.
      • outputType

        @Nullable
        private Class<U> outputType
        The output type.
      • inputType

        @Nullable
        private Class<T> inputType
        The input type.
      • hideExceptions

        private boolean hideExceptions
        Whether to raise runtime exceptions if expression fails.
      • returnOnError

        private U returnOnError
        Value to return from predicate when an error occurs.
    • Constructor Detail

      • AbstractSpringExpressionEvaluator

        public AbstractSpringExpressionEvaluator​(@Nonnull @NotEmpty @ParameterName(name="expression")
                                                 String expression)
        Constructor.
        Parameters:
        expression - the expression to evaluate
    • Method Detail

      • setOutputType

        public void setOutputType​(@Nullable
                                  Class<U> type)
        Set the output type to be enforced.
        Parameters:
        type - output type
      • getOutputType

        @Nullable
        protected Class<U> getOutputType()
        Get the output type to be enforced.
        Returns:
        output type
      • getInputType

        @Nullable
        public Class<T> getInputType()
        Get the input type to be enforced.
        Returns:
        input type
      • setInputType

        public void setInputType​(@Nullable
                                 Class<T> type)
        Set the input type to be enforced.
        Parameters:
        type - input type
      • setCustomObject

        public void setCustomObject​(@Nullable
                                    Object object)
        Set a custom (externally provided) object.
        Parameters:
        object - the custom object
      • getCustomObject

        public Object getCustomObject()
        Get the custom (externally provided) object.
        Returns:
        the custom object
      • setHideExceptions

        public void setHideExceptions​(boolean flag)
        Set whether to hide exceptions in expression execution (default is false).
        Parameters:
        flag - flag to set
      • setReturnOnError

        public void setReturnOnError​(U what)
        Set value to return if an error occurs (default is false).
        Parameters:
        what - value to set
      • evaluate

        protected U evaluate​(@Nullable
                             T input)
        Evaluate the Spring expression on the provided input.
        Parameters:
        input - input over which to evaluate the expression
        Returns:
        result of applying the expression to the provided input
      • prepareContext

        protected void prepareContext​(@Nonnull
                                      EvaluationContext context,
                                      @Nullable
                                      T input)
        Decorate the expression context with any additional content.
        Parameters:
        context - expression context
        input - to predicate