Interface ScriptFactory

All Known Implementing Classes:
DefaultScriptFactory, JSR223ScriptFactory

public interface ScriptFactory
A factory for scripts.
Author:
harald
  • Method Details

    • getInstance

      static ScriptFactory getInstance()
      The singleton.
      Returns:
      the singleton
    • setDefaultLanguage

      void setDefaultLanguage(String abbreviation)
      Sets the default language.

      Throws ScriptRuntimeException if no such language.

      Parameters:
      abbreviation - the abbreviation for the default language
    • setDefaultLanguage

      void setDefaultLanguage(ScriptingLanguage language)
      Sets the default language.
      Parameters:
      language - the language
    • getDefaultLanguage

      ScriptingLanguage getDefaultLanguage()
      Gets the default language.
      Returns:
      the default language, null if none
    • getLanguage

      ScriptingLanguage getLanguage(String abbreviation)
      Gets the scripting language.

      Throws ScriptRuntimeException if no such language.

      Parameters:
      abbreviation - one of the abbreviations for that language, null or empty string if default language
      Returns:
      the language, never null
    • isLanguageAvailable

      boolean isLanguageAvailable(String abbreviation)
      Check if a scripting language is available.
      Parameters:
      abbreviation - one of the abbreviations for that language, null or empty string if default language
      Returns:
      true if the scripting language is available
    • getLanguages

      Set<ScriptingLanguage> getLanguages()
      Gets all scripting languages.
      Returns:
      the languages
    • createScript

      Script createScript(String abbreviation, String code, boolean cached, boolean threadSafe, Function<String, ScriptConverter> converterProvider)
      Creates a script object.

      Scripts will be cached to optimize memory consumption and performance, if cached=true. The same source code will refer to the same compiled evaluation unit. The implementation may still return a new Script instance if caching not supported by the language or the caching refers to class instances instead of objects. Caching should not be used for scripts that are executed only once.

      If there are chances that scripts are invoked from different threads at a time, all scripts must be executed in a thread-safe manner. Although some languages are threadsafe by design, others may need some extra synchronization. If in doubt, set threadSafe to true

      An optional function provides a ScriptConverter for the given scripting language to translate the code before being compiled.

      Notice that the script will be compiled when first used. To compile it without execution, invoke Script.validate().

      Throws ScriptRuntimeException if creating the script failed.

      Parameters:
      abbreviation - the scripting language abbreviation, null or empty for default language
      code - the scripting code
      cached - the same code should refer to the same compiled script object
      threadSafe - true if script may be used by more than one thread in parallel
      converterProvider - the optional script converter provider
      Returns:
      the script, never null