Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 static com.google.common.base.MoreObjects.toStringHelper; |
| 20 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 21 | /** |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 22 | * Represents a link (line between two elements). This may be one of |
| 23 | * several concrete subclasses: |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 24 | * <ul> |
| 25 | * <li> |
| 26 | * An infrastructure link: |
| 27 | * two backing unidirectional links between two devices. |
| 28 | * </li> |
| 29 | * <li> |
| 30 | * An edge link: |
| 31 | * representing the connection between a host and a device. |
| 32 | * </li> |
| 33 | * <li> |
| 34 | * An aggregation link: |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 35 | * representing multiple underlying UI link instances, for example |
| 36 | * the link between two sub-regions in a region (layout). |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 37 | * </li> |
| 38 | * </ul> |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 39 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 40 | public abstract class UiLink extends UiElement { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 41 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 42 | protected final UiTopology topology; |
| 43 | protected final UiLinkId id; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Creates a UI link. |
| 47 | * |
| 48 | * @param topology parent topology |
| 49 | * @param id canonicalized link identifier |
| 50 | */ |
| 51 | public UiLink(UiTopology topology, UiLinkId id) { |
| 52 | this.topology = topology; |
| 53 | this.id = id; |
| 54 | } |
| 55 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 56 | @Override |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 57 | public String toString() { |
| 58 | return toStringHelper(this) |
| 59 | .add("id", id) |
| 60 | .toString(); |
| 61 | } |
| 62 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Returns the canonicalized link identifier for this link. |
| 65 | * |
| 66 | * @return the link identifier |
| 67 | */ |
| 68 | public UiLinkId id() { |
| 69 | return id; |
| 70 | } |
| 71 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 72 | @Override |
| 73 | public String idAsString() { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 74 | return id.toString(); |
| 75 | } |
| 76 | |
| 77 | /** |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 78 | * Returns the implementing class name as the type of link. |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 79 | * |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 80 | * @return link type |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 81 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 82 | public String type() { |
| 83 | return getClass().getSimpleName(); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 87 | * Returns the identifier of end-point A in string form. |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 88 | * |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 89 | * @return end point A identifier |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 90 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 91 | public abstract String endPointA(); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 94 | * Returns the identifier of end-point B in string form. |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 95 | * |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 96 | * @return end point B identifier |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 97 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 98 | public abstract String endPointB(); |
Simon Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Returns the port number (as a string) for end-point A, if applicable. |
| 102 | * This default implementation returns null, indicating not-applicable. |
| 103 | * Subclasses only need to override this method if end-point A has an |
| 104 | * associated port. |
| 105 | * |
| 106 | * @return port number for end-point A |
| 107 | */ |
| 108 | public String endPortA() { |
| 109 | return null; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns the port number (as a string) for end-point B, if applicable. |
| 114 | * This default implementation returns null, indicating not-applicable. |
| 115 | * Subclasses only need to override this method if end-point B has an |
| 116 | * associated port. |
| 117 | * |
| 118 | * @return port number for end-point B |
| 119 | */ |
| 120 | public String endPortB() { |
| 121 | return null; |
| 122 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 123 | } |