Package net.shibboleth.shared.logic

# Class ScriptedPredicate<T>

java.lang.Object
net.shibboleth.shared.scripting.AbstractScriptEvaluator
net.shibboleth.shared.logic.ScriptedPredicate<T>

Type Parameters:
  `T` - input type

All Implemented Interfaces:
  `Predicate<T>`

public class ScriptedPredicate<T> extends AbstractScriptEvaluator implements Predicate<T>
A `Predicate` which calls out to a supplied script.

Since:
  7.4.0

## Field Summary

Fields
Modifier and Type
Field
Description
`private Class<T>`
`inputTypeClass`
Input type.
`private final org.slf4j.Logger`
`log`
Class logger.

### Fields inherited from class net.shibboleth.shared.scripting.AbstractScriptEvaluator

`DEFAULT_ENGINE`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ScriptedPredicate(EvaluableScript theScript)`
Constructor.
`protected`
`ScriptedPredicate(EvaluableScript theScript, String extraInfo)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Class<T>`
`getInputType()`
Get the input type to be enforced.
`static <T> ScriptedPredicate<T>`
`inlineScript(String scriptSource)`
Factory to create `ScriptedPredicate` from inline data.
`static <T> ScriptedPredicate<T>`
`inlineScript(String engineName, String scriptSource)`
Factory to create `ScriptedPredicate` from inline data.
`protected void`
`prepareContext(ScriptContext scriptContext, Object... input)`
Pre-process the script context before execution.
`static <T> ScriptedPredicate<T>`
`resourceScript(String engineName, Resource resource)`
Factory to create `ScriptedPredicate` from a `Resource`.
`static <T> ScriptedPredicate<T>`
`resourceScript(Resource resource)`
Factory to create `ScriptedPredicate` from a `Resource`.
`private boolean`
`returnError()`
Helper function to sanity check return-on-error object.
`void`
`setInputType(Class<T> type)`
Set the input type to be enforced.
`void`
`setReturnOnError(boolean flag)`
Set value to return if an error occurs.
`boolean`
`test(T input)`

### Methods inherited from class net.shibboleth.shared.scripting.AbstractScriptEvaluator

`evaluate, finalizeContext, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setContextExtenders, setCustomObject, setHideExceptions, setLogPrefix, setOutputType, setReturnOnError`

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

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

### Methods inherited from interface java.util.function.Predicate

`and, negate, or`

## Field Details

### log

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

### inputTypeClass

@Nullable private Class<T> inputTypeClass
Input type.

## Constructor Details

### ScriptedPredicate

protected ScriptedPredicate(@Nonnull @NotEmpty EvaluableScript theScript, @Nullable @NotEmpty String extraInfo)
Constructor.

Parameters:
  `theScript` - the script we will evaluate.
  `extraInfo` - debugging information.

### ScriptedPredicate

protected ScriptedPredicate(@Nonnull @NotEmpty EvaluableScript theScript)
Constructor.

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

## Method Details

### getInputType

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

Returns:
  input type
Since:
  8.2.0

### setInputType

public void setInputType(@Nullable Class<T> type)
Set the input type to be enforced.

Parameters:
  `type` - input type
Since:
  8.2.0

### setReturnOnError

public void setReturnOnError(boolean flag)
Set value to return if an error occurs.

Parameters:
  `flag` - value to return

### test

public boolean test(@Nullable T input)

Specified by:
  `test` in interface `Predicate<T>`

### returnError

private boolean returnError() throws ClassCastException
Helper function to sanity check return-on-error object.

Returns:
  a boolean-valued error fallback
Throws:
  `ClassCastException` - if the installed fallback is null or non-Boolean

### prepareContext

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

Specified by:
  `prepareContext` in class `AbstractScriptEvaluator`
Parameters:
  `scriptContext` - the script context
  `input` - the input

### resourceScript

@Nonnull public static <T> ScriptedPredicate<T> resourceScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedPredicate` from a `Resource`.

Type Parameters:
  `T` - input type
Parameters:
  `resource` - the resource to look at
  `engineName` - the language
Returns:
  the predicate
Throws:
  `ScriptException` - if the compile fails
  `IOException` - if the file doesn't exist.
  `ComponentInitializationException` - if the scripting initialization fails

### resourceScript

@Nonnull public static <T> ScriptedPredicate<T> resourceScript(@Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedPredicate` from a `Resource`.

Type Parameters:
  `T` - input type
Parameters:
  `resource` - the resource to look at
Returns:
  the predicate
Throws:
  `ScriptException` - if the compile fails
  `IOException` - if the file doesn't exist.
  `ComponentInitializationException` - if the scripting initialization fails

### inlineScript

@Nonnull public static <T> ScriptedPredicate<T> inlineScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedPredicate` from inline data.

Type Parameters:
  `T` - input type
Parameters:
  `scriptSource` - the script, as a string
  `engineName` - the language
Returns:
  the predicate
Throws:
  `ScriptException` - if the compile fails
  `ComponentInitializationException` - if the scripting initialization fails

### inlineScript

@Nonnull public static <T> ScriptedPredicate<T> inlineScript(@Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedPredicate` from inline data.

Type Parameters:
  `T` - input type
Parameters:
  `scriptSource` - the script, as a string
Returns:
  the predicate
Throws:
  `ScriptException` - if the compile fails
  `ComponentInitializationException` - if the scripting initialization fails