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
-
Field Summary
Fields inherited from interface org.openhab.core.items.MetadataRegistry
INTERNAL_NAMESPACE_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionProviderMetadataRegistryDelegate(MetadataRegistry metadataRegistry, ScriptedMetadataProvider scriptedProvider) -
Method Summary
Modifier and TypeMethodDescriptionAdds the given element to the accordingManagedProvider.addPermanent(Metadata element) Adds metadata permanently to the registry.voidAdds aRegistryChangeListenerto the registry.@Nullable Metadataget(MetadataKey key) This method retrieves a single element from the registry.getAll()Returns a collection of all elements in the registry.getAllNamespaces(String itemname) Provides all namespaces of a particular itembooleanisInternalNamespace(String namespace) Determines whether the given namespace is internal.@Nullable Metadataremove(MetadataKey key) Removes the given element from the accordingManagedProvider.voidRemoves all elements that are provided by the script theProviderRegistryinstance is bound to.voidremoveItemMetadata(String itemname) Remove all metadata of a given itemvoidRemoves aRegistryChangeListenerfrom the registry.stream()Returns a stream of all elements in the registry.@Nullable MetadataUpdates the given element at the accordingManagedProvider.
-
Constructor Details
-
Method Details
-
addRegistryChangeListener
Description copied from interface:RegistryAdds aRegistryChangeListenerto the registry.- Specified by:
addRegistryChangeListenerin interfaceRegistry<Metadata,MetadataKey> - Parameters:
listener- registry change listener
-
getAll
Description copied from interface:RegistryReturns a collection of all elements in the registry.- Specified by:
getAllin interfaceRegistry<Metadata,MetadataKey> - Returns:
- collection of all elements in the registry
-
stream
Description copied from interface:RegistryReturns a stream of all elements in the registry.- Specified by:
streamin interfaceRegistry<Metadata,MetadataKey> - Returns:
- stream of all elements in the registry
-
get
Description copied from interface:RegistryThis method retrieves a single element from the registry.- Specified by:
getin interfaceRegistry<Metadata,MetadataKey> - Parameters:
key- key of the element- Returns:
- element or null if no element was found
-
removeRegistryChangeListener
Description copied from interface:RegistryRemoves aRegistryChangeListenerfrom the registry.- Specified by:
removeRegistryChangeListenerin interfaceRegistry<Metadata,MetadataKey> - Parameters:
listener- registry change listener
-
add
Description copied from interface:RegistryAdds the given element to the accordingManagedProvider.- Specified by:
addin interfaceRegistry<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
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
Description copied from interface:RegistryUpdates the given element at the accordingManagedProvider.- Specified by:
updatein interfaceRegistry<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
Description copied from interface:RegistryRemoves the given element from the accordingManagedProvider.- Specified by:
removein interfaceRegistry<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
Description copied from interface:MetadataRegistryDetermines whether the given namespace is internal.- Specified by:
isInternalNamespacein interfaceMetadataRegistry- Parameters:
namespace- the metadata namespace to check- Returns:
trueif the given namespace is internal,falseotherwise
-
getAllNamespaces
Description copied from interface:MetadataRegistryProvides all namespaces of a particular item- Specified by:
getAllNamespacesin interfaceMetadataRegistry- Parameters:
itemname- the name of the item for which the namespaces should be searched.
-
removeItemMetadata
Description copied from interface:MetadataRegistryRemove all metadata of a given item- Specified by:
removeItemMetadatain interfaceMetadataRegistry- 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.ProviderRegistryRemoves all elements that are provided by the script theProviderRegistryinstance is bound to. To be called when the script is unloaded or reloaded.- Specified by:
removeAllAddedByScriptin interfaceorg.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
-