]> git.basschouten.com Git - openhab-addons.git/blob
3778b81590a55da3ec43f578cbc44784c3108686
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.unifi.internal.api.util;
14
15 import java.lang.reflect.Type;
16
17 import org.openhab.binding.unifi.internal.api.model.UniFiClient;
18 import org.openhab.binding.unifi.internal.api.model.UniFiController;
19 import org.openhab.binding.unifi.internal.api.model.UniFiUnknownClient;
20 import org.openhab.binding.unifi.internal.api.model.UniFiWiredClient;
21 import org.openhab.binding.unifi.internal.api.model.UniFiWirelessClient;
22
23 import com.google.gson.InstanceCreator;
24
25 /**
26  * The {@link UniFiClientInstanceCreator} creates instances of {@link UniFiClient}s during the JSON unmarshalling of
27  * controller responses.
28  *
29  * @author Matthew Bowman - Initial contribution
30  */
31 public class UniFiClientInstanceCreator implements InstanceCreator<UniFiClient> {
32
33     private final UniFiController controller;
34
35     public UniFiClientInstanceCreator(UniFiController controller) {
36         this.controller = controller;
37     }
38
39     @Override
40     public UniFiClient createInstance(Type type) {
41         if (UniFiUnknownClient.class.equals(type)) {
42             return new UniFiUnknownClient(controller);
43         }
44         if (UniFiWirelessClient.class.equals(type)) {
45             return new UniFiWirelessClient(controller);
46         }
47         if (UniFiWiredClient.class.equals(type)) {
48             return new UniFiWiredClient(controller);
49         }
50         return null;
51     }
52 }