Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced last DS XML by annotations and correctly register ItemRegistry service #397

Merged
merged 1 commit into from Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

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
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