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