Class ProviderItemRegistryDelegate

java.lang.Object
org.openhab.core.automation.module.script.providersupport.shared.ProviderItemRegistryDelegate
All Implemented Interfaces:
org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry, Registry<Item,String>, ItemRegistry

@NonNullByDefault public class ProviderItemRegistryDelegate extends Object implements ItemRegistry, org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
The ProviderItemRegistryDelegate is wrapping a ItemRegistry to provide a comfortable way to provide items from scripts without worrying about the need to remove items again when the script is unloaded. Nonetheless, using the addPermanent(Item) method it is still possible to add items 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<Item> listener)
      Description copied from interface: Registry
      Adds a RegistryChangeListener to the registry.
      Specified by:
      addRegistryChangeListener in interface Registry<Item,String>
      Parameters:
      listener - registry change listener
    • getAll

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

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

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

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

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

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

      public @Nullable Item update(Item element)
      Description copied from interface: Registry
      Updates the given element at the according ManagedProvider.
      Specified by:
      update in interface Registry<Item,String>
      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 Item remove(String key)
      Description copied from interface: Registry
      Removes the given element from the according ManagedProvider.
      Specified by:
      remove in interface Registry<Item,String>
      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
    • getItem

      public Item getItem(String name) throws ItemNotFoundException
      Description copied from interface: ItemRegistry
      This method retrieves a single item from the registry.
      Specified by:
      getItem in interface ItemRegistry
      Parameters:
      name - the item name
      Returns:
      the uniquely identified item
      Throws:
      ItemNotFoundException - if no item matches the input
    • getItemByPattern

      public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException
      Description copied from interface: ItemRegistry
      This method retrieves a single item from the registry. Search patterns and shortened versions are supported, if they uniquely identify an item
      Specified by:
      getItemByPattern in interface ItemRegistry
      Parameters:
      name - the item name, a part of the item name or a search pattern
      Returns:
      the uniquely identified item
      Throws:
      ItemNotFoundException - if no item matches the input
      ItemNotUniqueException - if multiply items match the input
    • getItems

      public Collection<Item> getItems()
      Description copied from interface: ItemRegistry
      This method retrieves all items that are currently available in the registry
      Specified by:
      getItems in interface ItemRegistry
      Returns:
      a collection of all available items
    • getItemsOfType

      public Collection<Item> getItemsOfType(String type)
      Description copied from interface: ItemRegistry
      This method retrieves all items with the given type
      Specified by:
      getItemsOfType in interface ItemRegistry
      Parameters:
      type - item type as defined by ItemFactorys
      Returns:
      a collection of all items of the given type
    • getItems

      public Collection<Item> getItems(String pattern)
      Description copied from interface: ItemRegistry
      This method retrieves all items that match a given search pattern
      Specified by:
      getItems in interface ItemRegistry
      Returns:
      a collection of all items matching the search pattern
    • getItemsByTag

      public Collection<Item> getItemsByTag(String... tags)
      Description copied from interface: ItemRegistry
      Returns list of items which contains all of the given tags.
      Specified by:
      getItemsByTag in interface ItemRegistry
      Parameters:
      tags - array of tags to be present on the returned items.
      Returns:
      list of items which contains all of the given tags.
    • getItemsByTagAndType

      public Collection<Item> getItemsByTagAndType(String type, String... tags)
      Description copied from interface: ItemRegistry
      Returns list of items with a certain type containing all of the given tags.
      Specified by:
      getItemsByTagAndType in interface ItemRegistry
      Parameters:
      type - item type as defined by ItemFactorys
      tags - array of tags to be present on the returned items.
      Returns:
      list of items which contains all of the given tags.
    • getItemsByTag

      public <T extends Item> Collection<T> getItemsByTag(Class<T> typeFilter, String... tags)
      Description copied from interface: ItemRegistry
      Returns list of items which contains all of the given tags.
      Specified by:
      getItemsByTag in interface ItemRegistry
      Parameters:
      typeFilter - subclass of GenericItem to filter the resulting list for.
      tags - array of tags to be present on the returned items.
      Returns:
      list of items which contains all of the given tags, which is filtered by the given type filter.
    • remove

      public @Nullable Item remove(String itemName, boolean recursive)
      Specified by:
      remove in interface ItemRegistry
      See Also:
    • 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