Interface ScriptExtensionProvider

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

      • getDefaultPresets

        Collection<String> getDefaultPresets()
        These presets will always get injected into the ScriptEngine on instance creation.
        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".
        provided presets
      • getTypes

        Collection<String> getTypes()
        Returns the supported types which can be received by the given ScriptExtensionProvider
        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.
        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
        the requested type or null
        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.
        scriptIdentifier - the identifier of the script that receives the preset
        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.
        scriptIdentifier - the identifier of the script that is unloaded