Skip to content

Commit

Permalink
replaced last DS XML by annotations (openhab#397)
Browse files Browse the repository at this point in the history
Correctly register ItemRegistry service

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer authored and martinvw committed Sep 11, 2018
1 parent 8091914 commit b48e50b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +33,7 @@
*
* @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> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,36 @@
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
* an according service for each under the new interface.
*
* @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<>();
private BundleContext context;

private Set<PersistenceService> persistenceServices = new HashSet<>();

@Activate
public void activate(BundleContext context) {
this.context = context;
for (PersistenceService service : persistenceServices) {
registerDelegateService(service);
}
}

@Deactivate
public void deactivate() {
for (ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService> serviceReg : delegates
.values()) {
Expand All @@ -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);
Expand Down

0 comments on commit b48e50b

Please sign in to comment.