Class EvaluableScript
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.utilities.java.support.scripting.EvaluableScript
- All Implemented Interfaces:
Component
,DestructableComponent
,InitializableComponent
This is a helper class that takes care of reading in, optionally compiling, and evaluating a script.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CompiledScript
The compiled form of the script, if the script engine supports compiling.private final org.slf4j.Logger
The log.private String
The script to execute.private ScriptEngine
The script engine to execute the script.private String
The scripting language. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.EvaluableScript
(File scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(InputStream scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(String scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(String engineName, File scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(String engineName, InputStream scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(String engineName, String scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(String engineName, Resource scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1EvaluableScript
(Resource scriptSource) Deprecated, for removal: This API element is subject to removal in a future version.in 8.1 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Performs the initialization of the component.Evaluates this script against the given bindings.eval
(ScriptContext scriptContext) Evaluates this script against the given context.Gets the script source.Gets the script language.void
Deprecated, for removal: This API element is subject to removal in a future version.Remove in V9.0.0void
setEngineName
(String what) Sets the script language.void
Sets the script source.void
setScript
(InputStream scriptSource) Sets the script source.void
Sets the script source.void
Sets the script source.Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Field Details
-
scriptLanguage
The scripting language. -
script
The script to execute. -
scriptEngine
The script engine to execute the script. -
compiledScript
The compiled form of the script, if the script engine supports compiling. -
log
@Nonnull private final org.slf4j.Logger logThe log.
-
-
Constructor Details
-
EvaluableScript
public EvaluableScript()Constructor. -
EvaluableScript
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull @NotEmpty String scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull @NotEmpty String scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- Parameters:
scriptSource
- the script source- Throws:
ScriptException
- thrown if the scripting engine supports compilation and the script does not compile
-
EvaluableScript
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull Resource scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull Resource scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull InputStream scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor. 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull InputStream scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor. 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty String engineName, @ParameterName(name="scriptSource") @Nonnull File scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- 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
@Deprecated(forRemoval=true, since="8.1.0") public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull File scriptSource) throws ScriptException Deprecated, for removal: This API element is subject to removal in a future version.in 8.1Constructor.- 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 Details
-
getScript
Gets the script source.- Returns:
- the script source
-
setScript
Sets the script source.- Parameters:
what
- the script source
-
setScript
Sets the script source.- Parameters:
scriptSource
- how to get the script source- Throws:
IOException
- if there were issues reading the script
-
setScript
Sets the script source.- Parameters:
scriptSource
- how to get the script source- Throws:
IOException
- if there were issues reading the script
-
setScript
Sets the script source.- Parameters:
scriptSource
- how to get the script source- Throws:
IOException
- if there were issues reading the script
-
getScriptLanguage
Gets the script language.- Returns:
- the script language
-
setEngineName
Sets the script language.- Parameters:
what
- the script language
-
eval
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
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
-
doInitialize
Performs the initialization of the component. This method is executed within the lock on the object being initialized. The default implementation of this method is a no-op. Initializes the scripting engine and compiles the script, if possible.- Overrides:
doInitialize
in classAbstractInitializableComponent
- Throws:
ComponentInitializationException
- if the scripting engine supports compilation and the script does not compile
-
initializeWithScriptException
@Deprecated(forRemoval=true, since="8.1.0") public void initializeWithScriptException() throws ScriptExceptionDeprecated, for removal: This API element is subject to removal in a future version.Remove in V9.0.0Internal method to wrapAbstractInitializableComponent.initialize()
. This allows backwards compatibility with respect to the exception handling. We extract the cause from the Component Initialization and if it is aScriptException
throw that, otherwise we throw a new one which encapsulates the exception. Deprecation note. In most non-test cases the was to resolve this deprecation is to remove the method call (since most use is in bean generation and the initialize will be called). In every other case the answer is to useAbstractInitializableComponent.initialize()
and change the callers signature. Or just remove the whole thing.- Throws:
ScriptException
- if there is a compilation issue.
-