Skip to content

Commit

Permalink
Remove deprecated method in 'ConfigOptionProvider' - preparations (op…
Browse files Browse the repository at this point in the history
…enhab#8093)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored and andrewfg committed Aug 31, 2020
1 parent 4904738 commit 4792624
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable Locale locale) {
return getParameterOptions(uri, param, null, locale);
}

@Override
public @Nullable Collection<ParameterOption> 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<ParameterOption> getPcapNetworkInterfacesOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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<String, TrackerHandler> trackerHandlers = new HashMap<>();
private final Map<String, TrackerHandler> trackerHandlers = new HashMap<>();

/**
* All regions.
*/
private Set<String> regions = new HashSet<>();
private final Set<String> 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.
Expand All @@ -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;
Expand Down Expand Up @@ -187,53 +207,23 @@ protected void deactivate(ComponentContext componentContext) {
}

@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable Locale locale) {
return getParameterOptions(uri, param, null, locale);
}

@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
if (URI_STR.equals(uri.toString()) && ConfigHelper.CONFIG_REGION_NAME.equals(param)) {
Set<ParameterOption> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@
*/
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;

/**
* Functional interface for checking tracker registration.
*
* @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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
* @author Matthias Steigenberger - Initial contribution
*
*/
@Component(service = ConfigOptionProvider.class)
@NonNullByDefault
@Component
public class SmartMeterConfigProvider implements ConfigOptionProvider {

@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
return ConfigOptionProvider.super.getParameterOptions(uri, param, context, locale);
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable Locale locale) {
return getParameterOptions(uri, param, null, locale);
}

@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable Locale locale) {
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
if (!SmartMeterBindingConstants.THING_TYPE_SMLREADER.getAsString().equals(uri.getSchemeSpecificPart())) {
return null;
}
Expand Down

0 comments on commit 4792624

Please sign in to comment.