Module net.shibboleth.ext.spring
Package net.shibboleth.ext.spring.util
Class AbstractSpringExpressionEvaluator<T,U>
- java.lang.Object
-
- net.shibboleth.ext.spring.util.AbstractSpringExpressionEvaluator<T,U>
-
- Type Parameters:
T- type of inputU- 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 Summary
Fields Modifier and Type Field Description private ObjectcustomObjectA custom object to inject into the expression context.private booleanhideExceptionsWhether to raise runtime exceptions if expression fails.private Class<T>inputTypeThe input type.private org.slf4j.LoggerlogClass logger.private Class<U>outputTypeThe output type.private UreturnOnErrorValue to return from predicate when an error occurs.private StringspringExpressionSpEL expression to evaluate.
-
Constructor Summary
Constructors Constructor Description AbstractSpringExpressionEvaluator(String expression)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Uevaluate(T input)Evaluate the Spring expression on the provided input.ObjectgetCustomObject()Get the custom (externally provided) object.Class<T>getInputType()Get the input type to be enforced.protected Class<U>getOutputType()Get the output type to be enforced.protected voidprepareContext(EvaluationContext context, T input)Decorate the expression context with any additional content.voidsetCustomObject(Object object)Set a custom (externally provided) object.voidsetHideExceptions(boolean flag)Set whether to hide exceptions in expression execution (default is false).voidsetInputType(Class<T> type)Set the input type to be enforced.voidsetOutputType(Class<U> type)Set the output type to be enforced.voidsetReturnOnError(U what)Set value to return if an error occurs (default is false).
-
-
-
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.
-
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 contextinput- to predicate
-
-