Class ProviderMetadataRegistryDelegate

java.lang.Object
org.openhab.core.automation.module.script.providersupport.shared.ProviderMetadataRegistryDelegate
All Implemented Interfaces:
org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry, Registry<Metadata,MetadataKey>, MetadataRegistry

@NonNullByDefault public class ProviderMetadataRegistryDelegate extends Object implements MetadataRegistry, org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
The ProviderMetadataRegistryDelegate is wrapping a MetadataRegistry to provide a comfortable way to provide items from scripts without worrying about the need to remove metadata again when the script is unloaded. Nonetheless, using the addPermanent(Metadata) method it is still possible to add metadata permanently.

Use a new instance of this class for each ScriptEngine.

Author:
Florian Hotze - Initial contribution
  • Constructor Details

  • Method Details

    • addRegistryChangeListener

      public void addRegistryChangeListener(RegistryChangeListener<Metadata> listener)
      Description copied from interface: Registry
      Adds a RegistryChangeListener to the registry.
      Specified by:
      addRegistryChangeListener in interface Registry<Metadata,MetadataKey>
      Parameters:
      listener - registry change listener
    • getAll

      public Collection<Metadata> getAll()
      Description copied from interface: Registry
      Returns a collection of all elements in the registry.
      Specified by:
      getAll in interface Registry<Metadata,MetadataKey>
      Returns:
      collection of all elements in the registry
    • stream

      public Stream<Metadata> stream()
      Description copied from interface: Registry
      Returns a stream of all elements in the registry.
      Specified by:
      stream in interface Registry<Metadata,MetadataKey>
      Returns:
      stream of all elements in the registry
    • get

      public @Nullable Metadata get(MetadataKey key)
      Description copied from interface: Registry
      This method retrieves a single element from the registry.
      Specified by:
      get in interface Registry<Metadata,MetadataKey>
      Parameters:
      key - key of the element
      Returns:
      element or null if no element was found
    • removeRegistryChangeListener

      public void removeRegistryChangeListener(RegistryChangeListener<Metadata> listener)
      Description copied from interface: Registry
      Removes a RegistryChangeListener from the registry.
      Specified by:
      removeRegistryChangeListener in interface Registry<Metadata,MetadataKey>
      Parameters:
      listener - registry change listener
    • add

      public Metadata add(Metadata element)
      Description copied from interface: Registry
      Adds the given element to the according ManagedProvider.
      Specified by:
      add in interface Registry<Metadata,MetadataKey>
      Parameters:
      element - element to be added (must not be null)
      Returns:
      the added element or newly created object of the same type
    • addPermanent

      public Metadata addPermanent(Metadata element)
      Adds metadata permanently to the registry. This metadata will be kept in the registry even if the script is unloaded.
      Parameters:
      element - the metadata to be added (must not be null)
      Returns:
      the added metadata
    • update

      public @Nullable Metadata update(Metadata element)
      Description copied from interface: Registry
      Updates the given element at the according ManagedProvider.
      Specified by:
      update in interface Registry<Metadata,MetadataKey>
      Parameters:
      element - element to be updated (must not be null)
      Returns:
      returns the old element or null if no element with the same key exists
    • remove

      public @Nullable Metadata remove(MetadataKey key)
      Description copied from interface: Registry
      Removes the given element from the according ManagedProvider.
      Specified by:
      remove in interface Registry<Metadata,MetadataKey>
      Parameters:
      key - key of the element (must not be null)
      Returns:
      element that was removed, or null if no element with the given key exists
    • isInternalNamespace

      public boolean isInternalNamespace(String namespace)
      Description copied from interface: MetadataRegistry
      Determines whether the given namespace is internal.
      Specified by:
      isInternalNamespace in interface MetadataRegistry
      Parameters:
      namespace - the metadata namespace to check
      Returns:
      true if the given namespace is internal, false otherwise
    • getAllNamespaces

      public Collection<String> getAllNamespaces(String itemname)
      Description copied from interface: MetadataRegistry
      Provides all namespaces of a particular item
      Specified by:
      getAllNamespaces in interface MetadataRegistry
      Parameters:
      itemname - the name of the item for which the namespaces should be searched.
    • removeItemMetadata

      public void removeItemMetadata(String itemname)
      Description copied from interface: MetadataRegistry
      Remove all metadata of a given item
      Specified by:
      removeItemMetadata in interface MetadataRegistry
      Parameters:
      itemname - the name of the item for which the metadata is to be removed.
    • removeAllAddedByScript

      public void removeAllAddedByScript()
      Description copied from interface: org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
      Removes all elements that are provided by the script the ProviderRegistry instance is bound to. To be called when the script is unloaded or reloaded.
      Specified by:
      removeAllAddedByScript in interface org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry