Package org.openhab.core.items
Class ManagedItemProvider
java.lang.Object
org.openhab.core.common.registry.AbstractProvider<E>
org.openhab.core.common.registry.AbstractManagedProvider<Item,String,ManagedItemProvider.PersistedItem>
org.openhab.core.items.ManagedItemProvider
- All Implemented Interfaces:
ManagedProvider<Item,
,String> Provider<@NonNull Item>
,ItemProvider
@NonNullByDefault
public class ManagedItemProvider
extends AbstractManagedProvider<Item,String,ManagedItemProvider.PersistedItem>
implements ItemProvider
ManagedItemProvider
is an OSGi service, that allows to add or remove
items at runtime by calling add(org.openhab.core.items.Item)
or remove(java.lang.String)
.
An added item is automatically
exposed to the ItemRegistry
. Persistence of added Items is handled by
a StorageService
. Items are being restored using the given ItemFactory
s.- Author:
- Dennis Nobel - Initial contribution, added support for GroupItems, Thomas Eichstaedt-Engelen - Initial contribution, Kai Kreuzer - improved return values, Alex Tugarev - added tags
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.openhab.core.common.registry.AbstractProvider
listeners
-
Constructor Summary
ConstructorDescriptionManagedItemProvider
(StorageService storageService, ItemBuilderFactory itemBuilderFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element.protected void
addItemFactory
(ItemFactory itemFactory) protected String
Returns the name of storage, that is used to persist the elements.protected String
keyToString
(String key) Transforms the key into a string representation.@Nullable Item
Removes an element and returns the removed element.@Nullable Item
Removes an item and its member if recursive flag is set to true.protected void
removeItemFactory
(ItemFactory itemFactory) protected @Nullable Item
toElement
(String itemName, ManagedItemProvider.PersistedItem persistedItem) Converts the persistable element into the original element.protected ManagedItemProvider.PersistedItem
toPersistableElement
(Item item) Converts the original element into an element that can be persisted.Methods inherited from class org.openhab.core.common.registry.AbstractManagedProvider
get, getAll, update
Methods inherited from class org.openhab.core.common.registry.AbstractProvider
addProviderChangeListener, notifyListenersAboutAddedElement, notifyListenersAboutRemovedElement, notifyListenersAboutUpdatedElement, removeProviderChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openhab.core.common.registry.Provider
addProviderChangeListener, getAll, removeProviderChangeListener
-
Constructor Details
-
ManagedItemProvider
-
-
Method Details
-
remove
Description copied from interface:ManagedProvider
Removes an element and returns the removed element.- Specified by:
remove
in interfaceManagedProvider<Item,
String> - Overrides:
remove
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Parameters:
key
- key of the element that should be removed- Returns:
- element that was removed, or null if no element with the given key exists
-
remove
Removes an item and its member if recursive flag is set to true.- Parameters:
itemName
- item name to removerecursive
- if set to true all members of the item will be removed, too.- Returns:
- removed item or null if no item with that name exists
-
add
Description copied from interface:ManagedProvider
Adds an element.- Specified by:
add
in interfaceManagedProvider<Item,
String> - Overrides:
add
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Parameters:
element
- element to be added
-
addItemFactory
-
removeItemFactory
-
getStorageName
Description copied from class:AbstractManagedProvider
Returns the name of storage, that is used to persist the elements.- Specified by:
getStorageName
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Returns:
- name of the storage
-
keyToString
Description copied from class:AbstractManagedProvider
Transforms the key into a string representation.- Specified by:
keyToString
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Parameters:
key
- key- Returns:
- string representation of the key
-
toElement
protected @Nullable Item toElement(String itemName, ManagedItemProvider.PersistedItem persistedItem) Description copied from class:AbstractManagedProvider
Converts the persistable element into the original element.- Specified by:
toElement
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Parameters:
itemName
- keypersistedItem
- persistable element- Returns:
- original element
-
toPersistableElement
Description copied from class:AbstractManagedProvider
Converts the original element into an element that can be persisted.- Specified by:
toPersistableElement
in classAbstractManagedProvider<Item,
String, ManagedItemProvider.PersistedItem> - Parameters:
item
- original element- Returns:
- persistable element
-