replaced last DS XML by annotations (#397)
Correctly register ItemRegistry service Signed-off-by: Kai Kreuzer <kai@openhab.org>pull/399/head
parent
8091914a4b
commit
b48e50b7a1
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (c) 2015-2018 by the respective copyright holders.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
which accompanies this distribution, and is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
-->
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.openhab.core.compat1x.persistenceservicefactory">
|
||||
<implementation class="org.openhab.core.persistence.internal.PersistenceServiceFactory"/>
|
||||
<reference bind="addPersistenceService" cardinality="0..n" interface="org.openhab.core.persistence.PersistenceService" name="PersistenceService" policy="dynamic" unbind="removePersistenceService"/>
|
||||
</scr:component>
|
|
@ -19,6 +19,7 @@ import org.openhab.core.compat1x.internal.ItemMapper;
|
|||
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 @@ import org.osgi.service.component.annotations.Reference;
|
|||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@Component(immediate = true)
|
||||
@Component(service = { ItemRegistry.class, ItemUIRegistry.class })
|
||||
public class ItemUIRegistryDelegate
|
||||
implements ItemUIRegistry, RegistryChangeListener<org.eclipse.smarthome.core.items.Item> {
|
||||
|
||||
|
|
|
@ -18,6 +18,12 @@ import java.util.Set;
|
|||
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 @@ import org.osgi.framework.ServiceRegistration;
|
|||
*
|
||||
* @author Kai Kreuzer - Initial contribution and API
|
||||
*/
|
||||
@Component(immediate = true)
|
||||
public class PersistenceServiceFactory {
|
||||
|
||||
private Map<String, ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService>> delegates = new HashMap<>();
|
||||
|
@ -32,6 +39,7 @@ public class PersistenceServiceFactory {
|
|||
|
||||
private Set<PersistenceService> persistenceServices = new HashSet<>();
|
||||
|
||||
@Activate
|
||||
public void activate(BundleContext context) {
|
||||
this.context = context;
|
||||
for (PersistenceService service : persistenceServices) {
|
||||
|
@ -39,6 +47,7 @@ public class PersistenceServiceFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
for (ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService> serviceReg : delegates
|
||||
.values()) {
|
||||
|
@ -48,6 +57,7 @@ public class PersistenceServiceFactory {
|
|||
this.context = null;
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
|
||||
public void addPersistenceService(PersistenceService service) {
|
||||
if (context != null) {
|
||||
registerDelegateService(service);
|
||||
|
|
Loading…
Reference in New Issue