diff --git a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlProvider.java b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlProvider.java index ea2fe0d60c3..aa1fdf3295f 100644 --- a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlProvider.java +++ b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlProvider.java @@ -12,6 +12,8 @@ */ package org.eclipse.smarthome.core.binding.xml.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.ConfigDescription; import org.eclipse.smarthome.config.xml.AbstractXmlConfigDescriptionProvider; import org.eclipse.smarthome.config.xml.osgi.XmlDocumentProvider; @@ -36,14 +38,15 @@ * * @see BindingInfoXmlProviderFactory */ +@NonNullByDefault public class BindingInfoXmlProvider implements XmlDocumentProvider { private Logger logger = LoggerFactory.getLogger(BindingInfoXmlProvider.class); - private Bundle bundle; + private final Bundle bundle; - private XmlBindingInfoProvider bindingInfoProvider; - private AbstractXmlConfigDescriptionProvider configDescriptionProvider; + private final XmlBindingInfoProvider bindingInfoProvider; + private final AbstractXmlConfigDescriptionProvider configDescriptionProvider; public BindingInfoXmlProvider(Bundle bundle, XmlBindingInfoProvider bindingInfoProvider, AbstractXmlConfigDescriptionProvider configDescriptionProvider) throws IllegalArgumentException { @@ -60,26 +63,24 @@ public BindingInfoXmlProvider(Bundle bundle, XmlBindingInfoProvider bindingInfoP } this.bundle = bundle; - this.bindingInfoProvider = bindingInfoProvider; this.configDescriptionProvider = configDescriptionProvider; } @Override - public synchronized void addingObject(BindingInfoXmlResult bindingInfoXmlResult) { + public synchronized void addingObject(@Nullable BindingInfoXmlResult bindingInfoXmlResult) { if (bindingInfoXmlResult != null) { ConfigDescription configDescription = bindingInfoXmlResult.getConfigDescription(); if (configDescription != null) { try { - this.configDescriptionProvider.add(this.bundle, configDescription); + configDescriptionProvider.add(bundle, configDescription); } catch (Exception ex) { - this.logger.error("Could not register ConfigDescription!", ex); + logger.error("Could not register ConfigDescription!", ex); } } - BindingInfo bindingInfo = bindingInfoXmlResult.getBindingInfo(); - this.bindingInfoProvider.add(bundle, bindingInfo); + bindingInfoProvider.add(bundle, bindingInfoXmlResult.getBindingInfo()); } } @@ -93,5 +94,4 @@ public synchronized void release() { this.bindingInfoProvider.removeAll(bundle); this.configDescriptionProvider.removeAll(bundle); } - } diff --git a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlResult.java b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlResult.java index 3d052adcfec..76bb9617f99 100644 --- a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlResult.java +++ b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingInfoXmlResult.java @@ -12,6 +12,8 @@ */ package org.eclipse.smarthome.core.binding.xml.internal; +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.core.binding.BindingInfo; @@ -24,12 +26,13 @@ * * @author Michael Grammling - Initial contribution */ +@NonNullByDefault public class BindingInfoXmlResult { private BindingInfo bindingInfo; - private ConfigDescription configDescription; + private @Nullable ConfigDescription configDescription; - public BindingInfoXmlResult(BindingInfo bindingInfo, ConfigDescription configDescription) + public BindingInfoXmlResult(BindingInfo bindingInfo, @Nullable ConfigDescription configDescription) throws IllegalArgumentException { if (bindingInfo == null) { throw new IllegalArgumentException("The BindingInfo must not be null!"); @@ -40,16 +43,15 @@ public BindingInfoXmlResult(BindingInfo bindingInfo, ConfigDescription configDes } public BindingInfo getBindingInfo() { - return this.bindingInfo; + return bindingInfo; } - public ConfigDescription getConfigDescription() { - return this.configDescription; + public @Nullable ConfigDescription getConfigDescription() { + return configDescription; } @Override public String toString() { return "BindingInfoXmlResult [bindingInfo=" + bindingInfo + ", configDescription=" + configDescription + "]"; } - } diff --git a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingXmlConfigDescriptionProvider.java b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingXmlConfigDescriptionProvider.java index e16eae137be..9266022d405 100644 --- a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingXmlConfigDescriptionProvider.java +++ b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/BindingXmlConfigDescriptionProvider.java @@ -12,10 +12,12 @@ */ package org.eclipse.smarthome.core.binding.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 @@ * @author Simon Kaufmann - Initial contribution */ @Component(service = ConfigDescriptionProvider.class, immediate = true, property = { "esh.scope=core.xml.binding" }) +@NonNullByDefault public class BindingXmlConfigDescriptionProvider 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 BindingXmlConfigDescriptionProvider(final @Reference ConfigI18nLocalizationService configI18nService) { + this.configI18nService = configI18nService; } @Override protected ConfigI18nLocalizationService getConfigI18nLocalizerService() { - return configI18nLocalizerService; + return configI18nService; } - } diff --git a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/XmlBindingInfoProvider.java b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/XmlBindingInfoProvider.java index 5954c32d3aa..b22d34ad382 100644 --- a/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/XmlBindingInfoProvider.java +++ b/bundles/org.openhab.core.binding.xml/src/main/java/org/eclipse/smarthome/core/binding/xml/internal/XmlBindingInfoProvider.java @@ -18,6 +18,7 @@ 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; @@ -27,8 +28,8 @@ import org.eclipse.smarthome.config.xml.util.XmlDocumentReader; import org.eclipse.smarthome.core.binding.BindingInfo; import org.eclipse.smarthome.core.binding.BindingInfoProvider; +import org.eclipse.smarthome.core.binding.i18n.BindingI18nUtil; import org.eclipse.smarthome.core.common.ThreadPoolManager; -import org.eclipse.smarthome.core.i18n.BindingI18nUtil; import org.eclipse.smarthome.core.i18n.TranslationProvider; import org.eclipse.smarthome.core.service.ReadyService; import org.osgi.framework.Bundle; @@ -55,19 +56,24 @@ public class XmlBindingInfoProvider extends AbstractXmlBasedProvider bindingInfoTracker; - private ReadyService readyService; - - private ScheduledExecutorService scheduler = ThreadPoolManager + private final ReadyService readyService; + private final ScheduledExecutorService scheduler = ThreadPoolManager .getScheduledPool(XmlDocumentBundleTracker.THREAD_POOL_NAME); - private Future trackerJob; + private @Nullable Future trackerJob; + + @Activate + public XmlBindingInfoProvider(final @Reference TranslationProvider i18nProvider, + final @Reference ReadyService readyService) { + this.bindingI18nUtil = new BindingI18nUtil(i18nProvider); + this.readyService = readyService; + } @Activate public void activate(ComponentContext componentContext) { XmlDocumentReader bindingInfoReader = new BindingInfoReader(); - bindingInfoTracker = new XmlDocumentBundleTracker<>(componentContext.getBundleContext(), XML_DIRECTORY, bindingInfoReader, this, READY_MARKER, readyService); trackerJob = scheduler.submit(() -> { @@ -86,24 +92,15 @@ public void deactivate(ComponentContext componentContext) { } @Override - public synchronized BindingInfo getBindingInfo(String id, Locale locale) { - return get(id, locale); + public synchronized @Nullable BindingInfo getBindingInfo(@Nullable String id, @Nullable Locale locale) { + return id == null ? null : get(id, locale); } @Override - public synchronized Set getBindingInfos(Locale locale) { + public synchronized Set getBindingInfos(@Nullable Locale locale) { return new HashSet<>(getAll(locale)); } - @Reference - public void setTranslationProvider(TranslationProvider i18nProvider) { - this.bindingI18nUtil = new BindingI18nUtil(i18nProvider); - } - - public void unsetTranslationProvider(TranslationProvider i18nProvider) { - this.bindingI18nUtil = null; - } - @Reference(target = "(esh.scope=core.xml.binding)") public void setConfigDescriptionProvider(ConfigDescriptionProvider configDescriptionProvider) { this.configDescriptionProvider = (AbstractXmlConfigDescriptionProvider) configDescriptionProvider; @@ -113,26 +110,14 @@ public void unsetConfigDescriptionProvider(ConfigDescriptionProvider configDescr this.configDescriptionProvider = null; } - @Reference - public void setReadyService(ReadyService readyService) { - this.readyService = readyService; - } - - public void unsetReadyService(ReadyService readyService) { - this.readyService = null; - } - @Override - protected BindingInfo localize(Bundle bundle, BindingInfo bindingInfo, Locale locale) { - if (this.bindingI18nUtil == null) { - return null; - } + protected @Nullable BindingInfo localize(Bundle bundle, BindingInfo bindingInfo, @Nullable Locale locale) { + String name = bindingI18nUtil.getName(bundle, bindingInfo.getUID(), bindingInfo.getName(), locale); + String description = bindingI18nUtil.getDescription(bundle, bindingInfo.getUID(), bindingInfo.getDescription(), + locale); - String name = this.bindingI18nUtil.getName(bundle, bindingInfo.getUID(), bindingInfo.getName(), locale); - String description = this.bindingI18nUtil.getDescription(bundle, bindingInfo.getUID(), - bindingInfo.getDescription(), locale); - - return new BindingInfo(bindingInfo.getUID(), name, description, bindingInfo.getAuthor(), + return new BindingInfo(bindingInfo.getUID(), name == null ? bindingInfo.getName() : name, + description == null ? bindingInfo.getDescription() : description, bindingInfo.getAuthor(), bindingInfo.getServiceId(), bindingInfo.getConfigDescriptionURI()); } @@ -140,5 +125,4 @@ protected BindingInfo localize(Bundle bundle, BindingInfo bindingInfo, Locale lo public XmlDocumentProvider createDocumentProvider(Bundle bundle) { return new BindingInfoXmlProvider(bundle, this, configDescriptionProvider); } - } diff --git a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlBasedProvider.java b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlBasedProvider.java index 44e651c1a13..047d6cd5f75 100644 --- a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlBasedProvider.java +++ b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlBasedProvider.java @@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.core.common.registry.Identifiable; import org.eclipse.smarthome.core.i18n.LocalizedKey; import org.osgi.framework.Bundle; @@ -48,7 +49,7 @@ public abstract class AbstractXmlBasedProvidernull if translation was not possible. */ - protected abstract T_OBJECT localize(Bundle bundle, T_OBJECT object, Locale locale); + protected abstract @Nullable T_OBJECT localize(Bundle bundle, T_OBJECT object, @Nullable Locale locale); /** * Adds an object to the internal list associated with the specified module. @@ -104,7 +105,7 @@ private List acquireObjects(Bundle bundle) { * @param locale the locale * @return the object if found, null otherwise */ - protected final T_OBJECT get(T_ID key, Locale locale) { + protected final @Nullable T_OBJECT get(T_ID key, @Nullable Locale locale) { for (Entry> objects : bundleObjectMap.entrySet()) { for (T_OBJECT object : objects.getValue()) { if (key.equals(object.getUID())) { @@ -121,7 +122,7 @@ protected final T_OBJECT get(T_ID key, Locale locale) { * @param locale the locale * @return a collection containing all available objects. Never null */ - protected final synchronized Collection getAll(Locale locale) { + protected final synchronized Collection getAll(@Nullable Locale locale) { List ret = new LinkedList<>(); Collection>> objectList = bundleObjectMap.entrySet(); for (Entry> objects : objectList) { @@ -164,7 +165,7 @@ private void removeCachedEntries(T_OBJECT object) { } } - private T_OBJECT acquireLocalizedObject(Bundle bundle, T_OBJECT object, Locale locale) { + private T_OBJECT acquireLocalizedObject(Bundle bundle, T_OBJECT object, @Nullable Locale locale) { final LocalizedKey localizedKey = getLocalizedKey(object, locale); final T_OBJECT cacheEntry = localizedObjectCache.get(localizedKey); @@ -181,7 +182,7 @@ private T_OBJECT acquireLocalizedObject(Bundle bundle, T_OBJECT object, Locale l } } - private LocalizedKey getLocalizedKey(T_OBJECT object, Locale locale) { + private LocalizedKey getLocalizedKey(T_OBJECT object, @Nullable Locale locale) { return new LocalizedKey(object.getUID(), locale != null ? locale.toLanguageTag() : null); } diff --git a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlConfigDescriptionProvider.java b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlConfigDescriptionProvider.java index 4a1e3206189..7b0358f73ac 100644 --- a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlConfigDescriptionProvider.java +++ b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/AbstractXmlConfigDescriptionProvider.java @@ -16,6 +16,8 @@ import java.util.Collection; import java.util.Locale; +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; @@ -41,21 +43,19 @@ public abstract class AbstractXmlConfigDescriptionProvider extends AbstractXmlBa implements ConfigDescriptionProvider { @Override - public synchronized Collection getConfigDescriptions(Locale locale) { + public synchronized Collection getConfigDescriptions(@Nullable Locale locale) { return getAll(locale); } @Override - public synchronized ConfigDescription getConfigDescription(URI uri, Locale locale) { + public synchronized @Nullable ConfigDescription getConfigDescription(URI uri, @Nullable Locale locale) { return get(uri, locale); } @Override - protected ConfigDescription localize(Bundle bundle, ConfigDescription configDescription, Locale locale) { + protected @Nullable ConfigDescription localize(Bundle bundle, ConfigDescription configDescription, + @Nullable Locale locale) { ConfigI18nLocalizationService configI18nLocalizerService = getConfigI18nLocalizerService(); - if (configI18nLocalizerService == null) { - return null; - } return configI18nLocalizerService.getLocalizedConfigDescription(bundle, configDescription, locale); } diff --git a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProvider.java b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProvider.java index e316985d95e..1311fb61a45 100644 --- a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProvider.java +++ b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProvider.java @@ -12,6 +12,8 @@ */ package org.eclipse.smarthome.config.xml.osgi; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.xml.internal.ConfigDescriptionReader; /** @@ -24,6 +26,7 @@ * * @param the result type of the conversion */ +@NonNullByDefault public interface XmlDocumentProvider { /** @@ -31,7 +34,7 @@ public interface XmlDocumentProvider { * * @param object the result object to be processed (could be null) */ - void addingObject(T object); + void addingObject(@Nullable T object); /** * Signals that all available result objects from the XML processing of the @@ -43,5 +46,4 @@ public interface XmlDocumentProvider { * Releases any added result objects from the XML processing. */ void release(); - } diff --git a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProviderFactory.java b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProviderFactory.java index 49ca7b741a6..e0cf5cc8173 100644 --- a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProviderFactory.java +++ b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/osgi/XmlDocumentProviderFactory.java @@ -12,6 +12,7 @@ */ package org.eclipse.smarthome.config.xml.osgi; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.osgi.framework.Bundle; /** @@ -27,6 +28,7 @@ * @param the result type of the conversion * @see XmlDocumentProvider */ +@NonNullByDefault public interface XmlDocumentProviderFactory { /** @@ -37,5 +39,4 @@ public interface XmlDocumentProviderFactory { * @return the created provider for the specified module (must not be null) */ XmlDocumentProvider createDocumentProvider(Bundle bundle); - } diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfo.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfo.java index e005f609e69..2f164e458d5 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfo.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfo.java @@ -14,6 +14,8 @@ import java.net.URI; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.core.common.registry.Identifiable; /** @@ -27,6 +29,7 @@ * @author Michael Grammling - Initial contribution * @author Andre Fuechsel - Made author tag optional */ +@NonNullByDefault public class BindingInfo implements Identifiable { /** @@ -35,9 +38,9 @@ public class BindingInfo implements Identifiable { public static final String DEFAULT_SERVICE_ID_PREFIX = "binding."; private String id; private String name; - private String description; - private String author; - private URI configDescriptionURI; + private @Nullable String description; + private @Nullable String author; + private @Nullable URI configDescriptionURI; private String serviceId; /** @@ -46,13 +49,13 @@ public class BindingInfo implements Identifiable { * @param id the identifier for the binding (must neither be null, nor empty) * @param name a human readable name for the binding (must neither be null, nor empty) * @param description a human readable description for the binding (could be null or empty) - * @param author the author of the binding (must neither be null, nor empty) + * @param author the author of the binding (could be null or empty) * @param serviceId the service id of the main service of the binding (can be null) * @param configDescriptionURI the link to a concrete ConfigDescription (could be null) - * @throws IllegalArgumentException if the identifier, the name or the author is null or empty + * @throws IllegalArgumentException if the identifier or the name are null or empty */ - public BindingInfo(String id, String name, String description, String author, String serviceId, - URI configDescriptionURI) throws IllegalArgumentException { + public BindingInfo(String id, String name, @Nullable String description, @Nullable String author, + @Nullable String serviceId, @Nullable URI configDescriptionURI) throws IllegalArgumentException { if ((id == null) || (id.isEmpty())) { throw new IllegalArgumentException("The ID must neither be null nor empty!"); } @@ -76,7 +79,7 @@ public BindingInfo(String id, String name, String description, String author, St */ @Override public String getUID() { - return this.id; + return id; } /** @@ -85,7 +88,7 @@ public String getUID() { * @return a human readable name for the binding (neither null, nor empty) */ public String getName() { - return this.name; + return name; } /** @@ -94,8 +97,8 @@ public String getName() { * * @return a human readable description for the binding (could be null or empty) */ - public String getDescription() { - return this.description; + public @Nullable String getDescription() { + return description; } /** @@ -103,14 +106,14 @@ public String getDescription() { * * @return the author of the binding (could be null or empty) */ - public String getAuthor() { - return this.author; + public @Nullable String getAuthor() { + return author; } /** * Returns the service ID of the bindings main service, that can be configured. * - * @return service ID or null if no service is configured + * @return service ID */ public String getServiceId() { return serviceId; @@ -121,14 +124,13 @@ public String getServiceId() { * * @return the link to a concrete ConfigDescription (could be null) */ - public URI getConfigDescriptionURI() { - return this.configDescriptionURI; + public @Nullable URI getConfigDescriptionURI() { + return configDescriptionURI; } @Override public String toString() { - return "BindingInfoImpl [id=" + id + ", name=" + name + ", description=" + description + ", author=" + author + return "BindingInfoI [id=" + id + ", name=" + name + ", description=" + description + ", author=" + author + ", configDescriptionURI=" + configDescriptionURI + "]"; } - } diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfoProvider.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfoProvider.java index 698ffc5965e..cbd45c425f6 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfoProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/BindingInfoProvider.java @@ -15,6 +15,9 @@ import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * The {@link BindingInfoProvider} is a service interface providing {@link BindingInfo} objects. All registered * {@link BindingInfoProvider} services are tracked by the {@link BindingInfoRegistry} and provided as one common @@ -24,6 +27,7 @@ * * @see BindingInfoRegistry */ +@NonNullByDefault public interface BindingInfoProvider { /** @@ -34,15 +38,15 @@ public interface BindingInfoProvider { * @param locale the locale to be used for the binding information (could be null) * @return a localized binding information object (could be null) */ - BindingInfo getBindingInfo(String id, Locale locale); + @Nullable + BindingInfo getBindingInfo(@Nullable String id, @Nullable Locale locale); /** * Returns all binding information in the specified locale (language) this provider contains. * * @param locale the locale to be used for the binding information (could be null) * @return a localized set of all binding information this provider contains - * (not null, could be empty) + * (could be empty) */ - Set getBindingInfos(Locale locale); - + Set getBindingInfos(@Nullable Locale locale); } diff --git a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/i18n/BindingI18nUtil.java b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/i18n/BindingI18nUtil.java similarity index 71% rename from bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/i18n/BindingI18nUtil.java rename to bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/i18n/BindingI18nUtil.java index ac3ee41dcda..efe7c763cad 100644 --- a/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/i18n/BindingI18nUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/eclipse/smarthome/core/binding/i18n/BindingI18nUtil.java @@ -10,10 +10,14 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.smarthome.core.i18n; +package org.eclipse.smarthome.core.binding.i18n; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.i18n.I18nUtil; +import org.eclipse.smarthome.core.i18n.TranslationProvider; import org.osgi.framework.Bundle; /** @@ -23,6 +27,7 @@ * * @author Dennis Nobel - Initial contribution */ +@NonNullByDefault public class BindingI18nUtil { private final TranslationProvider i18nProvider; @@ -31,20 +36,18 @@ public BindingI18nUtil(TranslationProvider i18nProvider) { this.i18nProvider = i18nProvider; } - public String getDescription(Bundle bundle, String bindingId, String defaultDescription, Locale locale) { + public @Nullable String getDescription(Bundle bundle, String bindingId, @Nullable String defaultDescription, + @Nullable Locale locale) { String key = I18nUtil.stripConstantOr(defaultDescription, () -> inferKey(bindingId, "description")); - return i18nProvider.getText(bundle, key, defaultDescription, locale); } - public String getName(Bundle bundle, String bindingId, String defaultLabel, Locale locale) { + public @Nullable String getName(Bundle bundle, String bindingId, String defaultLabel, @Nullable Locale locale) { String key = I18nUtil.stripConstantOr(defaultLabel, () -> inferKey(bindingId, "name")); - return i18nProvider.getText(bundle, key, defaultLabel, locale); } private String inferKey(String bindingId, String lastSegment) { return "binding." + bindingId + "." + lastSegment; } - }