Class AbstractScript

java.lang.Object
org.tentackle.script.AbstractScript
All Implemented Interfaces:
Script

public abstract class AbstractScript extends Object implements Script
Abstract implementation of a script.
Author:
harald
  • Constructor Details

    • AbstractScript

      public AbstractScript(ScriptingLanguage language, String code, boolean cached, boolean threadSafe)
      Creates a script.
      Parameters:
      language - the language instance
      code - the scripting code
      cached - true to use caching, if possible
      threadSafe - true if thread-safety is required
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLanguage

      public ScriptingLanguage getLanguage()
      Description copied from interface: Script
      Gets the scripting language.
      Specified by:
      getLanguage in interface Script
      Returns:
      the language
    • isThreadSafe

      public boolean isThreadSafe()
      Description copied from interface: Script
      Returns whether script may be invoked from more than one thread in parallel.
      Specified by:
      isThreadSafe in interface Script
      Returns:
      true if thread-safe execution required, false if parallel execution allowed
    • isCached

      public boolean isCached()
      Description copied from interface: Script
      Returns whether there is only one compiled script for the same code.
      Specified by:
      isCached in interface Script
      Returns:
      true if cached
    • getCode

      public String getCode()
      Description copied from interface: Script
      Gets the scripting source code.
      Specified by:
      getCode in interface Script
      Returns:
      the code
    • execute

      public <T> T execute(ScriptVariable... variables)
      Description copied from interface: Script
      Executes a script.

      Throws ScriptRuntimeException if execution failed.
      Throws IllegalArgumentException if there are any duplicate variable names.

      Specified by:
      execute in interface Script
      Type Parameters:
      T - the result type
      Parameters:
      variables - the optional script variables
      Returns:
      the evaluated value, null if none