Class ScriptDefinition

java.lang.Object
org.jppf.scripting.ScriptDefinition
All Implemented Interfaces:
Serializable

public class ScriptDefinition extends Object implements Serializable
An easy to use wrapper around the JPPF scripting APIs.
Author:
Laurent Cohen
See Also:
  • Constructor Details

    • ScriptDefinition

      public ScriptDefinition(String language, String script)
      Initialize this object with the specified language and a script given as text.
      Parameters:
      language - the script language.
      script - the script content as text.
    • ScriptDefinition

      public ScriptDefinition(String language, String script, Map<String,Object> bindings)
      Initialize this object with the specified language, variable bindings and a script given as text.
      Parameters:
      language - the script language.
      script - the script content as text.
      bindings - optional variable bindings made available to the script at execution time.
    • ScriptDefinition

      public ScriptDefinition(String language, Reader reader) throws IOException
      Initialize this object with the specified language and a script to read from a Reader.
      Parameters:
      language - the script language.
      reader - a Reader from which to read the script content.
      Throws:
      IOException - if the script content could not be read from the reader.
    • ScriptDefinition

      public ScriptDefinition(String language, Reader reader, Map<String,Object> bindings) throws IOException
      Initialize this object with the specified language, variable bindings and a script to read from a Reader.
      Parameters:
      language - the script language.
      reader - a Reader from which to read the script content.
      bindings - optional variable bindings made available to the script at execution time.
      Throws:
      IOException - if the script content could not be read from the reader.
    • ScriptDefinition

      public ScriptDefinition(String language, File file) throws IOException
      Initialize this object with the specified language and a script to read from a file.
      Parameters:
      language - the script language.
      file - a file from which to read the script content.
      Throws:
      IOException - if the script content could not be read from the reader.
    • ScriptDefinition

      public ScriptDefinition(String language, File file, Map<String,Object> bindings) throws IOException
      Initialize this object with the specified language, variable bindings and a script to read from a file.
      Parameters:
      language - the script language.
      file - a file from which to read the script content.
      bindings - optional variable bindings made available to the script at execution time.
      Throws:
      IOException - if the script content could not be read from the file.
    • ScriptDefinition

      public ScriptDefinition(String language, String script, String id, Map<String,Object> bindings)
      Parameters:
      language - the script language.
      script - the script content as text.
      id - an identifier which allows reusing the compiled script.
      bindings - optional variable bindings made available to the script at execution time.
  • Method Details

    • getLanguage

      public String getLanguage()
      Returns:
      the script language.
    • getScript

      public String getScript()
      Returns:
      the script content as text.
    • getId

      public String getId()
      Returns:
      the identifier which allows reusing the compiled script.
    • getBindings

      public Map<String,Object> getBindings()
      Get the vairable bindings.
      Returns:
      the optional variable bindings made available to the script at execution time.
    • evaluate

      public Object evaluate() throws JPPFScriptingException
      Execute the script and return its execution result, using the initial variable bindings.
      Returns:
      the script execution result, or null if there is no result.
      Throws:
      JPPFScriptingException - if any error occurs while executing the script.
    • evaluate

      public Object evaluate(Map<String,Object> additionalBindings) throws JPPFScriptingException
      Execute the script and return its execution result, using additional bindings.
      Parameters:
      additionalBindings - bindings to use in addition to the initial bindings specified in the constructor. These optional bindings are only used for a single script execution and are not kept in this ScriptDefintion.
      Returns:
      the script execution result, or null if there is no result.
      Throws:
      JPPFScriptingException - if any error occurs while executing the script.
    • addBinding

      public ScriptDefinition addBinding(String name, Object value)
      Add the specified variable to the user-defined bindings.
      Parameters:
      name - the name of the variable binding to add.
      value - the value of the variable.
      Returns:
      this ScriptDefintion, for method call chaining.
    • removeBinding

      public Object removeBinding(String name)
      Remove the specified variable from the user-defined bindings.
      Parameters:
      name - the name of the variable binding to remove.
      Returns:
      the value of the variable, or null if the variable was not bound.