Class EvaluableScript
- java.lang.Object
-
- net.shibboleth.utilities.java.support.scripting.EvaluableScript
-
public final class EvaluableScript extends Object
This is a helper class that takes care of reading in, optionally compiling, and evaluating a script.
-
-
Field Summary
Fields Modifier and Type Field Description private CompiledScriptcompiledScriptThe compiled form of the script, if the script engine supports compiling.private StringscriptThe script to execute.private ScriptEnginescriptEngineThe script engine to execute the script.private StringscriptLanguageThe scripting language.
-
Constructor Summary
Constructors Constructor Description EvaluableScript(File scriptSource)Constructor.EvaluableScript(InputStream scriptSource)Constructor.EvaluableScript(String scriptSource)Constructor.EvaluableScript(String engineName, File scriptSource)Constructor.EvaluableScript(String engineName, InputStream scriptSource)Constructor.EvaluableScript(String engineName, String scriptSource)Constructor.EvaluableScript(String engineName, Resource scriptSource)Constructor.EvaluableScript(Resource scriptSource)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objecteval(Bindings scriptBindings)Evaluates this script against the given bindings.Objecteval(ScriptContext scriptContext)Evaluates this script against the given context.StringgetScript()Gets the script source.StringgetScriptLanguage()Gets the script language.private voidinitialize()Initializes the scripting engine and compiles the script, if possible.
-
-
-
Field Detail
-
scriptEngine
@Nullable private ScriptEngine scriptEngine
The script engine to execute the script.
-
compiledScript
@Nullable private CompiledScript compiledScript
The compiled form of the script, if the script engine supports compiling.
-
-
Constructor Detail
-
EvaluableScript
public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull @NotEmpty String scriptSource) throws ScriptException
Constructor.- Parameters:
engineName- the JSR-223 scripting engine namescriptSource- the script source- Throws:
ScriptException- thrown if the scripting engine supports compilation and the script does not compile
-
EvaluableScript
public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull @NotEmpty String scriptSource) throws ScriptException
Constructor.- Parameters:
scriptSource- the script source- Throws:
ScriptException- thrown if the scripting engine supports compilation and the script does not compile
-
EvaluableScript
public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull Resource scriptSource) throws ScriptException
Constructor.- Parameters:
engineName- the JSR-223 scripting engine namescriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile- Since:
- 8.0.0
-
EvaluableScript
public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull Resource scriptSource) throws ScriptException
Constructor.- Parameters:
scriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile- Since:
- 8.0.0
-
EvaluableScript
public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull InputStream scriptSource) throws ScriptException
Constructor. The provided stream is not closed.- Parameters:
engineName- the JSR-223 scripting engine namescriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile
-
EvaluableScript
public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull InputStream scriptSource) throws ScriptException
Constructor. The provided stream is not closed.- Parameters:
scriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile- Since:
- 8.0.0
-
EvaluableScript
public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull File scriptSource) throws ScriptException
Constructor.- Parameters:
engineName- the JSR-223 scripting engine namescriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile
-
EvaluableScript
public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull File scriptSource) throws ScriptException
Constructor.- Parameters:
scriptSource- the script source- Throws:
ScriptException- thrown if the script source file can not be read or the scripting engine supports compilation and the script does not compile- Since:
- 8.0.0
-
-
Method Detail
-
getScript
@Nonnull @NotEmpty public String getScript()
Gets the script source.- Returns:
- the script source
-
getScriptLanguage
@Nonnull @NotEmpty public String getScriptLanguage()
Gets the script language.- Returns:
- the script source
-
eval
@Nullable public Object eval(@Nonnull Bindings scriptBindings) throws ScriptException
Evaluates this script against the given bindings.- Parameters:
scriptBindings- the script bindings- Returns:
- the result of the script or null if the script did not return a result
- Throws:
ScriptException- thrown if there was a problem evaluating the script
-
eval
@Nullable public Object eval(@Nonnull ScriptContext scriptContext) throws ScriptException
Evaluates this script against the given context.- Parameters:
scriptContext- the script context- Returns:
- the result of the script or null if the script did not return a result
- Throws:
ScriptException- thrown if there was a problem evaluating the script
-
initialize
private void initialize() throws ScriptExceptionInitializes the scripting engine and compiles the script, if possible.- Throws:
ScriptException- thrown if the scripting engine supports compilation and the script does not compile
-
-