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.livisismarthome.internal.client.api.entity.link;
16 * Defines the data structure for a {@link LinkDTO}. This is the basic component used to link different data types in
20 * @author Oliver Kuhl - Initial contribution
22 public class LinkDTO {
24 public static final String LINK_TYPE_CAPABILITY = "/capability/";
25 public static final String LINK_TYPE_DEVICE = "/device/";
26 public static final String LINK_TYPE_MESSAGE = "/message/";
27 public static final String LINK_TYPE_SHC = "/desc/device/SHC.RWE/";
28 public static final String LINK_TYPE_UNKNOWN = "unknown";
31 * Returns the Type of the {@link LinkDTO}.
33 * @return {@link #LINK_TYPE_CAPABILITY},{@link #LINK_TYPE_DEVICE}, {@link #LINK_TYPE_MESSAGE},
34 * {@link #LINK_TYPE_SHC} or {@link #LINK_TYPE_UNKNOWN}
36 public static String getLinkType(String link) {
37 if (link.startsWith(LINK_TYPE_CAPABILITY)) {
38 return LINK_TYPE_CAPABILITY;
39 } else if (link.startsWith(LINK_TYPE_DEVICE)) {
40 return LINK_TYPE_DEVICE;
41 } else if (link.startsWith(LINK_TYPE_MESSAGE)) {
42 return LINK_TYPE_MESSAGE;
43 } else if (link.startsWith(LINK_TYPE_SHC)) {
46 return LINK_TYPE_UNKNOWN;
51 * Returns the id of the {@link LinkDTO} or null, if the link does not have an id or even no value.
53 * @return String the id of the link or null
55 public static String getId(String link) {
57 final String linkType = getLinkType(link);
58 if (linkType != null && !LinkDTO.LINK_TYPE_UNKNOWN.equals(linkType)
59 && !LinkDTO.LINK_TYPE_SHC.equals(linkType)) {
60 return link.replace(linkType, "");
67 * Returns true, if the {@link LinkDTO} points to a
68 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityDTO}.
70 * @return true if the link points to a capability, otherwise false
72 public static boolean isTypeCapability(String link) {
73 return LINK_TYPE_CAPABILITY.equals(LinkDTO.getLinkType(link));
77 * Returns true, if the {@link LinkDTO} points to a
78 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
80 * @return true if the link points to a device, otherwise false
82 public static boolean isTypeDevice(String link) {
83 return LINK_TYPE_DEVICE.equals(LinkDTO.getLinkType(link));
87 * Returns true, if the {@link LinkDTO} points to a
88 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.message.MessageDTO}.
90 * @return true if the link points to a message, otherwise false
92 public static boolean isTypeMessage(String link) {
93 return LINK_TYPE_MESSAGE.equals(LinkDTO.getLinkType(link));
97 * Returns true, if the {@link LinkDTO} points to a SHC.
99 * @return true if the link points to a SHC bridge device, otherwise false
101 public static boolean isTypeSHC(String link) {
102 return LINK_TYPE_SHC.equals(LinkDTO.getLinkType(link));
106 * Returns true, if the {@link LinkDTO} points to something unknown.
108 * @return true if the link points to something unknown, otherwise false
110 public static boolean isTypeUnknown(String link) {
111 return LINK_TYPE_UNKNOWN.equals(LinkDTO.getLinkType(link));