Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 22 | import org.onosproject.net.region.RegionId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 23 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Represents a device. |
| 26 | */ |
| 27 | public class UiDevice extends UiNode { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 28 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 29 | 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 Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 53 | |
| 54 | @Override |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 55 | public String toString() { |
| 56 | return MoreObjects.toStringHelper(this) |
| 57 | .add("id", id()) |
| 58 | .add("region", regionId) |
| 59 | .toString(); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 60 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 61 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 62 | // @Override |
| 63 | // protected void destroy() { |
| 64 | // } |
| 65 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 66 | /** |
| 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 Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 79 | |
| 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 | /** |
| 90 | * Returns the UI region to which this device belongs. |
| 91 | * |
| 92 | * @return the UI region |
| 93 | */ |
| 94 | public UiRegion uiRegion() { |
| 95 | return topology.findRegion(regionId); |
| 96 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 97 | } |