net.shibboleth.utilities.java.support.scripting
Class EvaluableScript

java.lang.Object
  extended by net.shibboleth.utilities.java.support.scripting.EvaluableScript

public class EvaluableScript
extends Object

This is a helper class that takes care of reading in, optionally compiling, and evaluating a script.


Field Summary
private  CompiledScript compiledScript
          The compiled form of the script, if the script engine supports compiling.
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
EvaluableScript(String engineName, File scriptSource)
          Constructor.
EvaluableScript(String engineName, String scriptSource)
          Constructor.
 
Method Summary
 com.google.common.base.Optional<Object> eval(Bindings scriptBindings)
          Evaluates this script against the given bindings.
 com.google.common.base.Optional<Object> eval(ScriptContext scriptContext)
          Evaluates this script against the given context.
 String getScript()
          Gets the script source.
private  void initialize()
          Initializes the scripting engine and compiles the script, if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scriptLanguage

private final String scriptLanguage
The scripting language.


script

private final String script
The script to execute.


scriptEngine

private ScriptEngine scriptEngine
The script engine to execute the script.


compiledScript

private CompiledScript compiledScript
The compiled form of the script, if the script engine supports compiling.

Constructor Detail

EvaluableScript

public EvaluableScript(@Nonnull@NotEmpty
                       String engineName,
                       @Nonnull@NotEmpty
                       String scriptSource)
                throws ScriptException
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

public EvaluableScript(@Nonnull@NotEmpty
                       String engineName,
                       @Nonnull
                       File scriptSource)
                throws ScriptException
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
Method Detail

getScript

@Nonnull
public String getScript()
Gets the script source.

Returns:
the script source

eval

@Nonnull
public com.google.common.base.Optional<Object> eval(Bindings scriptBindings)
                                             throws ScriptException
Evaluates this script against the given bindings.

Parameters:
scriptBindings - the script bindings
Returns:
the result of the script or Optional.absent() if the script did not return a result
Throws:
ScriptException - thrown if there was a problem evaluating the script

eval

@Nonnull
public com.google.common.base.Optional<Object> eval(ScriptContext scriptContext)
                                             throws ScriptException
Evaluates this script against the given context.

Parameters:
scriptContext - the script context
Returns:
the result of the script or Optional.absent() if the script did not return a result
Throws:
ScriptException - thrown if there was a problem evaluating the script

initialize

private void initialize()
                 throws ScriptException
Initializes the scripting engine and compiles the script, if possible.

Throws:
ScriptException - thrown if the scripting engine supports compilation and the script does not compile


Copyright © 1999-2012. All Rights Reserved.