Package net.shibboleth.shared.scripting

# Class EvaluableScript

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.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 CompiledScript`
`compiledScript`
The compiled form of the script, if the script engine supports compiling.
`private final org.slf4j.Logger`
`log`
The log.
`private String`
`script`
The script to execute.
`private ScriptEngine`
`scriptEngine`
The script engine to execute the script.
`private String`
`scriptLanguage`
The scripting language.

## Constructor Summary

Constructors
Constructor
Description
`EvaluableScript()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doInitialize()`
Performs the initialization of the component.
`Object`
`eval(Bindings scriptBindings)`
Evaluates this script against the given bindings.
`Object`
`eval(ScriptContext scriptContext)`
Evaluates this script against the given context.
`String`
`getScript()`
Gets the script source.
`String`
`getScriptLanguage()`
Gets the script language.
`void`
`setEngineName(String what)`
Sets the script language.
`void`
`setScript(File scriptSource)`
Sets the script source.
`void`
`setScript(InputStream scriptSource)`
Sets the script source.
`void`
`setScript(String what)`
Sets the script source.
`void`
`setScript(Resource scriptSource)`
Sets the script source.

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### scriptLanguage

@Nonnull @NotEmpty private String scriptLanguage
The scripting language.

### script

@NonnullAfterInit @NotEmpty private String script
The script to execute.

### scriptEngine

@NonnullAfterInit 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.

## Method Details

### getScript

@NonnullAfterInit @NotEmpty public String getScript()
Gets the script source.

Returns:
  the script source

### setScript

public void setScript(@Nonnull @NotEmpty String what)
Sets the script source.

Parameters:
  `what` - the script source

### setScript

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

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

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

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