Package org.openhab.core.common.registry
Class AbstractManagedProvider<E extends Identifiable<K>,K,PE>
java.lang.Object
org.openhab.core.common.registry.AbstractProvider<E>
org.openhab.core.common.registry.AbstractManagedProvider<E,K,PE>
- Type Parameters:
E
- type of the elementK
- type of the element keyPE
- type of the persistable element
- All Implemented Interfaces:
ManagedProvider<E,
,K> Provider<E>
- Direct Known Subclasses:
DefaultAbstractManagedProvider
,ManagedItemProvider
,ManagedPersistenceServiceConfigurationProvider
,ManagedRuleProvider
,ManagedSemanticTagProvider
,ManagedThingProvider
,ManagedTransformationProvider
@NonNullByDefault
public abstract class AbstractManagedProvider<@NonNull E extends Identifiable<@NonNull K>,@NonNull K,@NonNull PE>
extends AbstractProvider<E>
implements ManagedProvider<E,K>
AbstractManagedProvider
is an abstract implementation for the ManagedProvider
interface and can be
used as base class for ManagedProvider
implementations. It uses the StorageService
to persist the
elements.
It provides the possibility to transform the element into another java class, that can be persisted. This is needed,
if the original element class is not directly persistable. If the element type can be persisted directly the
DefaultAbstractManagedProvider
can be used as base class.
- Author:
- Dennis Nobel - Initial contribution
-
Field Summary
Fields inherited from class org.openhab.core.common.registry.AbstractProvider
listeners
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element.@Nullable E
Returns an element for the given key or null if no element for the given key exists.getAll()
Returns a collection of all elements.protected abstract String
Returns the name of storage, that is used to persist the elements.protected abstract String
keyToString
(@NonNull K key) Transforms the key into a string representation.@Nullable E
Removes an element and returns the removed element.protected abstract @Nullable E
Converts the persistable element into the original element.protected abstract PE
toPersistableElement
(@NonNull E element) Converts the original element into an element that can be persisted.@Nullable E
Updates an element.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, removeProviderChangeListener
-
Field Details
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
AbstractManagedProvider
-
-
Method Details
-
add
Description copied from interface:ManagedProvider
Adds an element.- Specified by:
add
in interfaceManagedProvider<E extends Identifiable<K>,
K> - Parameters:
element
- element to be added
-
getAll
Description copied from interface:Provider
Returns a collection of all elements.- Specified by:
getAll
in interfaceProvider<E extends Identifiable<K>>
- Returns:
- collection of all elements
-
get
Description copied from interface:ManagedProvider
Returns an element for the given key or null if no element for the given key exists.- Specified by:
get
in interfaceManagedProvider<E extends Identifiable<K>,
K> - Parameters:
key
- key- Returns:
- returns element or null, if no element for the given key exists
-
remove
Description copied from interface:ManagedProvider
Removes an element and returns the removed element.- Specified by:
remove
in interfaceManagedProvider<E extends Identifiable<K>,
K> - 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
-
update
Description copied from interface:ManagedProvider
Updates an element.- Specified by:
update
in interfaceManagedProvider<E extends Identifiable<K>,
K> - Parameters:
element
- element to be updated- Returns:
- returns the old element or null if no element with the same key exists
-
getStorageName
Returns the name of storage, that is used to persist the elements.- Returns:
- name of the storage
-
keyToString
Transforms the key into a string representation.- Parameters:
key
- key- Returns:
- string representation of the key
-
toElement
Converts the persistable element into the original element.- Parameters:
key
- keypersistableElement
- persistable element- Returns:
- original element
-
toPersistableElement
Converts the original element into an element that can be persisted.- Parameters:
element
- original element- Returns:
- persistable element
-