blob: 0484b0eb1d1dc66c8b7dbc49af6f64b94f202ba0 [file] [log] [blame]
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05303 *
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.yangutils.datamodel;
18
Bharat saraswalb1170bd2016-07-14 13:26:18 +053019import java.util.ArrayList;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053020import java.util.LinkedList;
21import java.util.List;
Bharat saraswald9822e92016-04-05 15:13:44 +053022
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053023import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053024import org.onosproject.yangutils.datamodel.utils.Parsable;
25import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053026
27import 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 Ramadeac28b2016-06-20 15:12:43 +053064 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053065 * | 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 saraswald9822e92016-04-05 15:13:44 +053076 * Represents data model node to maintain information defined in YANG notification.
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053077 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053078public class YangNotification
79 extends YangNode
Bharat saraswalb1170bd2016-07-14 13:26:18 +053080 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
81 YangAugmentableNode, YangIfFeatureHolder {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053082
Bharat saraswal96dfef02016-06-16 00:29:12 +053083 private static final long serialVersionUID = 806201611L;
84
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053085 /**
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 Ramadeac28b2016-06-20 15:12:43 +0530116 * List of if-feature.
117 */
118 private List<YangIfFeature> ifFeatureList;
119
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530120 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
121
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530122 /**
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530123 * Create a notification node.
124 */
125 public YangNotification() {
126 super(YangNodeType.NOTIFICATION_NODE);
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530127 listOfLeaf = new LinkedList<>();
128 listOfLeafList = new LinkedList<>();
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530129 }
130
131 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530132 public void detectCollidingChild(String identifierName, YangConstructType dataType)
133 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530134 // Detect colliding child.
135 detectCollidingChildUtil(identifierName, dataType, this);
136 }
137
138 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530139 public void detectSelfCollision(String identifierName, YangConstructType dataType)
140 throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530141 if (getName().equals(identifierName)) {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530142 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \""
Bharat saraswal96dfef02016-06-16 00:29:12 +0530143 + getName() + "\"");
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530144 }
145 }
146
147 @Override
148 public YangConstructType getYangConstructType() {
149 return YangConstructType.NOTIFICATION_DATA;
150 }
151
152 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530153 public void validateDataOnEntry()
154 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530155 //TODO: implement the method.
156 }
157
158 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530159 public void validateDataOnExit()
160 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530161 //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-Huawei2ee9e7e2016-06-01 14:30:22 +0530180 public void setListOfLeaf(List<YangLeaf> leafsList) {
181 listOfLeaf = leafsList;
182 }
183
184 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530185 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-Huawei2ee9e7e2016-06-01 14:30:22 +0530195 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
196 this.listOfLeafList = listOfLeafList;
197 }
198
199 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530200 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 Ramadeac28b2016-06-20 15:12:43 +0530233
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 saraswalb1170bd2016-07-14 13:26:18 +0530251
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 Agrawale3ed0d92016-03-23 19:04:17 +0530266}