Package org.openhab.core.items
Class ManagedItemProvider
java.lang.Object
org.openhab.core.common.registry.AbstractProvider<Item>
org.openhab.core.common.registry.AbstractManagedProvider<Item,String,ManagedItemProvider.PersistedItem>
org.openhab.core.items.ManagedItemProvider
- All Implemented Interfaces:
ManagedProvider<Item,,String> Provider<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 ItemFactorys.- 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
Nested Classes -
Field Summary
Fields inherited from class org.openhab.core.common.registry.AbstractProvider
listeners -
Constructor Summary
ConstructorsConstructorDescriptionManagedItemProvider(StorageService storageService, ItemBuilderFactory itemBuilderFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an element.protected voidaddItemFactory(ItemFactory itemFactory) protected StringReturns the name of storage, that is used to persist the elements.protected StringkeyToString(String key) Transforms the key into a string representation.@Nullable ItemRemoves an element and returns the removed element.@Nullable ItemRemoves an item and its member if recursive flag is set to true.protected voidremoveItemFactory(ItemFactory itemFactory) protected @Nullable ItemtoElement(String itemName, ManagedItemProvider.PersistedItem persistedItem) Converts the persistable element into the original element.protected ManagedItemProvider.PersistedItemtoPersistableElement(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, updateMethods inherited from class org.openhab.core.common.registry.AbstractProvider
addProviderChangeListener, notifyListenersAboutAddedElement, notifyListenersAboutRemovedElement, notifyListenersAboutUpdatedElement, removeProviderChangeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openhab.core.common.registry.Provider
addProviderChangeListener, getAll, removeProviderChangeListener
-
Constructor Details
-
ManagedItemProvider
-
-
Method Details
-
remove
Description copied from interface:ManagedProviderRemoves an element and returns the removed element.- Specified by:
removein interfaceManagedProvider<Item,String> - Overrides:
removein 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:ManagedProviderAdds an element.- Specified by:
addin interfaceManagedProvider<Item,String> - Overrides:
addin classAbstractManagedProvider<Item,String, ManagedItemProvider.PersistedItem> - Parameters:
element- element to be added
-
addItemFactory
-
removeItemFactory
-
getStorageName
Description copied from class:AbstractManagedProviderReturns the name of storage, that is used to persist the elements.- Specified by:
getStorageNamein classAbstractManagedProvider<Item,String, ManagedItemProvider.PersistedItem> - Returns:
- name of the storage
-
keyToString
Description copied from class:AbstractManagedProviderTransforms the key into a string representation.- Specified by:
keyToStringin 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:AbstractManagedProviderConverts the persistable element into the original element.- Specified by:
toElementin classAbstractManagedProvider<Item,String, ManagedItemProvider.PersistedItem> - Parameters:
itemName- keypersistedItem- persistable element- Returns:
- original element
-
toPersistableElement
Description copied from class:AbstractManagedProviderConverts the original element into an element that can be persisted.- Specified by:
toPersistableElementin classAbstractManagedProvider<Item,String, ManagedItemProvider.PersistedItem> - Parameters:
item- original element- Returns:
- persistable element
-