blob: 2b2426a2c9009504e4a2b54aca10faa8aadb847f [file] [log] [blame]
Vinod Kumar S67e7be62016-02-11 20:13:28 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S67e7be62016-02-11 20:13:28 +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
Vinod Kumar S38046502016-03-23 15:30:27 +053019import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053020import org.onosproject.yangutils.datamodel.utils.Parsable;
21import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053022import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Vinod Kumar S38046502016-03-23 15:30:27 +053023
janani b23ccc312016-07-14 19:35:22 +053024import java.util.ArrayList;
25import java.util.LinkedList;
26import java.util.List;
27
Vinod Kumar S38046502016-03-23 15:30:27 +053028import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
29
30/*
Vinod Kumar S67e7be62016-02-11 20:13:28 +053031 * The "list" statement is used to define an interior data node in the
32 * schema tree. A list node may exist in multiple instances in the data
33 * tree. Each such instance is known as a list entry. The "list"
34 * statement takes one argument, which is an identifier, followed by a
35 * block of sub-statements that holds detailed list information.
36 *
37 * A list entry is uniquely identified by the values of the list's keys,
38 * if defined.
39 *
40 * The list's sub-statements
41 *
42 * +--------------+---------+-------------+------------------+
43 * | substatement | section | cardinality |data model mapping|
44 * +--------------+---------+-------------+------------------+
45 * | anyxml | 7.10 | 0..n |-not supported |
46 * | choice | 7.9 | 0..n |-child nodes |
47 * | config | 7.19.1 | 0..1 |-boolean |
48 * | container | 7.5 | 0..n |-child nodes |
49 * | description | 7.19.3 | 0..1 |-string |
50 * | grouping | 7.11 | 0..n |-child nodes |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053051 * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053052 * | key | 7.8.2 | 0..1 |-String list |
53 * | leaf | 7.6 | 0..n |-YangLeaf |
54 * | leaf-list | 7.7 | 0..n |-YangLeafList |
55 * | list | 7.8 | 0..n |-child nodes |
56 * | max-elements | 7.7.4 | 0..1 |-int |
57 * | min-elements | 7.7.3 | 0..1 |-int |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053058 * | must | 7.5.3 | 0..n |-YangMust |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053059 * | ordered-by | 7.7.5 | 0..1 |-TODO |
60 * | reference | 7.19.4 | 0..1 |-string |
61 * | status | 7.19.2 | 0..1 |-YangStatus |
62 * | typedef | 7.3 | 0..n |-child nodes |
63 * | unique | 7.8.3 | 0..n |-TODO |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053064 * | uses | 7.12 | 0..n |-child nodes |
65 * | when | 7.19.5 | 0..1 |-YangWhen |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053066 * +--------------+---------+-------------+------------------+
67 */
68
69/**
Bharat saraswald9822e92016-04-05 15:13:44 +053070 * Represents list data represented in YANG.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053071 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053072public class YangList
73 extends YangNode
Bharat saraswalb1170bd2016-07-14 13:26:18 +053074 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
75 YangAugmentableNode, YangMustHolder, YangIfFeatureHolder, YangDataNode {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053076
Bharat saraswal96dfef02016-06-16 00:29:12 +053077 private static final long serialVersionUID = 806201609L;
78
Vinod Kumar S67e7be62016-02-11 20:13:28 +053079 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053080 * Name of the YANG list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053081 */
82 private String name;
83
84 /**
85 * If list maintains config data.
86 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053087 private Boolean isConfig;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053088
89 /**
90 * Description of list.
91 */
92 private String description;
93
94 /**
95 * Reference RFC 6020.
96 *
97 * The "key" statement, which MUST be present if the list represents
98 * configuration, and MAY be present otherwise, takes as an argument a
99 * string that specifies a space-separated list of leaf identifiers of this
100 * list. A leaf identifier MUST NOT appear more than once in the key. Each
101 * such leaf identifier MUST refer to a child leaf of the list. The leafs
102 * can be defined directly in sub-statements to the list, or in groupings
103 * used in the list.
104 *
105 * The combined values of all the leafs specified in the key are used to
106 * uniquely identify a list entry. All key leafs MUST be given values when a
107 * list entry is created. Thus, any default values in the key leafs or their
108 * types are ignored. It also implies that any mandatory statement in the
109 * key leafs are ignored.
110 *
111 * A leaf that is part of the key can be of any built-in or derived type,
112 * except it MUST NOT be the built-in type "empty".
113 *
114 * All key leafs in a list MUST have the same value for their "config" as
115 * the list itself.
116 *
117 * List of key leaf names.
118 */
119 private List<String> keyList;
120
121 /**
janani b23ccc312016-07-14 19:35:22 +0530122 * Reference RFC 6020.
123 *
124 * The "unique" statement is used to put constraints on valid list
125 * entries. It takes as an argument a string that contains a space-
126 * separated list of schema node identifiers, which MUST be given in the
127 * descendant form. Each such schema node identifier MUST refer to a leaf.
128 *
129 * If one of the referenced leafs represents configuration data, then
130 * all of the referenced leafs MUST represent configuration data.
131 *
132 * The "unique" constraint specifies that the combined values of all the
133 * leaf instances specified in the argument string, including leafs with
134 * default values, MUST be unique within all list entry instances in
135 * which all referenced leafs exist.
136 *
137 * List of unique leaf/leaf-list names
138 */
139 private List<String> uniqueList;
140
141 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530142 * List of leaves.
143 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530144 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530145
146 /**
147 * List of leaf-lists.
148 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530149 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530150
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530151 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
152
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530153 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530154 * Reference RFC 6020.
155 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530156 * The "max-elements" statement, which is optional, takes as an argument a
157 * positive integer or the string "unbounded", which puts a constraint on
158 * valid list entries. A valid leaf-list or list always has at most
159 * max-elements entries.
160 *
161 * If no "max-elements" statement is present, it defaults to "unbounded".
162 */
rama-huawei6c728a92016-07-11 14:48:12 +0530163 private YangMaxElement maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530164
165 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530166 * Reference RFC 6020.
167 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530168 * The "min-elements" statement, which is optional, takes as an argument a
169 * non-negative integer that puts a constraint on valid list entries. A
170 * valid leaf-list or list MUST have at least min-elements entries.
171 *
172 * If no "min-elements" statement is present, it defaults to zero.
173 *
174 * The behavior of the constraint depends on the type of the leaf-list's or
175 * list's closest ancestor node in the schema tree that is not a non-
176 * presence container:
177 *
178 * o If this ancestor is a case node, the constraint is enforced if any
179 * other node from the case exists.
180 *
181 * o Otherwise, it is enforced if the ancestor node exists.
182 */
rama-huawei6c728a92016-07-11 14:48:12 +0530183 private YangMinElement minElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530184
185 /**
186 * reference.
187 */
188 private String reference;
189
190 /**
191 * Status of the node.
192 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530193 private YangStatusType status = YangStatusType.CURRENT;
194
195 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530196 * List of must statement constraints.
197 */
198 private List<YangMust> mustConstraintList;
199
200 /**
201 * When data of the node.
202 */
203 private YangWhen when;
204
205 /**
206 * List of if-feature.
207 */
208 private List<YangIfFeature> ifFeatureList;
209
210 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530211 * Creates a YANG list object.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530212 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530213 public YangList() {
214 super(YangNodeType.LIST_NODE);
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530215 }
216
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530217 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530218 * Returns the when.
219 *
220 * @return the when
221 */
222 public YangWhen getWhen() {
223 return when;
224 }
225
226 /**
227 * Sets the when.
228 *
229 * @param when the when to set
230 */
231 public void setWhen(YangWhen when) {
232 this.when = when;
233 }
234
235 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530236 * Returns the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530237 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530238 * @return YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530239 */
240 @Override
241 public String getName() {
242 return name;
243 }
244
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530245 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530246 * Sets the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530247 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530248 * @param name YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530249 */
250 @Override
251 public void setName(String name) {
252 this.name = name;
253 }
254
255 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530256 * Returns the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530257 *
258 * @return the isConfig
259 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530260 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530261 return isConfig;
262 }
263
264 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530265 * Sets the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530266 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530267 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530268 */
269 public void setConfig(boolean isCfg) {
270 isConfig = isCfg;
271 }
272
273 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530274 * Returns the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530275 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530277 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530278 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530279 public String getDescription() {
280 return description;
281 }
282
283 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530284 * Sets the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530285 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530286 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530287 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530288 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530289 public void setDescription(String description) {
290 this.description = description;
291 }
292
293 /**
janani b23ccc312016-07-14 19:35:22 +0530294 * Returns the list of unique field names.
295 *
296 * @return the list of unique field names
297 */
298 public List<String> getUniqueList() {
299 return uniqueList;
300 }
301
302 /**
303 * Sets the list of unique field names.
304 *
305 * @param uniqueList the list of unique field names
306 */
307 private void setUniqueList(List<String> uniqueList) {
308 this.uniqueList = uniqueList;
309 }
310
311 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530312 * Returns the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530313 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530314 * @return the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530315 */
316 public List<String> getKeyList() {
317 return keyList;
318 }
319
320 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530321 * Sets the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530322 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530323 * @param keyList the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530324 */
325 private void setKeyList(List<String> keyList) {
326 this.keyList = keyList;
327 }
328
329 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530330 * Adds a key field name.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530331 *
332 * @param key key field name.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530333 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530334 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530335 public void addKey(String key)
336 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530337 if (getKeyList() == null) {
338 setKeyList(new LinkedList<String>());
339 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530340
341 if (getKeyList().contains(key)) {
342 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
343 " key");
344 }
345
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530346 getKeyList().add(key);
347 }
348
349 /**
janani b23ccc312016-07-14 19:35:22 +0530350 * Adds a unique field name.
351 *
352 * @param unique unique field name.
353 * @throws DataModelException a violation of data model rules
354 */
355 public void addUnique(String unique)
356 throws DataModelException {
357 if (getUniqueList() == null) {
358 setUniqueList(new LinkedList<>());
359 }
360 if (getUniqueList().contains(unique)) {
361 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
362 " unique");
363 }
364 getUniqueList().add(unique);
365 }
366
367 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530368 * Returns the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530369 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530370 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530371 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530372 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530373 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530374 return listOfLeaf;
375 }
376
377 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530378 * Sets the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530379 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530380 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530381 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530382 @Override
383 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530384 listOfLeaf = leafsList;
385 }
386
387 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530388 * Adds a leaf.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530389 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530390 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530391 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530392 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530393 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530394 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530395 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530396 }
397
398 getListOfLeaf().add(leaf);
399 }
400
401 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530402 * Returns the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530403 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530404 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530405 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530406 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530407 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530408 return listOfLeafList;
409 }
410
411 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530412 * Sets the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530414 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530415 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530416 @Override
417 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530418 this.listOfLeafList = listOfLeafList;
419 }
420
421 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530422 * Adds a leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530423 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530424 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530425 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530426 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530427 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530428 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530429 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530430 }
431
432 getListOfLeafList().add(leafList);
433 }
434
435 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530436 * Returns the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530437 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530438 * @return the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530439 */
rama-huawei6c728a92016-07-11 14:48:12 +0530440 public YangMaxElement getMaxElements() {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530441 return maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530442 }
443
444 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530445 * Sets the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530446 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530447 * @param max the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530448 */
rama-huawei6c728a92016-07-11 14:48:12 +0530449 public void setMaxElements(YangMaxElement max) {
450 this.maxElements = max;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530451 }
452
453 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530454 * Returns the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530455 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530456 * @return the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530457 */
rama-huawei6c728a92016-07-11 14:48:12 +0530458 public YangMinElement getMinElements() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530459 return minElements;
460 }
461
462 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530463 * Sets the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530464 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530465 * @param minElements the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530466 */
rama-huawei6c728a92016-07-11 14:48:12 +0530467 public void setMinElements(YangMinElement minElements) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530468 this.minElements = minElements;
469 }
470
471 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530472 * Returns the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530473 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530474 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530475 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530476 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530477 public String getReference() {
478 return reference;
479 }
480
481 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530482 * Sets the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530483 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530484 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530485 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530486 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530487 public void setReference(String reference) {
488 this.reference = reference;
489 }
490
491 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530492 * Returns the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530493 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530494 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530495 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530496 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530497 public YangStatusType getStatus() {
498 return status;
499 }
500
501 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530502 * Sets the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530503 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530504 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530505 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530506 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530507 public void setStatus(YangStatusType status) {
508 this.status = status;
509 }
510
511 /**
512 * Returns the type of the parsed data.
513 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530514 * @return returns LIST_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530515 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530516 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530517 public YangConstructType getYangConstructType() {
518 return YangConstructType.LIST_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530519 }
520
521 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530522 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530523 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530524 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530525 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530526 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530527 public void validateDataOnEntry()
528 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530529 // TODO auto-generated method stub, to be implemented by parser
530 }
531
532 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530533 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530534 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530535 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530536 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530537 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530538 public void validateDataOnExit()
539 throws DataModelException {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530540 List<String> keys = getKeyList();
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530541 List<YangLeaf> leaves = getListOfLeaf();
542 List<YangLeafList> leafLists = getListOfLeafList();
543
544 setDefaultConfigValueToChild(leaves, leafLists);
545 validateConfig(leaves, leafLists);
546
547 /* A list must have atleast one key leaf if config is true */
janani b23ccc312016-07-14 19:35:22 +0530548 if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList()
janani bdd1314f2016-05-19 17:39:50 +0530549 && !isListPresentInGrouping()) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530550 throw new DataModelException("A list must have atleast one key leaf if config is true;");
551 } else if (keys != null) {
janani b23ccc312016-07-14 19:35:22 +0530552 validateKey(leaves, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530553 }
554 }
555
556 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530557 * Sets the config's value to all leaf if leaf's config statement is not
558 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530559 *
janani b23ccc312016-07-14 19:35:22 +0530560 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530561 * @param leafLists list of leaf-list attributes of YANG list
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530562 */
563 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
564
Vinod Kumar S71cba682016-02-25 15:52:16 +0530565 /*
566 * If "config" is not specified, the default is the same as the parent
567 * schema node's "config" value.
568 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530569 if (leaves != null) {
570 for (YangLeaf leaf : leaves) {
571 if (leaf.isConfig() == null) {
572 leaf.setConfig(isConfig);
573 }
574 }
575 }
576
Vinod Kumar S71cba682016-02-25 15:52:16 +0530577 /*
578 * If "config" is not specified, the default is the same as the parent
579 * schema node's "config" value.
580 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530581 if (leafLists != null) {
582 for (YangLeafList leafList : leafLists) {
583 if (leafList.isConfig() == null) {
584 leafList.setConfig(isConfig);
585 }
586 }
587 }
588 }
589
590 /**
591 * Validates config statement of YANG list.
592 *
janani b23ccc312016-07-14 19:35:22 +0530593 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530594 * @param leafLists list of leaf-list attributes of YANG list
595 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530596 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530597 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
598 throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530599
Vinod Kumar S71cba682016-02-25 15:52:16 +0530600 /*
601 * If a node has "config" set to "false", no node underneath it can have
602 * "config" set to "true".
603 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530604 if (!isConfig && leaves != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530605 for (YangLeaf leaf : leaves) {
606 if (leaf.isConfig()) {
607 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
608 "it can have \"config\" set to \"true\".");
609 }
610 }
611 }
612
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530613 if (!isConfig && leafLists != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530614 for (YangLeafList leafList : leafLists) {
615 if (leafList.isConfig()) {
616 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
617 "it can have \"config\" set to \"true\".");
618 }
619 }
620 }
621 }
622
623 /**
624 * Validates key statement of list.
625 *
janani b23ccc312016-07-14 19:35:22 +0530626 * @param leaves list of leaf attributes of list
Vidyashree Rama1db15562016-05-17 16:16:15 +0530627 * @param leafLists list of leaf-list attributes of list
janani b23ccc312016-07-14 19:35:22 +0530628 * @param keys list of key attributes of list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530629 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530630 */
janani b23ccc312016-07-14 19:35:22 +0530631 private void validateKey(List<YangLeaf> leaves, List<String> keys)
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530632 throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530633 boolean leafFound = false;
634 List<YangLeaf> keyLeaves = new LinkedList<>();
635
Vinod Kumar S71cba682016-02-25 15:52:16 +0530636 /*
637 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
638 * that is part of the key must not be the built-in type "empty".
639 */
640 for (String key : keys) {
Vidyashree Rama1db15562016-05-17 16:16:15 +0530641 if (leaves != null && !leaves.isEmpty()) {
642 for (YangLeaf leaf : leaves) {
643 if (key.equals(leaf.getName())) {
644 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
645 throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
646 "type \"empty\".");
647 }
648 leafFound = true;
649 keyLeaves.add(leaf);
650 break;
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530651 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530652 }
653 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530654
janani bdd1314f2016-05-19 17:39:50 +0530655 if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) {
Vidyashree Rama1db15562016-05-17 16:16:15 +0530656 throw new DataModelException("An identifier, in key, must refer to a child leaf of the list");
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530657 }
658 leafFound = false;
659 }
660
Vinod Kumar S71cba682016-02-25 15:52:16 +0530661 /*
662 * All key leafs in a list MUST have the same value for their "config"
663 * as the list itself.
664 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530665 for (YangLeaf keyLeaf : keyLeaves) {
666 if (isConfig != keyLeaf.isConfig()) {
667 throw new DataModelException("All key leafs in a list must have the same value for their" +
668 " \"config\" as the list itself.");
669 }
670 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530671 }
672
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530673 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530674 public void detectCollidingChild(String identifierName, YangConstructType dataType)
675 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530676 // Asks helper to detect colliding child.
677 detectCollidingChildUtil(identifierName, dataType, this);
678 }
679
680 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530681 public void detectSelfCollision(String identifierName, YangConstructType dataType)
682 throws DataModelException {
Vinod Kumar S38046502016-03-23 15:30:27 +0530683 if (getName().equals(identifierName)) {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530684 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
Vinod Kumar S38046502016-03-23 15:30:27 +0530685 getName() + "\"");
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530686 }
687 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530688
689 private boolean isUsesPresentInList() {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530690 YangNode node = getChild();
Vidyashree Rama1db15562016-05-17 16:16:15 +0530691 while (node != null) {
692 if (node instanceof YangUses) {
693 return true;
694 }
695 node = node.getNextSibling();
696 }
697 return false;
janani bdd1314f2016-05-19 17:39:50 +0530698 // TODO When grouping linking is done this method has to be modified.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530699 }
700
janani bdd1314f2016-05-19 17:39:50 +0530701 private boolean isListPresentInGrouping() {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530702 YangNode node = getParent();
janani bdd1314f2016-05-19 17:39:50 +0530703 while (node != null) {
704 if (node instanceof YangGrouping) {
705 return true;
706 }
707 node = node.getParent();
708 }
709 return false;
710 // TODO When grouping linking is done this method has to be modified.
711 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530712
713 @Override
714 public List<YangIfFeature> getIfFeatureList() {
715 return ifFeatureList;
716 }
717
718 @Override
719 public void addIfFeatureList(YangIfFeature ifFeature) {
720 if (getIfFeatureList() == null) {
721 setIfFeatureList(new LinkedList<>());
722 }
723 getIfFeatureList().add(ifFeature);
724 }
725
726 @Override
727 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
728 this.ifFeatureList = ifFeatureList;
729 }
730
731 @Override
732 public List<YangMust> getListOfMust() {
733 return mustConstraintList;
734 }
735
736 @Override
737 public void setListOfMust(List<YangMust> mustConstraintList) {
738 this.mustConstraintList = mustConstraintList;
739 }
740
741 @Override
742 public void addMust(YangMust must) {
743 if (getListOfMust() == null) {
744 setListOfMust(new LinkedList<>());
745 }
746 getListOfMust().add(must);
747 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530748
749 @Override
750 public void addAugmentation(YangAugmentedInfo augmentInfo) {
751 yangAugmentedInfo.add(augmentInfo);
752 }
753
754 @Override
755 public void removeAugmentation(YangAugmentedInfo augmentInfo) {
756 yangAugmentedInfo.remove(augmentInfo);
757 }
758
759 @Override
760 public List<YangAugmentedInfo> getAugmentedInfoList() {
761 return yangAugmentedInfo;
762 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530763}