Class ScriptedFunction<T,U>
- java.lang.Object
-
- net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
-
- net.shibboleth.utilities.java.support.logic.ScriptedFunction<T,U>
-
- Type Parameters:
T- input typeU- output type
- All Implemented Interfaces:
Function<T,U>
public class ScriptedFunction<T,U> extends AbstractScriptEvaluator implements Function<T,U>
AFunctionwhich calls out to a supplied script.- Since:
- 7.4.0
-
-
Field Summary
Fields Modifier and Type Field Description private Class<T>inputTypeClassInput Type.private org.slf4j.LoggerlogClass logger.-
Fields inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedScriptedFunction(EvaluableScript theScript)Constructor.protectedScriptedFunction(EvaluableScript theScript, String extraInfo)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Uapply(T input)Class<T>getInputType()Get the input type to be enforced.static <T,U>
ScriptedFunction<T,U>inlineScript(String scriptSource)Factory to createScriptedFunctionfrom inline data.static <T,U>
ScriptedFunction<T,U>inlineScript(String engineName, String scriptSource)Factory to createScriptedFunctionfrom inline data.protected voidprepareContext(ScriptContext scriptContext, Object... input)Pre-process the script context before execution.static <T,U>
ScriptedFunction<T,U>resourceScript(String engineName, Resource resource)Factory to createScriptedFunctionfrom aResource.static <T,U>
ScriptedFunction<T,U>resourceScript(Resource resource)Factory to createScriptedFunctionfrom aResource.voidsetInputType(Class<T> type)Set the input type to be enforced.voidsetOutputType(Class<?> type)Set the output type to be enforced.voidsetReturnOnError(Object value)Set value to return if an error occurs.-
Methods inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
evaluate, finalizeContext, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setCustomObject, setHideExceptions, setLogPrefix
-
-
-
-
Constructor Detail
-
ScriptedFunction
protected ScriptedFunction(@Nonnull @NotEmpty @ParameterName(name="theScript") EvaluableScript theScript, @Nullable @NotEmpty @ParameterName(name="extraInfo") String extraInfo)
Constructor.- Parameters:
theScript- the script we will evaluate.extraInfo- debugging information.
-
ScriptedFunction
protected ScriptedFunction(@Nonnull @NotEmpty @ParameterName(name="theScript") EvaluableScript theScript)
Constructor.- Parameters:
theScript- the script we will evaluate.
-
-
Method Detail
-
setOutputType
public void setOutputType(@Nullable Class<?> type)Set the output type to be enforced.- Overrides:
setOutputTypein classAbstractScriptEvaluator- Parameters:
type- 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
-
setReturnOnError
public void setReturnOnError(@Nullable Object value)Set value to return if an error occurs.- Overrides:
setReturnOnErrorin classAbstractScriptEvaluator- Parameters:
value- value to return
-
prepareContext
protected void prepareContext(@Nonnull ScriptContext scriptContext, @Nullable Object... input)Pre-process the script context before execution.- Specified by:
prepareContextin classAbstractScriptEvaluator- Parameters:
scriptContext- the script contextinput- the input
-
resourceScript
public static <T,U> ScriptedFunction<T,U> resourceScript(@Nonnull @NotEmpty String engineName, @Nonnull Resource resource) throws ScriptException, IOException
Factory to createScriptedFunctionfrom aResource.- Type Parameters:
T- input typeU- output type- Parameters:
resource- the resource to look atengineName- the language- Returns:
- the function
- Throws:
ScriptException- if the compile failsIOException- if the file doesn't exist.
-
resourceScript
public static <T,U> ScriptedFunction<T,U> resourceScript(Resource resource) throws ScriptException, IOException
Factory to createScriptedFunctionfrom aResource.- Type Parameters:
T- input typeU- output type- Parameters:
resource- the resource to look at- Returns:
- the function
- Throws:
ScriptException- if the compile failsIOException- if the file doesn't exist.
-
inlineScript
public static <T,U> ScriptedFunction<T,U> inlineScript(@Nonnull @NotEmpty String engineName, @Nonnull @NotEmpty String scriptSource) throws ScriptException
Factory to createScriptedFunctionfrom inline data.- Type Parameters:
T- input typeU- output type- Parameters:
scriptSource- the script, as a stringengineName- the language- Returns:
- the function
- Throws:
ScriptException- if the compile fails
-
inlineScript
public static <T,U> ScriptedFunction<T,U> inlineScript(@Nonnull @NotEmpty String scriptSource) throws ScriptException
Factory to createScriptedFunctionfrom inline data.- Type Parameters:
T- input typeU- output type- Parameters:
scriptSource- the script, as a string- Returns:
- the function
- Throws:
ScriptException- if the compile fails
-
-