mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
Added constructor injection to config xml (#1168)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
3ae82d1558
commit
80dce80ad9
@ -16,6 +16,8 @@ import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescription;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescriptionProvider;
|
||||
import org.eclipse.smarthome.config.core.i18n.ConfigI18nLocalizationService;
|
||||
@ -40,25 +42,30 @@ import org.osgi.service.component.annotations.Reference;
|
||||
* @author Simon Kaufmann - Initial contribution
|
||||
*/
|
||||
@Component(service = ConfigDescriptionProvider.class, immediate = true, property = { "esh.scope=core.xml.config" })
|
||||
@NonNullByDefault
|
||||
public class ConfigXmlConfigDescriptionProvider extends AbstractXmlConfigDescriptionProvider
|
||||
implements XmlDocumentProviderFactory<List<ConfigDescription>> {
|
||||
|
||||
private static final String XML_DIRECTORY = "/ESH-INF/config/";
|
||||
public static final String READY_MARKER = "esh.xmlConfig";
|
||||
|
||||
private XmlDocumentBundleTracker<List<ConfigDescription>> configDescriptionTracker;
|
||||
|
||||
private ConfigI18nLocalizationService configI18nLocalizerService;
|
||||
private ReadyService readyService;
|
||||
|
||||
private ScheduledExecutorService scheduler = ThreadPoolManager
|
||||
private final ConfigI18nLocalizationService configI18nService;
|
||||
private @Nullable XmlDocumentBundleTracker<List<ConfigDescription>> configDescriptionTracker;
|
||||
private final ReadyService readyService;
|
||||
private final ScheduledExecutorService scheduler = ThreadPoolManager
|
||||
.getScheduledPool(XmlDocumentBundleTracker.THREAD_POOL_NAME);
|
||||
private Future<?> trackerJob;
|
||||
private @Nullable Future<?> trackerJob;
|
||||
|
||||
@Activate
|
||||
public ConfigXmlConfigDescriptionProvider(final @Reference ConfigI18nLocalizationService configI18nService,
|
||||
final @Reference ReadyService readyService) {
|
||||
this.configI18nService = configI18nService;
|
||||
this.readyService = readyService;
|
||||
}
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
XmlDocumentReader<List<ConfigDescription>> configDescriptionReader = new ConfigDescriptionReader();
|
||||
|
||||
configDescriptionTracker = new XmlDocumentBundleTracker<>(componentContext.getBundleContext(), XML_DIRECTORY,
|
||||
configDescriptionReader, this, READY_MARKER, readyService);
|
||||
trackerJob = scheduler.submit(() -> {
|
||||
@ -68,40 +75,25 @@ public class ConfigXmlConfigDescriptionProvider extends AbstractXmlConfigDescrip
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
if (trackerJob != null && !trackerJob.isDone()) {
|
||||
trackerJob.cancel(true);
|
||||
Future<?> localTrackerJob = trackerJob;
|
||||
if (localTrackerJob != null && !localTrackerJob.isDone()) {
|
||||
localTrackerJob.cancel(true);
|
||||
trackerJob = null;
|
||||
}
|
||||
configDescriptionTracker.close();
|
||||
configDescriptionTracker = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) {
|
||||
this.configI18nLocalizerService = configI18nLocalizerService;
|
||||
}
|
||||
|
||||
public void unsetConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) {
|
||||
this.configI18nLocalizerService = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setReadyService(ReadyService readyService) {
|
||||
this.readyService = readyService;
|
||||
}
|
||||
|
||||
public void unsetReadyService(ReadyService readyService) {
|
||||
this.readyService = null;
|
||||
XmlDocumentBundleTracker<List<ConfigDescription>> localConfigDescriptionTracker = configDescriptionTracker;
|
||||
if (localConfigDescriptionTracker != null) {
|
||||
localConfigDescriptionTracker.close();
|
||||
configDescriptionTracker = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigI18nLocalizationService getConfigI18nLocalizerService() {
|
||||
return configI18nLocalizerService;
|
||||
return configI18nService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlDocumentProvider<List<ConfigDescription>> createDocumentProvider(Bundle bundle) {
|
||||
return new ConfigDescriptionXmlProvider(bundle, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user