blob: b86911af9f1ab0a6f6eefd075d1f57942df2fd8b [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
Vidyashree Rama07c26bb2016-07-28 17:33:15 +053019import java.util.ArrayList;
20import java.util.LinkedList;
21import java.util.List;
Vinod Kumar S38046502016-03-23 15:30:27 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053023import org.onosproject.yangutils.datamodel.utils.Parsable;
24import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053025import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Vinod Kumar S38046502016-03-23 15:30:27 +053026
27import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
28
29/*
Vinod Kumar S67e7be62016-02-11 20:13:28 +053030 * The "list" statement is used to define an interior data node in the
31 * schema tree. A list node may exist in multiple instances in the data
32 * tree. Each such instance is known as a list entry. The "list"
33 * statement takes one argument, which is an identifier, followed by a
34 * block of sub-statements that holds detailed list information.
35 *
36 * A list entry is uniquely identified by the values of the list's keys,
37 * if defined.
38 *
39 * The list's sub-statements
40 *
41 * +--------------+---------+-------------+------------------+
42 * | substatement | section | cardinality |data model mapping|
43 * +--------------+---------+-------------+------------------+
44 * | anyxml | 7.10 | 0..n |-not supported |
45 * | choice | 7.9 | 0..n |-child nodes |
46 * | config | 7.19.1 | 0..1 |-boolean |
47 * | container | 7.5 | 0..n |-child nodes |
48 * | description | 7.19.3 | 0..1 |-string |
49 * | grouping | 7.11 | 0..n |-child nodes |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053050 * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053051 * | key | 7.8.2 | 0..1 |-String list |
52 * | leaf | 7.6 | 0..n |-YangLeaf |
53 * | leaf-list | 7.7 | 0..n |-YangLeafList |
54 * | list | 7.8 | 0..n |-child nodes |
55 * | max-elements | 7.7.4 | 0..1 |-int |
56 * | min-elements | 7.7.3 | 0..1 |-int |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053057 * | must | 7.5.3 | 0..n |-YangMust |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053058 * | ordered-by | 7.7.5 | 0..1 |-TODO |
59 * | reference | 7.19.4 | 0..1 |-string |
60 * | status | 7.19.2 | 0..1 |-YangStatus |
61 * | typedef | 7.3 | 0..n |-child nodes |
62 * | unique | 7.8.3 | 0..n |-TODO |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053063 * | uses | 7.12 | 0..n |-child nodes |
64 * | when | 7.19.5 | 0..1 |-YangWhen |
Vinod Kumar S67e7be62016-02-11 20:13:28 +053065 * +--------------+---------+-------------+------------------+
66 */
67
68/**
Bharat saraswald9822e92016-04-05 15:13:44 +053069 * Represents list data represented in YANG.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053070 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053071public class YangList
72 extends YangNode
Bharat saraswalb1170bd2016-07-14 13:26:18 +053073 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
Vidyashree Rama07c26bb2016-07-28 17:33:15 +053074 YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053075
Bharat saraswal96dfef02016-06-16 00:29:12 +053076 private static final long serialVersionUID = 806201609L;
77
Vinod Kumar S67e7be62016-02-11 20:13:28 +053078 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053079 * Name of the YANG list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053080 */
81 private String name;
82
83 /**
84 * If list maintains config data.
85 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053086 private Boolean isConfig;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053087
88 /**
89 * Description of list.
90 */
91 private String description;
92
93 /**
94 * Reference RFC 6020.
95 *
96 * The "key" statement, which MUST be present if the list represents
97 * configuration, and MAY be present otherwise, takes as an argument a
98 * string that specifies a space-separated list of leaf identifiers of this
99 * list. A leaf identifier MUST NOT appear more than once in the key. Each
100 * such leaf identifier MUST refer to a child leaf of the list. The leafs
101 * can be defined directly in sub-statements to the list, or in groupings
102 * used in the list.
103 *
104 * The combined values of all the leafs specified in the key are used to
105 * uniquely identify a list entry. All key leafs MUST be given values when a
106 * list entry is created. Thus, any default values in the key leafs or their
107 * types are ignored. It also implies that any mandatory statement in the
108 * key leafs are ignored.
109 *
110 * A leaf that is part of the key can be of any built-in or derived type,
111 * except it MUST NOT be the built-in type "empty".
112 *
113 * All key leafs in a list MUST have the same value for their "config" as
114 * the list itself.
115 *
116 * List of key leaf names.
117 */
118 private List<String> keyList;
119
120 /**
janani b23ccc312016-07-14 19:35:22 +0530121 * Reference RFC 6020.
122 *
123 * The "unique" statement is used to put constraints on valid list
124 * entries. It takes as an argument a string that contains a space-
125 * separated list of schema node identifiers, which MUST be given in the
126 * descendant form. Each such schema node identifier MUST refer to a leaf.
127 *
128 * If one of the referenced leafs represents configuration data, then
129 * all of the referenced leafs MUST represent configuration data.
130 *
131 * The "unique" constraint specifies that the combined values of all the
132 * leaf instances specified in the argument string, including leafs with
133 * default values, MUST be unique within all list entry instances in
134 * which all referenced leafs exist.
135 *
136 * List of unique leaf/leaf-list names
137 */
138 private List<String> uniqueList;
139
140 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530141 * List of leaves.
142 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530143 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530144
145 /**
146 * List of leaf-lists.
147 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530148 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530149
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530150 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
151
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530152 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530153 * Reference RFC 6020.
154 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530155 * The "max-elements" statement, which is optional, takes as an argument a
156 * positive integer or the string "unbounded", which puts a constraint on
157 * valid list entries. A valid leaf-list or list always has at most
158 * max-elements entries.
159 *
160 * If no "max-elements" statement is present, it defaults to "unbounded".
161 */
rama-huawei6c728a92016-07-11 14:48:12 +0530162 private YangMaxElement maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530163
164 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530165 * Reference RFC 6020.
166 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530167 * The "min-elements" statement, which is optional, takes as an argument a
168 * non-negative integer that puts a constraint on valid list entries. A
169 * valid leaf-list or list MUST have at least min-elements entries.
170 *
171 * If no "min-elements" statement is present, it defaults to zero.
172 *
173 * The behavior of the constraint depends on the type of the leaf-list's or
174 * list's closest ancestor node in the schema tree that is not a non-
175 * presence container:
176 *
177 * o If this ancestor is a case node, the constraint is enforced if any
178 * other node from the case exists.
179 *
180 * o Otherwise, it is enforced if the ancestor node exists.
181 */
rama-huawei6c728a92016-07-11 14:48:12 +0530182 private YangMinElement minElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530183
184 /**
185 * reference.
186 */
187 private String reference;
188
189 /**
190 * Status of the node.
191 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530192 private YangStatusType status = YangStatusType.CURRENT;
193
194 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530195 * List of must statement constraints.
196 */
197 private List<YangMust> mustConstraintList;
198
199 /**
200 * When data of the node.
201 */
202 private YangWhen when;
203
204 /**
205 * List of if-feature.
206 */
207 private List<YangIfFeature> ifFeatureList;
208
209 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530210 * Creates a YANG list object.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530211 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530212 public YangList() {
213 super(YangNodeType.LIST_NODE);
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530214 }
215
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530216 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530217 * Returns the when.
218 *
219 * @return the when
220 */
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530221 @Override
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530222 public YangWhen getWhen() {
223 return when;
224 }
225
226 /**
227 * Sets the when.
228 *
229 * @param when the when to set
230 */
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530231 @Override
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530232 public void setWhen(YangWhen when) {
233 this.when = when;
234 }
235
236 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530237 * Returns the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530238 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530239 * @return YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530240 */
241 @Override
242 public String getName() {
243 return name;
244 }
245
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530246 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530247 * Sets the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530248 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530249 * @param name YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530250 */
251 @Override
252 public void setName(String name) {
253 this.name = name;
254 }
255
256 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530257 * Returns the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530258 *
259 * @return the isConfig
260 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530261 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 return isConfig;
263 }
264
265 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530266 * Sets the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530267 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530268 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530269 */
270 public void setConfig(boolean isCfg) {
271 isConfig = isCfg;
272 }
273
274 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530275 * Returns the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530276 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530277 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530278 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530279 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530280 public String getDescription() {
281 return description;
282 }
283
284 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530285 * Sets the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530286 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530287 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530288 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530289 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530290 public void setDescription(String description) {
291 this.description = description;
292 }
293
294 /**
janani b23ccc312016-07-14 19:35:22 +0530295 * Returns the list of unique field names.
296 *
297 * @return the list of unique field names
298 */
299 public List<String> getUniqueList() {
300 return uniqueList;
301 }
302
303 /**
304 * Sets the list of unique field names.
305 *
306 * @param uniqueList the list of unique field names
307 */
308 private void setUniqueList(List<String> uniqueList) {
309 this.uniqueList = uniqueList;
310 }
311
312 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530313 * Returns the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530314 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530315 * @return the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530316 */
317 public List<String> getKeyList() {
318 return keyList;
319 }
320
321 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530322 * Sets the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530323 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530324 * @param keyList the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530325 */
326 private void setKeyList(List<String> keyList) {
327 this.keyList = keyList;
328 }
329
330 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530331 * Adds a key field name.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530332 *
333 * @param key key field name.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530334 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530335 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530336 public void addKey(String key)
337 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530338 if (getKeyList() == null) {
339 setKeyList(new LinkedList<String>());
340 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530341
342 if (getKeyList().contains(key)) {
343 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
344 " key");
345 }
346
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530347 getKeyList().add(key);
348 }
349
350 /**
janani b23ccc312016-07-14 19:35:22 +0530351 * Adds a unique field name.
352 *
353 * @param unique unique field name.
354 * @throws DataModelException a violation of data model rules
355 */
356 public void addUnique(String unique)
357 throws DataModelException {
358 if (getUniqueList() == null) {
359 setUniqueList(new LinkedList<>());
360 }
361 if (getUniqueList().contains(unique)) {
362 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
363 " unique");
364 }
365 getUniqueList().add(unique);
366 }
367
368 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530369 * Returns the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530370 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530371 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530372 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530373 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530374 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530375 return listOfLeaf;
376 }
377
378 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530379 * Sets the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530380 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530381 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530382 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530383 @Override
384 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530385 listOfLeaf = leafsList;
386 }
387
388 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530389 * Adds a leaf.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530390 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530391 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530392 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530393 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530394 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530395 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530396 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530397 }
398
399 getListOfLeaf().add(leaf);
400 }
401
402 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530403 * Returns the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530404 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530405 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530406 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530407 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530408 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530409 return listOfLeafList;
410 }
411
412 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530413 * Sets the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530414 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530415 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530416 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530417 @Override
418 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530419 this.listOfLeafList = listOfLeafList;
420 }
421
422 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530423 * Adds a leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530424 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530425 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530426 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530427 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530428 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530429 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530430 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530431 }
432
433 getListOfLeafList().add(leafList);
434 }
435
436 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530437 * Returns the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530438 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530439 * @return the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530440 */
rama-huawei6c728a92016-07-11 14:48:12 +0530441 public YangMaxElement getMaxElements() {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530442 return maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530443 }
444
445 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530446 * Sets the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530447 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530448 * @param max the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530449 */
rama-huawei6c728a92016-07-11 14:48:12 +0530450 public void setMaxElements(YangMaxElement max) {
451 this.maxElements = max;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530452 }
453
454 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530455 * Returns the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530456 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530457 * @return the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530458 */
rama-huawei6c728a92016-07-11 14:48:12 +0530459 public YangMinElement getMinElements() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530460 return minElements;
461 }
462
463 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530464 * Sets the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530465 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530466 * @param minElements the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530467 */
rama-huawei6c728a92016-07-11 14:48:12 +0530468 public void setMinElements(YangMinElement minElements) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530469 this.minElements = minElements;
470 }
471
472 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530473 * Returns the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530474 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530475 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530476 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530477 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530478 public String getReference() {
479 return reference;
480 }
481
482 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530483 * Sets the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530484 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530485 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530486 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530487 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530488 public void setReference(String reference) {
489 this.reference = reference;
490 }
491
492 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530493 * Returns the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530494 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530495 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530496 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530497 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530498 public YangStatusType getStatus() {
499 return status;
500 }
501
502 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530503 * Sets the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530504 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530505 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530506 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530507 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530508 public void setStatus(YangStatusType status) {
509 this.status = status;
510 }
511
512 /**
513 * Returns the type of the parsed data.
514 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530515 * @return returns LIST_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530516 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530517 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530518 public YangConstructType getYangConstructType() {
519 return YangConstructType.LIST_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530520 }
521
522 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530523 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530524 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530525 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530526 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530527 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530528 public void validateDataOnEntry()
529 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530530 // TODO auto-generated method stub, to be implemented by parser
531 }
532
533 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530534 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530535 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530536 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530537 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530538 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530539 public void validateDataOnExit()
540 throws DataModelException {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530541 List<String> keys = getKeyList();
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530542 List<YangLeaf> leaves = getListOfLeaf();
543 List<YangLeafList> leafLists = getListOfLeafList();
544
545 setDefaultConfigValueToChild(leaves, leafLists);
546 validateConfig(leaves, leafLists);
547
548 /* A list must have atleast one key leaf if config is true */
janani b23ccc312016-07-14 19:35:22 +0530549 if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList()
janani bdd1314f2016-05-19 17:39:50 +0530550 && !isListPresentInGrouping()) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530551 throw new DataModelException("A list must have atleast one key leaf if config is true;");
552 } else if (keys != null) {
janani b23ccc312016-07-14 19:35:22 +0530553 validateKey(leaves, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530554 }
555 }
556
557 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530558 * Sets the config's value to all leaf if leaf's config statement is not
559 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530560 *
janani b23ccc312016-07-14 19:35:22 +0530561 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530562 * @param leafLists list of leaf-list attributes of YANG list
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530563 */
564 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
565
Vinod Kumar S71cba682016-02-25 15:52:16 +0530566 /*
567 * If "config" is not specified, the default is the same as the parent
568 * schema node's "config" value.
569 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530570 if (leaves != null) {
571 for (YangLeaf leaf : leaves) {
572 if (leaf.isConfig() == null) {
573 leaf.setConfig(isConfig);
574 }
575 }
576 }
577
Vinod Kumar S71cba682016-02-25 15:52:16 +0530578 /*
579 * If "config" is not specified, the default is the same as the parent
580 * schema node's "config" value.
581 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530582 if (leafLists != null) {
583 for (YangLeafList leafList : leafLists) {
584 if (leafList.isConfig() == null) {
585 leafList.setConfig(isConfig);
586 }
587 }
588 }
589 }
590
591 /**
592 * Validates config statement of YANG list.
593 *
janani b23ccc312016-07-14 19:35:22 +0530594 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530595 * @param leafLists list of leaf-list attributes of YANG list
596 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530597 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530598 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
599 throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530600
Vinod Kumar S71cba682016-02-25 15:52:16 +0530601 /*
602 * If a node has "config" set to "false", no node underneath it can have
603 * "config" set to "true".
604 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530605 if (!isConfig && leaves != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530606 for (YangLeaf leaf : leaves) {
607 if (leaf.isConfig()) {
608 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
609 "it can have \"config\" set to \"true\".");
610 }
611 }
612 }
613
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530614 if (!isConfig && leafLists != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530615 for (YangLeafList leafList : leafLists) {
616 if (leafList.isConfig()) {
617 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
618 "it can have \"config\" set to \"true\".");
619 }
620 }
621 }
622 }
623
624 /**
625 * Validates key statement of list.
626 *
janani b23ccc312016-07-14 19:35:22 +0530627 * @param leaves list of leaf 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}