From b48e50b7a11f171aae778382d3871eb9de41f523 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Tue, 11 Sep 2018 11:43:01 +0200 Subject: [PATCH] replaced last DS XML by annotations (#397) Correctly register ItemRegistry service Signed-off-by: Kai Kreuzer --- .../OSGI-INF/persistenceservicefactory.xml | 15 --------------- .../items/internal/ItemUIRegistryDelegate.java | 3 ++- .../internal/PersistenceServiceFactory.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 bundles/org.openhab.core.compat1x/OSGI-INF/persistenceservicefactory.xml diff --git a/bundles/org.openhab.core.compat1x/OSGI-INF/persistenceservicefactory.xml b/bundles/org.openhab.core.compat1x/OSGI-INF/persistenceservicefactory.xml deleted file mode 100644 index 5fb90b090d1..00000000000 --- a/bundles/org.openhab.core.compat1x/OSGI-INF/persistenceservicefactory.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java index d19a0585082..226c8d0ae52 100644 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java +++ b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java @@ -19,6 +19,7 @@ import org.openhab.core.items.Item; import org.openhab.core.items.ItemNotFoundException; import org.openhab.core.items.ItemNotUniqueException; +import org.openhab.core.items.ItemRegistry; import org.openhab.core.items.ItemRegistryChangeListener; import org.openhab.core.types.State; import org.openhab.model.sitemap.LinkableWidget; @@ -32,7 +33,7 @@ * * @author Kai Kreuzer - Initial contribution */ -@Component(immediate = true) +@Component(service = { ItemRegistry.class, ItemUIRegistry.class }) public class ItemUIRegistryDelegate implements ItemUIRegistry, RegistryChangeListener { diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java index c59426429ef..b95f2f17979 100644 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java +++ b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java @@ -18,6 +18,12 @@ import org.openhab.core.persistence.PersistenceService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; /** * This class listens for services that implement the old persistence service interface and registers @@ -25,6 +31,7 @@ * * @author Kai Kreuzer - Initial contribution and API */ +@Component(immediate = true) public class PersistenceServiceFactory { private Map> delegates = new HashMap<>(); @@ -32,6 +39,7 @@ public class PersistenceServiceFactory { private Set persistenceServices = new HashSet<>(); + @Activate public void activate(BundleContext context) { this.context = context; for (PersistenceService service : persistenceServices) { @@ -39,6 +47,7 @@ public void activate(BundleContext context) { } } + @Deactivate public void deactivate() { for (ServiceRegistration serviceReg : delegates .values()) { @@ -48,6 +57,7 @@ public void deactivate() { this.context = null; } + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) public void addPersistenceService(PersistenceService service) { if (context != null) { registerDelegateService(service);