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.void
Adds aRegistryChangeListener
to the registry.@Nullable Metadata
get
(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 itemboolean
isInternalNamespace
(String namespace) Determines whether the given namespace is internal.@Nullable Metadata
remove
(MetadataKey key) Removes the given element from the accordingManagedProvider
.void
Removes all elements that are provided by the script theProviderRegistry
instance is bound to.void
removeItemMetadata
(String itemname) Remove all metadata of a given itemvoid
Removes aRegistryChangeListener
from the registry.stream()
Returns a stream of all elements in the registry.@Nullable Metadata
Updates the given element at the accordingManagedProvider
.
-
Constructor Details
-
Method Details
-
addRegistryChangeListener
Description copied from interface:Registry
Adds aRegistryChangeListener
to the registry.- Specified by:
addRegistryChangeListener
in interfaceRegistry<Metadata,
MetadataKey> - Parameters:
listener
- registry change listener
-
getAll
Description copied from interface:Registry
Returns a collection of all elements in the registry.- Specified by:
getAll
in interfaceRegistry<Metadata,
MetadataKey> - Returns:
- collection of all elements in the registry
-
stream
Description copied from interface:Registry
Returns a stream of all elements in the registry.- Specified by:
stream
in interfaceRegistry<Metadata,
MetadataKey> - Returns:
- stream of all elements in the registry
-
get
Description copied from interface:Registry
This method retrieves a single element from the registry.- Specified by:
get
in interfaceRegistry<Metadata,
MetadataKey> - Parameters:
key
- key of the element- Returns:
- element or null if no element was found
-
removeRegistryChangeListener
Description copied from interface:Registry
Removes aRegistryChangeListener
from the registry.- Specified by:
removeRegistryChangeListener
in interfaceRegistry<Metadata,
MetadataKey> - Parameters:
listener
- registry change listener
-
add
Description copied from interface:Registry
Adds the given element to the accordingManagedProvider
.- Specified by:
add
in 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:Registry
Updates the given element at the accordingManagedProvider
.- Specified by:
update
in 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:Registry
Removes the given element from the accordingManagedProvider
.- Specified by:
remove
in 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:MetadataRegistry
Determines whether the given namespace is internal.- Specified by:
isInternalNamespace
in interfaceMetadataRegistry
- Parameters:
namespace
- the metadata namespace to check- Returns:
true
if the given namespace is internal,false
otherwise
-
getAllNamespaces
Description copied from interface:MetadataRegistry
Provides all namespaces of a particular item- Specified by:
getAllNamespaces
in interfaceMetadataRegistry
- Parameters:
itemname
- the name of the item for which the namespaces should be searched.
-
removeItemMetadata
Description copied from interface:MetadataRegistry
Remove all metadata of a given item- Specified by:
removeItemMetadata
in 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.ProviderRegistry
Removes all elements that are provided by the script theProviderRegistry
instance is bound to. To be called when the script is unloaded or reloaded.- Specified by:
removeAllAddedByScript
in interfaceorg.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
-