Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [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.yangutils.datamodel; |
| 18 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 19 | import java.util.ArrayList; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 20 | import java.util.LinkedList; |
| 21 | import java.util.List; |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 22 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 25 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 26 | |
| 27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 28 | |
| 29 | /* |
| 30 | * Reference RFC 6020. |
| 31 | * |
| 32 | * YANG allows the definition of notifications suitable for NETCONF. |
| 33 | * YANG data definition statements are used to model the content of the |
| 34 | * notification. |
| 35 | * |
| 36 | * The "notification" statement is used to define a NETCONF |
| 37 | * notification. It takes one argument, which is an identifier, |
| 38 | * followed by a block of substatements that holds detailed notification |
| 39 | * information. The "notification" statement defines a notification |
| 40 | * node in the schema tree. |
| 41 | * |
| 42 | * If a leaf in the notification tree has a "mandatory" statement with |
| 43 | * the value "true", the leaf MUST be present in a NETCONF notification. |
| 44 | * |
| 45 | * If a leaf in the notification tree has a default value, the NETCONF |
| 46 | * client MUST use this value in the same cases as described in |
| 47 | * Section 7.6.1. In these cases, the client MUST operationally behave |
| 48 | * as if the leaf was present in the NETCONF notification with the |
| 49 | * default value as its value. |
| 50 | * |
| 51 | * If a "config" statement is present for any node in the notification |
| 52 | * tree, the "config" statement is ignored. |
| 53 | * |
| 54 | * The notification's substatements |
| 55 | * |
| 56 | * +--------------+---------+-------------+------------------+ |
| 57 | * | substatement | section | cardinality |data model mapping| |
| 58 | * +--------------+---------+-------------+------------------+ |
| 59 | * | anyxml | 7.10 | 0..n | -not supported | |
| 60 | * | choice | 7.9 | 0..n | -child nodes | |
| 61 | * | container | 7.5 | 0..n | -child nodes | |
| 62 | * | description | 7.19.3 | 0..1 | -string | |
| 63 | * | grouping | 7.11 | 0..n | -child nodes | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 64 | * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 65 | * | leaf | 7.6 | 0..n | -YangLeaf | |
| 66 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
| 67 | * | list | 7.8 | 0..n | -child nodes | |
| 68 | * | reference | 7.19.4 | 0..1 | -string | |
| 69 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 70 | * | typedef | 7.3 | 0..n | -child nodes | |
| 71 | * | uses | 7.12 | 0..n | -child nodes | |
| 72 | * +--------------+---------+-------------+------------------+ |
| 73 | */ |
| 74 | |
| 75 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 76 | * Represents data model node to maintain information defined in YANG notification. |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 77 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 78 | public class YangNotification |
| 79 | extends YangNode |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 80 | implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, |
| 81 | YangAugmentableNode, YangIfFeatureHolder { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 82 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 83 | private static final long serialVersionUID = 806201611L; |
| 84 | |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 85 | /** |
| 86 | * Name of the notification. |
| 87 | */ |
| 88 | private String name; |
| 89 | |
| 90 | /** |
| 91 | * Description of notification. |
| 92 | */ |
| 93 | private String description; |
| 94 | |
| 95 | /** |
| 96 | * List of leaves contained. |
| 97 | */ |
| 98 | private List<YangLeaf> listOfLeaf; |
| 99 | |
| 100 | /** |
| 101 | * List of leaf-lists contained. |
| 102 | */ |
| 103 | private List<YangLeafList> listOfLeafList; |
| 104 | |
| 105 | /** |
| 106 | * Reference of the module. |
| 107 | */ |
| 108 | private String reference; |
| 109 | |
| 110 | /** |
| 111 | * Status of the node. |
| 112 | */ |
| 113 | private YangStatusType status = YangStatusType.CURRENT; |
| 114 | |
| 115 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 116 | * List of if-feature. |
| 117 | */ |
| 118 | private List<YangIfFeature> ifFeatureList; |
| 119 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 120 | private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>(); |
| 121 | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 122 | /** |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 123 | * Create a notification node. |
| 124 | */ |
| 125 | public YangNotification() { |
| 126 | super(YangNodeType.NOTIFICATION_NODE); |
| 127 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 128 | listOfLeafList = new LinkedList<YangLeafList>(); |
| 129 | } |
| 130 | |
| 131 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 132 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 133 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 134 | // Detect colliding child. |
| 135 | detectCollidingChildUtil(identifierName, dataType, this); |
| 136 | } |
| 137 | |
| 138 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 139 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 140 | throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 141 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 142 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \"" |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 143 | + getName() + "\""); |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public YangConstructType getYangConstructType() { |
| 149 | return YangConstructType.NOTIFICATION_DATA; |
| 150 | } |
| 151 | |
| 152 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 153 | public void validateDataOnEntry() |
| 154 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 155 | //TODO: implement the method. |
| 156 | } |
| 157 | |
| 158 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 159 | public void validateDataOnExit() |
| 160 | throws DataModelException { |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 161 | //TODO: implement the method. |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public String getDescription() { |
| 166 | return description; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void setDescription(String description) { |
| 171 | this.description = description; |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public List<YangLeaf> getListOfLeaf() { |
| 176 | return listOfLeaf; |
| 177 | } |
| 178 | |
| 179 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 180 | public void setListOfLeaf(List<YangLeaf> leafsList) { |
| 181 | listOfLeaf = leafsList; |
| 182 | } |
| 183 | |
| 184 | @Override |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 185 | public void addLeaf(YangLeaf leaf) { |
| 186 | getListOfLeaf().add(leaf); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public List<YangLeafList> getListOfLeafList() { |
| 191 | return listOfLeafList; |
| 192 | } |
| 193 | |
| 194 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 195 | public void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
| 196 | this.listOfLeafList = listOfLeafList; |
| 197 | } |
| 198 | |
| 199 | @Override |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 200 | public void addLeafList(YangLeafList leafList) { |
| 201 | getListOfLeafList().add(leafList); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public String getName() { |
| 206 | return name; |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void setName(String name) { |
| 211 | this.name = name; |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public String getReference() { |
| 216 | return reference; |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void setReference(String reference) { |
| 221 | this.reference = reference; |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public YangStatusType getStatus() { |
| 226 | return status; |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void setStatus(YangStatusType status) { |
| 231 | this.status = status; |
| 232 | } |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 233 | |
| 234 | @Override |
| 235 | public List<YangIfFeature> getIfFeatureList() { |
| 236 | return ifFeatureList; |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 241 | if (getIfFeatureList() == null) { |
| 242 | setIfFeatureList(new LinkedList<>()); |
| 243 | } |
| 244 | getIfFeatureList().add(ifFeature); |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 249 | this.ifFeatureList = ifFeatureList; |
| 250 | } |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 251 | |
| 252 | @Override |
| 253 | public void addAugmentation(YangAugmentedInfo augmentInfo) { |
| 254 | yangAugmentedInfo.add(augmentInfo); |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void removeAugmentation(YangAugmentedInfo augmentInfo) { |
| 259 | yangAugmentedInfo.remove(augmentInfo); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public List<YangAugmentedInfo> getAugmentedInfoList() { |
| 264 | return yangAugmentedInfo; |
| 265 | } |
Gaurav Agrawal | e3ed0d9 | 2016-03-23 19:04:17 +0530 | [diff] [blame] | 266 | } |