Package net.shibboleth.shared.scripting

# Class AbstractScriptEvaluator

java.lang.Object
net.shibboleth.shared.scripting.AbstractScriptEvaluator

Direct Known Subclasses:
  `ScriptedBiConsumer`, `ScriptedBiFunction`, `ScriptedBiPredicate`, `ScriptedConsumer`, `ScriptedFunction`, `ScriptedPredicate`, `ScriptedRunnable.RunnableScriptEvaluator`

public abstract class AbstractScriptEvaluator extends Object
A component that evaluates an `EvaluableScript` against a set of inputs and returns the result.

Since:
  7.4.0

## Field Summary

Fields
Modifier and Type
Field
Description
`private Collection<ScriptContextExtender>`
`contextExtenders`
Extension objects to apply.
`private Object`
`customObject`
A custom object to inject into the script.
`static final String`
`DEFAULT_ENGINE`
The default language is Javascript.
`private boolean`
`hideExceptions`
Whether to raise runtime exceptions if a script fails.
`private final org.slf4j.Logger`
`log`
Class logger.
`private String`
`logPrefix`
Debugging info.
`private Class<?>`
`outputType`
The output type to validate.
`private Object`
`returnOnError`
Value to return from script if an error occurs.
`private final EvaluableScript`
`script`
The script we care about.

## Constructor Summary

Constructors
Constructor
Description
`AbstractScriptEvaluator(EvaluableScript theScript)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected Object`
`evaluate(Object... input)`
Evaluate the script.
`protected Object`
`finalizeContext(ScriptContext scriptContext, Object scriptResult)`
Complete processing by evaluating the result of the script and returning the final result to the caller.
`protected Object`
`getCustomObject()`
Return the custom (externally provided) object.
`protected boolean`
`getHideExceptions()`
Get whether to hide exceptions in script execution.
`protected String`
`getLogPrefix()`
Get log prefix for debugging.
`protected Class<?>`
`getOutputType()`
Get the output type to be enforced.
`protected Object`
`getReturnOnError()`
Get value to return if an error occurs.
`protected abstract void`
`prepareContext(ScriptContext scriptContext, Object... input)`
Pre-process the script context before execution.
`void`
`setContextExtenders(Collection<? extends ScriptContextExtender> extenders)`
Set `ScriptContextExtender` instances to apply when populating script context.
`void`
`setCustomObject(Object object)`
Set the custom (externally provided) object.
`void`
`setHideExceptions(boolean flag)`
Set whether to hide exceptions in script execution (default is false).
`void`
`setLogPrefix(String prefix)`
Set log prefix for debugging.
`protected void`
`setOutputType(Class<?> type)`
Set the output type to be enforced.
`protected void`
`setReturnOnError(Object value)`
Set value to return if an error occurs.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_ENGINE

@Nonnull @NotEmpty public static final String DEFAULT_ENGINE
The default language is Javascript.

See Also:
  - Constant Field Values

### log

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

### script

@Nonnull private final EvaluableScript script
The script we care about.

### contextExtenders

@Nonnull private Collection<ScriptContextExtender> contextExtenders
Extension objects to apply.

### logPrefix

@Nullable private String logPrefix
Debugging info.

### outputType

@Nullable private Class<?> outputType
The output type to validate.

### customObject

@Nullable private Object customObject
A custom object to inject into the script.

### hideExceptions

private boolean hideExceptions
Whether to raise runtime exceptions if a script fails.

### returnOnError

@Nullable private Object returnOnError
Value to return from script if an error occurs.

## Constructor Details

### AbstractScriptEvaluator

public AbstractScriptEvaluator(@Nonnull @ParameterName(name="theScript") EvaluableScript theScript)
Constructor.

Parameters:
  `theScript` - the script we will evaluate.

## Method Details

### getLogPrefix

@Nullable protected String getLogPrefix()
Get log prefix for debugging.

Returns:
  log prefix

### setLogPrefix

public void setLogPrefix(@Nullable String prefix)
Set log prefix for debugging.

Parameters:
  `prefix` - log prefix

### getOutputType

@Nullable protected Class<?> getOutputType()
Get the output type to be enforced.

Returns:
  output type

### setOutputType

protected void setOutputType(@Nullable Class<?> type)
Set the output type to be enforced.

Parameters:
  `type` - output type

### getCustomObject

@Nullable protected Object getCustomObject()
Return the custom (externally provided) object.

Returns:
  the custom object

### setCustomObject

public void setCustomObject(@Nullable Object object)
Set the custom (externally provided) object.

Parameters:
  `object` - the custom object

### getHideExceptions

protected boolean getHideExceptions()
Get whether to hide exceptions in script execution.

Returns:
  whether to hide exceptions in script execution

### setHideExceptions

public void setHideExceptions(boolean flag)
Set whether to hide exceptions in script execution (default is false).

Parameters:
  `flag` - flag to set

### getReturnOnError

@Nullable protected Object getReturnOnError()
Get value to return if an error occurs.

Returns:
  value to return

### setReturnOnError

protected void setReturnOnError(@Nullable Object value)
Set value to return if an error occurs.

Parameters:
  `value` - value to return

### setContextExtenders

public void setContextExtenders(@Nullable Collection<? extends ScriptContextExtender> extenders)
Set `ScriptContextExtender` instances to apply when populating script context.

Parameters:
  `extenders` - extenders to apply
Since:
  9.0.0

### evaluate

@Nullable protected Object evaluate(@Nullable Object... input)
Evaluate the script.

Parameters:
  `input` - input parameters
Returns:
  script result

### prepareContext

protected abstract void prepareContext(@Nonnull ScriptContext scriptContext, @Nullable Object... input)
Pre-process the script context before execution.

Parameters:
  `scriptContext` - the script context
  `input` - the input

### finalizeContext

@Nullable protected Object finalizeContext(@Nonnull ScriptContext scriptContext, @Nullable Object scriptResult) throws ScriptException
Complete processing by evaluating the result of the script and returning the final result to the caller.

The default implementation just returns the result.

Parameters:
  `scriptContext` - the context after execution
  `scriptResult` - the result of script execution
Returns:
  the final result to return, or null
Throws:
  `ScriptException` - to signal a failure after script execution