Interface ScriptExtensionProvider

All Known Implementing Classes:
LifecycleScriptExtensionProvider

@NonNullByDefault public interface ScriptExtensionProvider
A ScriptExtensionProvider can provide variable and types on ScriptEngine instance basis.
Author:
Simon Merschjohann - Initial contribution
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Object
    get(String scriptIdentifier, String type)
    This method should return an Object of the given type.
    These presets will always get injected into the ScriptEngine on instance creation.
    Returns the provided Presets which are supported by this ScriptExtensionProvider.
    Returns the supported types which can be received by the given ScriptExtensionProvider
    importPreset(String scriptIdentifier, String preset)
    This method should return variables and types of the concrete type which will be injected into the ScriptEngines scope.
    void
    unload(String scriptIdentifier)
    This will be called when the ScriptEngine will be unloaded (e.g.
  • Method Details

    • getDefaultPresets

      Collection<String> getDefaultPresets()
      These presets will always get injected into the ScriptEngine on instance creation.
      Returns:
      collection of presets
    • getPresets

      Collection<String> getPresets()
      Returns the provided Presets which are supported by this ScriptExtensionProvider. Presets define imports which will be injected into the ScriptEngine if called by "importPreset".
      Returns:
      provided presets
    • getTypes

      Collection<String> getTypes()
      Returns the supported types which can be received by the given ScriptExtensionProvider
      Returns:
      provided types
    • get

      @Nullable Object get(String scriptIdentifier, String type) throws IllegalArgumentException
      This method should return an Object of the given type. Note: get can be called multiple times in the scripts use caching where appropriate.
      Parameters:
      scriptIdentifier - the identifier of the script that requests the given type
      type - the type that is requested (must be part of the collection returned by the #getTypes() method
      Returns:
      the requested type or null
      Throws:
      IllegalArgumentException - if the given type does not match to one returned by the #getTypes() method
    • importPreset

      Map<String,Object> importPreset(String scriptIdentifier, String preset)
      This method should return variables and types of the concrete type which will be injected into the ScriptEngines scope.
      Parameters:
      scriptIdentifier - the identifier of the script that receives the preset
      Returns:
      the presets, must be non-null (use an empty map instead)
    • unload

      void unload(String scriptIdentifier)
      This will be called when the ScriptEngine will be unloaded (e.g. if the Script is deleted or updated). Every Context information stored in the ScriptExtensionProvider should be removed.
      Parameters:
      scriptIdentifier - the identifier of the script that is unloaded