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 Details

    • scriptLanguage

      @Nonnull @NotEmpty private String scriptLanguage
      The scripting language.
    • 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 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.1
      Constructor.
      Parameters:
      engineName - the JSR-223 scripting engine name
      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="scriptSource") @Nonnull @NotEmpty String scriptSource) throws ScriptException
      Deprecated, for removal: This API element is subject to removal in a future version.
      in 8.1
      Constructor.
      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.1
      Constructor.
      Parameters:
      engineName - the JSR-223 scripting engine name
      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="scriptSource") @Nonnull Resource scriptSource) throws ScriptException
      Deprecated, for removal: This API element is subject to removal in a future version.
      in 8.1
      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

      @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.1
      Constructor. The provided stream is not closed.
      Parameters:
      engineName - the JSR-223 scripting engine name
      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
    • 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.1
      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

      @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.1
      Constructor.
      Parameters:
      engineName - the JSR-223 scripting engine name
      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
    • 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.1
      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 Details

    • 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 ComponentInitializationException
      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 class AbstractInitializableComponent
      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.0
      Internal method to wrap AbstractInitializableComponent.initialize(). This allows backwards compatibility with respect to the exception handling. We extract the cause from the Component Initialization and if it is a ScriptException 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 use AbstractInitializableComponent.initialize() and change the callers signature. Or just remove the whole thing.
      Throws:
      ScriptException - if there is a compilation issue.