mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
[xml] Feature thing xml constructor injection (#1167)
* Added contructor injection to thing xml * Removed Nullable from getChannels and getChannelGroups Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
committed by
Kai Kreuzer
parent
12d91f7da9
commit
45602fa184
+8
-10
@@ -12,10 +12,12 @@
|
||||
*/
|
||||
package org.eclipse.smarthome.core.thing.xml.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescription;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescriptionProvider;
|
||||
import org.eclipse.smarthome.config.core.i18n.ConfigI18nLocalizationService;
|
||||
import org.eclipse.smarthome.config.xml.AbstractXmlConfigDescriptionProvider;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@@ -25,22 +27,18 @@ import org.osgi.service.component.annotations.Reference;
|
||||
* @author Simon Kaufmann - Initial contribution
|
||||
*/
|
||||
@Component(service = ConfigDescriptionProvider.class, immediate = true, property = { "esh.scope=core.xml.thing" })
|
||||
@NonNullByDefault
|
||||
public class ThingXmlConfigDescriptionProvider extends AbstractXmlConfigDescriptionProvider {
|
||||
|
||||
private ConfigI18nLocalizationService configI18nLocalizerService;
|
||||
private final ConfigI18nLocalizationService configI18nService;
|
||||
|
||||
@Reference
|
||||
public void setConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) {
|
||||
this.configI18nLocalizerService = configI18nLocalizerService;
|
||||
}
|
||||
|
||||
public void unsetConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) {
|
||||
this.configI18nLocalizerService = null;
|
||||
@Activate
|
||||
public ThingXmlConfigDescriptionProvider(final @Reference ConfigI18nLocalizationService configI18nService) {
|
||||
this.configI18nService = configI18nService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigI18nLocalizationService getConfigI18nLocalizerService() {
|
||||
return configI18nLocalizerService;
|
||||
return configI18nService;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-19
@@ -15,6 +15,7 @@ package org.eclipse.smarthome.core.thing.xml.internal;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.config.xml.AbstractXmlBasedProvider;
|
||||
import org.eclipse.smarthome.core.thing.UID;
|
||||
import org.eclipse.smarthome.core.thing.i18n.ChannelGroupTypeI18nLocalizationService;
|
||||
@@ -22,6 +23,7 @@ import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
|
||||
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
|
||||
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@@ -35,36 +37,29 @@ import org.osgi.service.component.annotations.Reference;
|
||||
public class XmlChannelGroupTypeProvider extends AbstractXmlBasedProvider<UID, ChannelGroupType>
|
||||
implements ChannelGroupTypeProvider {
|
||||
|
||||
private ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService;
|
||||
private final ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService;
|
||||
|
||||
@Activate
|
||||
public XmlChannelGroupTypeProvider(
|
||||
final @Reference ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService) {
|
||||
this.channelGroupTypeI18nLocalizationService = channelGroupTypeI18nLocalizationService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
|
||||
public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
|
||||
@Nullable Locale locale) {
|
||||
return get(channelGroupTypeUID, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
|
||||
public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
|
||||
return getAll(locale);
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setChannelGroupTypeI18nLocalizationService(
|
||||
final ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService) {
|
||||
this.channelGroupTypeI18nLocalizationService = channelGroupTypeI18nLocalizationService;
|
||||
}
|
||||
|
||||
public void unsetChannelGroupTypeI18nLocalizationService(
|
||||
final ChannelGroupTypeI18nLocalizationService channelGroupTypeI18nLocalizationService) {
|
||||
this.channelGroupTypeI18nLocalizationService = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelGroupType localize(Bundle bundle, ChannelGroupType channelGroupType, Locale locale) {
|
||||
if (channelGroupTypeI18nLocalizationService == null) {
|
||||
return null;
|
||||
}
|
||||
protected @Nullable ChannelGroupType localize(Bundle bundle, ChannelGroupType channelGroupType,
|
||||
@Nullable Locale locale) {
|
||||
return channelGroupTypeI18nLocalizationService.createLocalizedChannelGroupType(bundle, channelGroupType,
|
||||
locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-19
@@ -15,6 +15,7 @@ package org.eclipse.smarthome.core.thing.xml.internal;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.config.xml.AbstractXmlBasedProvider;
|
||||
import org.eclipse.smarthome.core.thing.UID;
|
||||
import org.eclipse.smarthome.core.thing.i18n.ChannelTypeI18nLocalizationService;
|
||||
@@ -22,6 +23,7 @@ import org.eclipse.smarthome.core.thing.type.ChannelType;
|
||||
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
|
||||
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@@ -37,35 +39,26 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@Component(property = { "esh.scope=core.xml.channels" })
|
||||
public class XmlChannelTypeProvider extends AbstractXmlBasedProvider<UID, ChannelType> implements ChannelTypeProvider {
|
||||
|
||||
private ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService;
|
||||
private final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService;
|
||||
|
||||
@Activate
|
||||
public XmlChannelTypeProvider(
|
||||
final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
|
||||
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
|
||||
public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
|
||||
return get(channelTypeUID, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Collection<ChannelType> getChannelTypes(Locale locale) {
|
||||
public synchronized Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
|
||||
return getAll(locale);
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setChannelTypeI18nLocalizationService(
|
||||
final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
|
||||
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
|
||||
}
|
||||
|
||||
public void unsetChannelTypeI18nLocalizationService(
|
||||
final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
|
||||
this.channelTypeI18nLocalizationService = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelType localize(Bundle bundle, ChannelType channelType, Locale locale) {
|
||||
if (channelTypeI18nLocalizationService == null) {
|
||||
return null;
|
||||
}
|
||||
protected @Nullable ChannelType localize(Bundle bundle, ChannelType channelType, @Nullable Locale locale) {
|
||||
return channelTypeI18nLocalizationService.createLocalizedChannelType(bundle, channelType, locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-39
@@ -18,6 +18,7 @@ import java.util.Locale;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescriptionProvider;
|
||||
import org.eclipse.smarthome.config.xml.AbstractXmlBasedProvider;
|
||||
import org.eclipse.smarthome.config.xml.AbstractXmlConfigDescriptionProvider;
|
||||
@@ -60,24 +61,28 @@ public class XmlThingTypeProvider extends AbstractXmlBasedProvider<UID, ThingTyp
|
||||
private static final String XML_DIRECTORY = "/ESH-INF/thing/";
|
||||
public static final String READY_MARKER = "esh.xmlThingTypes";
|
||||
|
||||
private ThingTypeI18nLocalizationService thingTypeI18nLocalizationService;
|
||||
private AbstractXmlConfigDescriptionProvider configDescriptionProvider;
|
||||
private final ThingTypeI18nLocalizationService thingTypeI18nLocalizationService;
|
||||
private XmlChannelTypeProvider channelTypeProvider;
|
||||
private XmlChannelGroupTypeProvider channelGroupTypeProvider;
|
||||
|
||||
private XmlDocumentBundleTracker<List<?>> thingTypeTracker;
|
||||
private ReadyService readyService;
|
||||
|
||||
private AbstractXmlConfigDescriptionProvider configDescriptionProvider;
|
||||
private @Nullable XmlDocumentBundleTracker<List<?>> thingTypeTracker;
|
||||
private final ReadyService readyService;
|
||||
private final ScheduledExecutorService scheduler = ThreadPoolManager
|
||||
.getScheduledPool(XmlDocumentBundleTracker.THREAD_POOL_NAME);
|
||||
private Future<?> trackerJob;
|
||||
private @Nullable Future<?> trackerJob;
|
||||
|
||||
@Activate
|
||||
public XmlThingTypeProvider(final @Reference ThingTypeI18nLocalizationService thingTypeI18nLocalizationService,
|
||||
final @Reference ReadyService readyService) {
|
||||
this.thingTypeI18nLocalizationService = thingTypeI18nLocalizationService;
|
||||
this.readyService = readyService;
|
||||
}
|
||||
|
||||
@Activate
|
||||
protected void activate(BundleContext bundleContext) {
|
||||
XmlDocumentReader<List<?>> thingTypeReader = new ThingDescriptionReader();
|
||||
thingTypeTracker = new XmlDocumentBundleTracker<>(bundleContext, XML_DIRECTORY, thingTypeReader, this,
|
||||
READY_MARKER, readyService);
|
||||
|
||||
trackerJob = scheduler.submit(() -> {
|
||||
thingTypeTracker.open();
|
||||
});
|
||||
@@ -85,35 +90,28 @@ public class XmlThingTypeProvider extends AbstractXmlBasedProvider<UID, ThingTyp
|
||||
|
||||
@Deactivate
|
||||
protected void deactivate() {
|
||||
if (trackerJob != null && !trackerJob.isDone()) {
|
||||
trackerJob.cancel(true);
|
||||
Future<?> localTrackerJob = trackerJob;
|
||||
if (localTrackerJob != null && !localTrackerJob.isDone()) {
|
||||
localTrackerJob.cancel(true);
|
||||
trackerJob = null;
|
||||
}
|
||||
thingTypeTracker.close();
|
||||
thingTypeTracker = null;
|
||||
XmlDocumentBundleTracker<List<?>> localThingTypeTracker = thingTypeTracker;
|
||||
if (localThingTypeTracker != null) {
|
||||
localThingTypeTracker.close();
|
||||
thingTypeTracker = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
|
||||
public @Nullable ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
|
||||
return get(thingTypeUID, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Collection<ThingType> getThingTypes(Locale locale) {
|
||||
public synchronized Collection<ThingType> getThingTypes(@Nullable Locale locale) {
|
||||
return getAll(locale);
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setThingTypeI18nLocalizationService(
|
||||
final ThingTypeI18nLocalizationService thingTypeI18nLocalizationService) {
|
||||
this.thingTypeI18nLocalizationService = thingTypeI18nLocalizationService;
|
||||
}
|
||||
|
||||
public void unsetThingTypeI18nLocalizationService(
|
||||
final ThingTypeI18nLocalizationService thingTypeI18nLocalizationService) {
|
||||
this.thingTypeI18nLocalizationService = null;
|
||||
}
|
||||
|
||||
@Reference(target = "(esh.scope=core.xml.thing)")
|
||||
public void setConfigDescriptionProvider(ConfigDescriptionProvider configDescriptionProvider) {
|
||||
this.configDescriptionProvider = (AbstractXmlConfigDescriptionProvider) configDescriptionProvider;
|
||||
@@ -141,20 +139,8 @@ public class XmlThingTypeProvider extends AbstractXmlBasedProvider<UID, ThingTyp
|
||||
this.channelGroupTypeProvider = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setReadyService(ReadyService readyService) {
|
||||
this.readyService = readyService;
|
||||
}
|
||||
|
||||
public void unsetReadyService(ReadyService readyService) {
|
||||
this.readyService = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThingType localize(Bundle bundle, ThingType thingType, Locale locale) {
|
||||
if (thingTypeI18nLocalizationService == null) {
|
||||
return null;
|
||||
}
|
||||
protected @Nullable ThingType localize(Bundle bundle, ThingType thingType, @Nullable Locale locale) {
|
||||
return thingTypeI18nLocalizationService.createLocalizedThingType(bundle, thingType, locale);
|
||||
}
|
||||
|
||||
@@ -163,5 +149,4 @@ public class XmlThingTypeProvider extends AbstractXmlBasedProvider<UID, ThingTyp
|
||||
return new ThingTypeXmlProvider(bundle, configDescriptionProvider, this, channelTypeProvider,
|
||||
channelGroupTypeProvider);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -304,7 +304,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
|
||||
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
|
||||
final List<ChannelType> allChannelTypes = new ArrayList<>();
|
||||
final Bundle bundle = bundleResolver.resolveBundle(DefaultSystemChannelTypeProvider.class);
|
||||
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ package org.eclipse.smarthome.core.thing.internal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescriptionAliasProvider;
|
||||
@@ -78,7 +77,7 @@ public class ThingConfigDescriptionAliasProvider implements ConfigDescriptionAli
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable URI getAlias(@NonNull URI uri) {
|
||||
public @Nullable URI getAlias(URI uri) {
|
||||
// If this is not a concrete thing, then return
|
||||
if (uri.getScheme() == null) {
|
||||
return null;
|
||||
|
||||
-1
@@ -37,6 +37,5 @@ public interface ChannelGroupTypeProvider {
|
||||
/**
|
||||
* @see ChannelTypeRegistry#getChannelGroupTypes(Locale)
|
||||
*/
|
||||
@Nullable
|
||||
Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale);
|
||||
}
|
||||
|
||||
+1
-2
@@ -32,7 +32,6 @@ public interface ChannelTypeProvider {
|
||||
/**
|
||||
* @see ChannelTypeRegistry#getChannelTypes(Locale)
|
||||
*/
|
||||
@Nullable
|
||||
Collection<ChannelType> getChannelTypes(@Nullable Locale locale);
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ public interface ChannelTypeProvider {
|
||||
* @deprecated The {@link ChannelGroupTypeProvider} is now to be implemented/used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default @Nullable Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
|
||||
default Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user