Class LifecycleScriptExtensionProvider

java.lang.Object
org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider
All Implemented Interfaces:
ScriptExtensionProvider

@NonNullByDefault public class LifecycleScriptExtensionProvider extends Object implements ScriptExtensionProvider
ScriptExtensionProvider which providers a 'lifecycleTracker' object allowing scripts to register for disposal events.
Author:
Jonathan Gilbert - Initial contribution
  • Constructor Details

    • LifecycleScriptExtensionProvider

      public LifecycleScriptExtensionProvider()
  • Method Details

    • getDefaultPresets

      public Collection<String> getDefaultPresets()
      Description copied from interface: ScriptExtensionProvider
      These presets will always get injected into the ScriptEngine on instance creation.
      Specified by:
      getDefaultPresets in interface ScriptExtensionProvider
      Returns:
      collection of presets
    • getPresets

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

      public Collection<String> getTypes()
      Description copied from interface: ScriptExtensionProvider
      Returns the supported types which can be received by the given ScriptExtensionProvider
      Specified by:
      getTypes in interface ScriptExtensionProvider
      Returns:
      provided types
    • get

      public @Nullable Object get(String scriptIdentifier, String type) throws IllegalArgumentException
      Description copied from interface: ScriptExtensionProvider
      This method should return an Object of the given type. Note: get can be called multiple times in the scripts use caching where appropriate.
      Specified by:
      get in interface ScriptExtensionProvider
      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

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

      public void unload(String scriptIdentifier)
      Description copied from interface: ScriptExtensionProvider
      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.
      Specified by:
      unload in interface ScriptExtensionProvider
      Parameters:
      scriptIdentifier - the identifier of the script that is unloaded