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