From 067f703b785dc19e44d4e6817b6711edbb1d6dfe Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Thu, 9 Jul 2020 23:14:51 +0200 Subject: [PATCH] Remove deprecated method in 'ConfigOptionProvider' - preparations (#8093) Signed-off-by: Christoph Weitkamp Signed-off-by: MPH80 --- .../AmazonDashButtonConfigOptionProvider.java | 16 +++- .../internal/GPSTrackerHandlerFactory.java | 92 +++++++++---------- .../internal/provider/TrackerRegistry.java | 8 +- .../internal/SmartMeterConfigProvider.java | 10 +- 4 files changed, 64 insertions(+), 62 deletions(-) diff --git a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/config/AmazonDashButtonConfigOptionProvider.java b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/config/AmazonDashButtonConfigOptionProvider.java index 82a362bdbce7f..3113c5537d86b 100644 --- a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/config/AmazonDashButtonConfigOptionProvider.java +++ b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/config/AmazonDashButtonConfigOptionProvider.java @@ -17,13 +17,14 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.ConfigOptionProvider; import org.eclipse.smarthome.config.core.ParameterOption; import org.eclipse.smarthome.core.thing.ThingTypeUID; @@ -40,18 +41,25 @@ * @author Oliver Libutzki - Initial contribution * */ -@Component(service = ConfigOptionProvider.class, immediate = true) +@Component(service = ConfigOptionProvider.class) +@NonNullByDefault public class AmazonDashButtonConfigOptionProvider implements ConfigOptionProvider { @Override - public Collection getParameterOptions(URI uri, String param, Locale locale) { + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable Locale locale) { + return getParameterOptions(uri, param, null, locale); + } + + @Override + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, + @Nullable Locale locale) { if ("thing-type".equals(uri.getScheme())) { ThingTypeUID thingtypeUID = new ThingTypeUID(uri.getSchemeSpecificPart()); if (thingtypeUID.equals(DASH_BUTTON_THING_TYPE) && PROPERTY_NETWORK_INTERFACE_NAME.equals(param)) { return getPcapNetworkInterfacesOptions(); } } - return Collections.emptyList(); + return null; } private Collection getPcapNetworkInterfacesOptions() { diff --git a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/GPSTrackerHandlerFactory.java b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/GPSTrackerHandlerFactory.java index d0d7aafd3dfaf..e294e3a25b4d0 100644 --- a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/GPSTrackerHandlerFactory.java +++ b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/GPSTrackerHandlerFactory.java @@ -15,10 +15,17 @@ import static org.openhab.binding.gpstracker.internal.GPSTrackerBindingConstants.CONFIG_PID; import java.net.URI; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import javax.servlet.ServletException; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.ConfigOptionProvider; import org.eclipse.smarthome.config.core.ParameterOption; import org.eclipse.smarthome.core.i18n.LocationProvider; @@ -36,6 +43,7 @@ import org.openhab.binding.gpstracker.internal.provider.gpslogger.GPSLoggerCallbackServlet; import org.openhab.binding.gpstracker.internal.provider.owntracks.OwnTracksCallbackServlet; import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.http.HttpService; @@ -49,6 +57,7 @@ * @author Gabor Bicskei - Initial contribution */ @Component(configurationPid = CONFIG_PID, service = { ThingHandlerFactory.class, ConfigOptionProvider.class }) +@NonNullByDefault public class GPSTrackerHandlerFactory extends BaseThingHandlerFactory implements TrackerRegistry, ConfigOptionProvider { /** * Config URI @@ -63,47 +72,58 @@ public class GPSTrackerHandlerFactory extends BaseThingHandlerFactory implements /** * Discovery service instance */ - private TrackerDiscoveryService discoveryService; + private final TrackerDiscoveryService discoveryService; /** * Unit provider */ - private UnitProvider unitProvider; + private final UnitProvider unitProvider; /** * Location provider */ - private LocationProvider locationProvider; + private final LocationProvider locationProvider; /** * HTTP service reference */ - private HttpService httpService; + private final HttpService httpService; /** * Endpoint called by tracker applications */ - private OwnTracksCallbackServlet otHTTPEndpoint; + private @NonNullByDefault({}) OwnTracksCallbackServlet otHTTPEndpoint; /** * Endpoint called by tracker applications */ - private GPSLoggerCallbackServlet glHTTPEndpoint; + private @NonNullByDefault({}) GPSLoggerCallbackServlet glHTTPEndpoint; /** * Notification broker */ - private NotificationBroker notificationBroker = new NotificationBroker(); + private final NotificationBroker notificationBroker = new NotificationBroker(); /** * Handler registry */ - private Map trackerHandlers = new HashMap<>(); + private final Map trackerHandlers = new HashMap<>(); /** * All regions. */ - private Set regions = new HashSet<>(); + private final Set regions = new HashSet<>(); + + @Activate + public GPSTrackerHandlerFactory(final @Reference HttpService httpService, // + final @Reference TrackerDiscoveryService discoveryService, // + final @Reference UnitProvider unitProvider, // + final @Reference LocationProvider locationProvider) { + this.httpService = httpService; + this.discoveryService = discoveryService; + this.unitProvider = unitProvider; + this.locationProvider = locationProvider; + } /** * Called by the framework to find out if thing type is supported by the handler factory. @@ -123,12 +143,12 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { * @return Handler instance */ @Override - protected ThingHandler createHandler(Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (GPSTrackerBindingConstants.THING_TYPE_TRACKER.equals(thingTypeUID) && ConfigHelper.getTrackerId(thing.getConfiguration()) != null) { TrackerHandler trackerHandler = new TrackerHandler(thing, notificationBroker, regions, - locationProvider != null ? locationProvider.getLocation() : null, unitProvider); + locationProvider.getLocation(), unitProvider); discoveryService.removeTracker(trackerHandler.getTrackerId()); trackerHandlers.put(trackerHandler.getTrackerId(), trackerHandler); return trackerHandler; @@ -187,53 +207,23 @@ protected void deactivate(ComponentContext componentContext) { } @Override - public Collection getParameterOptions(URI uri, String param, Locale locale) { + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable Locale locale) { + return getParameterOptions(uri, param, null, locale); + } + + @Override + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, + @Nullable Locale locale) { if (URI_STR.equals(uri.toString()) && ConfigHelper.CONFIG_REGION_NAME.equals(param)) { Set ret = new HashSet<>(); regions.forEach(r -> ret.add(new ParameterOption(r, r))); return ret; } - return Collections.emptyList(); - } - - @Reference - protected void setHttpService(HttpService httpService) { - this.httpService = httpService; - } - - protected void unsetHttpService(HttpService httpService) { - this.httpService = null; - } - - @Reference - protected void setTrackerDiscoveryService(TrackerDiscoveryService discoveryService) { - this.discoveryService = discoveryService; - } - - protected void unsetTrackerDiscoveryService(TrackerDiscoveryService discoveryService) { - this.discoveryService = null; - } - - @Reference - protected void setUnitProvider(UnitProvider unitProvider) { - this.unitProvider = unitProvider; - } - - protected void unsetUnitProvider(UnitProvider unitProvider) { - this.unitProvider = null; - } - - @Reference - protected void setLocationProvider(LocationProvider locationProvider) { - this.locationProvider = locationProvider; - } - - protected void unsetLocationProvider(LocationProvider locationProvider) { - this.locationProvider = null; + return null; } @Override - public TrackerHandler getTrackerHandler(String trackerId) { + public @Nullable TrackerHandler getTrackerHandler(String trackerId) { return trackerHandlers.get(trackerId); } } diff --git a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/TrackerRegistry.java b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/TrackerRegistry.java index 5f425b84a5edc..c48986a257c21 100644 --- a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/TrackerRegistry.java +++ b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/TrackerRegistry.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.gpstracker.internal.provider; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.gpstracker.internal.handler.TrackerHandler; /** @@ -19,13 +21,15 @@ * * @author Gabor Bicskei - Initial contribution */ +@NonNullByDefault public interface TrackerRegistry { /** * Returns a handler for a given id - * + * * @param trackerId the id of the tracker - * @return the handler or null if it does not exist + * @return the handler */ + @Nullable TrackerHandler getTrackerHandler(String trackerId); } diff --git a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterConfigProvider.java b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterConfigProvider.java index fee7a6e9f722a..110b849c32e18 100644 --- a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterConfigProvider.java +++ b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterConfigProvider.java @@ -34,18 +34,18 @@ * @author Matthias Steigenberger - Initial contribution * */ +@Component(service = ConfigOptionProvider.class) @NonNullByDefault -@Component public class SmartMeterConfigProvider implements ConfigOptionProvider { @Override - public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, - @Nullable Locale locale) { - return ConfigOptionProvider.super.getParameterOptions(uri, param, context, locale); + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable Locale locale) { + return getParameterOptions(uri, param, null, locale); } @Override - public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable Locale locale) { + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, + @Nullable Locale locale) { if (!SmartMeterBindingConstants.THING_TYPE_SMLREADER.getAsString().equals(uri.getSchemeSpecificPart())) { return null; }