2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.innogysmarthome.internal.client.entity.link;
15 import org.openhab.binding.innogysmarthome.internal.client.entity.capability.Capability;
16 import org.openhab.binding.innogysmarthome.internal.client.entity.device.Device;
17 import org.openhab.binding.innogysmarthome.internal.client.entity.message.Message;
20 * Defines the data structure for a {@link Link}. This is the basic component used to link different data types in the
23 * @author Oliver Kuhl - Initial contribution
27 public static final String LINK_TYPE_CAPABILITY = "/capability/";
28 public static final String LINK_TYPE_DEVICE = "/device/";
29 public static final String LINK_TYPE_MESSAGE = "/message/";
30 public static final String LINK_TYPE_SHC = "/desc/device/SHC.RWE/";
31 public static final String LINK_TYPE_UNKNOWN = "unknown";
34 * Returns the Type of the {@link Link}.
36 * @return {@link #LINK_TYPE_CAPABILITY},{@link #LINK_TYPE_DEVICE}, {@link #LINK_TYPE_MESSAGE},
37 * {@link #LINK_TYPE_SHC} or {@link #LINK_TYPE_UNKNOWN}
39 public static String getLinkType(String link) {
40 if (link.startsWith(LINK_TYPE_CAPABILITY)) {
41 return LINK_TYPE_CAPABILITY;
42 } else if (link.startsWith(LINK_TYPE_DEVICE)) {
43 return LINK_TYPE_DEVICE;
44 } else if (link.startsWith(LINK_TYPE_MESSAGE)) {
45 return LINK_TYPE_MESSAGE;
46 } else if (link.startsWith(LINK_TYPE_SHC)) {
49 return LINK_TYPE_UNKNOWN;
54 * Returns the id of the {@link Link} or null, if the link does not have an id or even no value.
56 * @return String the id of the link or null
58 public static String getId(String link) {
60 final String linkType = getLinkType(link);
61 if (linkType != null && !Link.LINK_TYPE_UNKNOWN.equals(linkType) && !Link.LINK_TYPE_SHC.equals(linkType)) {
62 return link.replace(linkType, "");
69 * Returns true, if the {@link Link} points to a {@link Capability}.
73 public static boolean isTypeCapability(String link) {
74 return LINK_TYPE_CAPABILITY.equals(Link.getLinkType(link));
78 * Returns true, if the {@link Link} points to a {@link Device}.
82 public static boolean isTypeDevice(String link) {
83 return LINK_TYPE_DEVICE.equals(Link.getLinkType(link));
87 * Returns true, if the {@link Link} points to a {@link Message}.
91 public static boolean isTypeMessage(String link) {
92 return LINK_TYPE_MESSAGE.equals(Link.getLinkType(link));
96 * Returns true, if the {@link Link} points to a SHC.
100 public static boolean isTypeSHC(String link) {
101 return LINK_TYPE_SHC.equals(Link.getLinkType(link));
105 * Returns true, if the {@link Link} points to something unknown.
109 public static boolean isTypeUnknown(String link) {
110 return LINK_TYPE_UNKNOWN.equals(Link.getLinkType(link));