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
public final class EvaluableScript extends AbstractInitializableComponent
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 org.slf4j.LoggerlogThe log.private StringscriptThe script to execute.private ScriptEnginescriptEngineThe script engine to execute the script.private StringscriptLanguageThe scripting language.
-
Constructor Summary
Constructors Constructor Description EvaluableScript()Constructor.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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voiddoInitialize()Performs the initialization of the component.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.voidinitializeWithScriptException()Deprecated, for removal: This API element is subject to removal in a future version.Remove in V9.0.0voidsetEngineName(String what)Sets the script language.voidsetScript(File scriptSource)Sets the script source.voidsetScript(InputStream scriptSource)Sets the script source.voidsetScript(String what)Sets the script source.voidsetScript(Resource scriptSource)Sets the script source.-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
-
-
-
Field Detail
-
script
@NonnullAfterInit @NotEmpty private String script
The script to execute.
-
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.
-
log
@Nonnull private final org.slf4j.Logger log
The log.
-
-
Constructor Detail
-
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 Detail
-
getScript
@Nonnull @NotEmpty public String getScript()
Gets the script source.- Returns:
- the script source
-
setScript
@Nonnull @NotEmpty public void setScript(@Nonnull @NotEmpty String what)
Sets the script source.- Parameters:
what- the script source
-
setScript
@Nonnull @NotEmpty public void setScript(@Nonnull InputStream scriptSource) throws IOException
Sets the script source.- Parameters:
scriptSource- how to get the script source- Throws:
IOException- if there were issues reading the script
-
setScript
@Nonnull @NotEmpty public void setScript(@Nonnull File scriptSource) throws IOException
Sets the script source.- Parameters:
scriptSource- how to get the script source- Throws:
IOException- if there were issues reading the script
-
setScript
@Nonnull @NotEmpty public void setScript(@Nonnull Resource scriptSource) throws IOException
Sets the script source.- Parameters:
scriptSource- how to get the script source- Throws:
IOException- if there were issues reading the script
-
getScriptLanguage
@Nonnull @NotEmpty public String getScriptLanguage()
Gets the script language.- Returns:
- the script language
-
setEngineName
@Nonnull @NotEmpty public void setEngineName(@Nonnull @NotEmpty String what)
Sets the script language.- Parameters:
what- the script language
-
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
-
doInitialize
protected void doInitialize() throws ComponentInitializationExceptionPerforms 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:
doInitializein 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 ScriptException
Deprecated, 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 aScriptExceptionthrow 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.
-
-