blob: 3ed9da0414db0c10c6702fba33bc0bad4d7156c2 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.ui.model.topo;
18
Simon Huntc0f20c12016-05-09 09:30:20 -070019import com.google.common.base.MoreObjects;
Simon Hunt23fb1352016-04-11 12:15:19 -070020import org.onosproject.net.Device;
Simon Hunt642bc452016-05-04 19:34:45 -070021import org.onosproject.net.DeviceId;
Simon Huntc0f20c12016-05-09 09:30:20 -070022import org.onosproject.net.region.RegionId;
Simon Hunt23fb1352016-04-11 12:15:19 -070023
Simon Hunt5f6dbf82016-03-30 08:53:33 -070024/**
25 * Represents a device.
26 */
27public class UiDevice extends UiNode {
Simon Hunt23fb1352016-04-11 12:15:19 -070028
Simon Huntc0f20c12016-05-09 09:30:20 -070029 private final UiTopology topology;
30 private final Device device;
31
32 private RegionId regionId;
33
34 /**
35 * Creates a new UI device.
36 *
37 * @param topology parent topology
38 * @param device backing device
39 */
40 public UiDevice(UiTopology topology, Device device) {
41 this.topology = topology;
42 this.device = device;
43 }
44
45 /**
46 * Sets the ID of the region to which this device belongs.
47 *
48 * @param regionId region identifier
49 */
50 public void setRegionId(RegionId regionId) {
51 this.regionId = regionId;
52 }
Simon Hunt23fb1352016-04-11 12:15:19 -070053
54 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070055 public String toString() {
56 return MoreObjects.toStringHelper(this)
57 .add("id", id())
58 .add("region", regionId)
59 .toString();
Simon Hunt23fb1352016-04-11 12:15:19 -070060 }
Simon Hunt642bc452016-05-04 19:34:45 -070061
Simon Huntc0f20c12016-05-09 09:30:20 -070062 // @Override
63// protected void destroy() {
64// }
65
Simon Hunt642bc452016-05-04 19:34:45 -070066 /**
67 * Returns the identity of the device.
68 *
69 * @return device ID
70 */
71 public DeviceId id() {
72 return device.id();
73 }
74
75 @Override
76 public String idAsString() {
77 return id().toString();
78 }
Simon Huntc0f20c12016-05-09 09:30:20 -070079
80 /**
81 * Returns the device instance backing this UI device.
82 *
83 * @return the backing device instance
84 */
85 public Device backingDevice() {
86 return device;
87 }
88
89 /**
Simon Hunt58a0dd02016-05-17 11:54:23 -070090 * Returns the identifier of the region to which this device belongs.
91 * This will be null if the device does not belong to any region.
92 *
93 * @return region identity
94 */
95 public RegionId regionId() {
96 return regionId;
97 }
98
99 /**
Simon Huntc0f20c12016-05-09 09:30:20 -0700100 * Returns the UI region to which this device belongs.
101 *
102 * @return the UI region
103 */
104 public UiRegion uiRegion() {
105 return topology.findRegion(regionId);
106 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700107}