Package org.forgerock.openam.scripting
Interface ScriptEvaluator
-
- All Known Implementing Classes:
StandardScriptEvaluator
,ThreadPoolScriptEvaluator
public interface ScriptEvaluator
Common component for evaluating scripts in one of the supported scripting languages.- Since:
- 12.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
bindVariableInGlobalScope(String name, Object object)
Binds the given object to the given variable name in the global scope of all scripts evaluated via this script evaluator.<T> T
evaluateScript(ScriptObject script, Bindings bindings)
Evaluates the given script object using an appropriate script engine for the language of the script.
-
-
-
Method Detail
-
evaluateScript
<T> T evaluateScript(ScriptObject script, Bindings bindings) throws ScriptException
Evaluates the given script object using an appropriate script engine for the language of the script. Any bindings associated with the script will be passed to the engine when the script is evaluated. There are three scope levels at which variables can be set:- Global variables are set using the
bindVariableInGlobalScope(String, Object)
method, which makes the objects visible to all script engines. This is most appropriate for stateless API objects such as HTTP clients and other basic functionality. - Script variables are set in the bindings attached to a
ScriptObject
. - Parameter variables are set by the bindings parameter to this method.
- Type Parameters:
T
- the type of result expected from the script.- Parameters:
script
- the script to evaluate.bindings
- any additional variable bindings to set before running the script.- Returns:
- the result of evaluating the script, or null if no result produced.
- Throws:
ScriptException
- if an error occurs evaluating the script.ClassCastException
- if the result is not of the expected type.IllegalStateException
- if no scripting engine can be located for the given scripting language.
- Global variables are set using the
-
bindVariableInGlobalScope
void bindVariableInGlobalScope(String name, Object object)
Binds the given object to the given variable name in the global scope of all scripts evaluated via this script evaluator. This is intended to be used to bind common API components such as HTTP clients etc that should be available to all scripts. For per-script state to initialise, use the bindings element on the script object itself.- Parameters:
name
- the name of the variable to bind the object to.object
- the object to bind into the global scope of all scripts.- Throws:
NullPointerException
- if either name or object is empty.IllegalArgumentException
- if the name is an empty string.
-
-