blob: e2bd8b5f6205f3edd43beb1bf42a505878c1e5b3 [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;
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053022
Vinod Kumar S38046502016-03-23 15:30:27 +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 Agrawal72cd1b72016-06-30 13:28:14 +053026import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Vinod Kumar S38046502016-03-23 15:30:27 +053027
28import 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,
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053075 YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode,
76 YangIsFilterContentNodes {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053077
Bharat saraswal96dfef02016-06-16 00:29:12 +053078 private static final long serialVersionUID = 806201609L;
79
Vinod Kumar S67e7be62016-02-11 20:13:28 +053080 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053081 * Name of the YANG list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053082 */
83 private String name;
84
85 /**
86 * If list maintains config data.
87 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053088 private Boolean isConfig;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053089
90 /**
91 * Description of list.
92 */
93 private String description;
94
95 /**
96 * Reference RFC 6020.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053097 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +053098 * The "key" statement, which MUST be present if the list represents
99 * configuration, and MAY be present otherwise, takes as an argument a
100 * string that specifies a space-separated list of leaf identifiers of this
101 * list. A leaf identifier MUST NOT appear more than once in the key. Each
102 * such leaf identifier MUST refer to a child leaf of the list. The leafs
103 * can be defined directly in sub-statements to the list, or in groupings
104 * used in the list.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530105 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530106 * The combined values of all the leafs specified in the key are used to
107 * uniquely identify a list entry. All key leafs MUST be given values when a
108 * list entry is created. Thus, any default values in the key leafs or their
109 * types are ignored. It also implies that any mandatory statement in the
110 * key leafs are ignored.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530111 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530112 * A leaf that is part of the key can be of any built-in or derived type,
113 * except it MUST NOT be the built-in type "empty".
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530114 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530115 * All key leafs in a list MUST have the same value for their "config" as
116 * the list itself.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530117 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530118 * List of key leaf names.
119 */
120 private List<String> keyList;
121
122 /**
janani b23ccc312016-07-14 19:35:22 +0530123 * Reference RFC 6020.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530124 * <p>
janani b23ccc312016-07-14 19:35:22 +0530125 * The "unique" statement is used to put constraints on valid list
126 * entries. It takes as an argument a string that contains a space-
127 * separated list of schema node identifiers, which MUST be given in the
128 * descendant form. Each such schema node identifier MUST refer to a leaf.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530129 * <p>
janani b23ccc312016-07-14 19:35:22 +0530130 * If one of the referenced leafs represents configuration data, then
131 * all of the referenced leafs MUST represent configuration data.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530132 * <p>
janani b23ccc312016-07-14 19:35:22 +0530133 * The "unique" constraint specifies that the combined values of all the
134 * leaf instances specified in the argument string, including leafs with
135 * default values, MUST be unique within all list entry instances in
136 * which all referenced leafs exist.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530137 * <p>
janani b23ccc312016-07-14 19:35:22 +0530138 * List of unique leaf/leaf-list names
139 */
140 private List<String> uniqueList;
141
142 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530143 * List of leaves.
144 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530145 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530146
147 /**
148 * List of leaf-lists.
149 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530150 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530151
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530152 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
153
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530154 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530155 * Reference RFC 6020.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530156 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530157 * The "max-elements" statement, which is optional, takes as an argument a
158 * positive integer or the string "unbounded", which puts a constraint on
159 * valid list entries. A valid leaf-list or list always has at most
160 * max-elements entries.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530161 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530162 * If no "max-elements" statement is present, it defaults to "unbounded".
163 */
rama-huawei6c728a92016-07-11 14:48:12 +0530164 private YangMaxElement maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530165
166 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530167 * Reference RFC 6020.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530168 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530169 * The "min-elements" statement, which is optional, takes as an argument a
170 * non-negative integer that puts a constraint on valid list entries. A
171 * valid leaf-list or list MUST have at least min-elements entries.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530172 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530173 * If no "min-elements" statement is present, it defaults to zero.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530174 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530175 * The behavior of the constraint depends on the type of the leaf-list's or
176 * list's closest ancestor node in the schema tree that is not a non-
177 * presence container:
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530178 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530179 * o If this ancestor is a case node, the constraint is enforced if any
180 * other node from the case exists.
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530181 * <p>
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530182 * o Otherwise, it is enforced if the ancestor node exists.
183 */
rama-huawei6c728a92016-07-11 14:48:12 +0530184 private YangMinElement minElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530185
186 /**
187 * reference.
188 */
189 private String reference;
190
191 /**
192 * Status of the node.
193 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530194 private YangStatusType status = YangStatusType.CURRENT;
195
196 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530197 * List of must statement constraints.
198 */
199 private List<YangMust> mustConstraintList;
200
201 /**
202 * When data of the node.
203 */
204 private YangWhen when;
205
206 /**
207 * List of if-feature.
208 */
209 private List<YangIfFeature> ifFeatureList;
210
211 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530212 * Creates a YANG list object.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530213 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530214 public YangList() {
215 super(YangNodeType.LIST_NODE);
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530216 listOfLeaf = new LinkedList<>();
217 listOfLeafList = new LinkedList<>();
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530218 }
219
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530220 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530221 * Returns the when.
222 *
223 * @return the when
224 */
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530225 @Override
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530226 public YangWhen getWhen() {
227 return when;
228 }
229
230 /**
231 * Sets the when.
232 *
233 * @param when the when to set
234 */
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530235 @Override
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530236 public void setWhen(YangWhen when) {
237 this.when = when;
238 }
239
240 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530241 * Returns the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530242 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530243 * @return YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530244 */
245 @Override
246 public String getName() {
247 return name;
248 }
249
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530250 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530251 * Sets the YANG list name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530252 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530253 * @param name YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530254 */
255 @Override
256 public void setName(String name) {
257 this.name = name;
258 }
259
260 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530261 * Returns the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 *
263 * @return the isConfig
264 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530265 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530266 return isConfig;
267 }
268
269 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530270 * Sets the config flag.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530271 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530272 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530273 */
274 public void setConfig(boolean isCfg) {
275 isConfig = isCfg;
276 }
277
278 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530279 * Returns the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530280 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530281 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530282 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530283 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530284 public String getDescription() {
285 return description;
286 }
287
288 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530289 * Sets the description.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530290 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530291 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530292 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530293 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530294 public void setDescription(String description) {
295 this.description = description;
296 }
297
298 /**
janani b23ccc312016-07-14 19:35:22 +0530299 * Returns the list of unique field names.
300 *
301 * @return the list of unique field names
302 */
303 public List<String> getUniqueList() {
304 return uniqueList;
305 }
306
307 /**
308 * Sets the list of unique field names.
309 *
310 * @param uniqueList the list of unique field names
311 */
312 private void setUniqueList(List<String> uniqueList) {
313 this.uniqueList = uniqueList;
314 }
315
316 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530317 * Returns the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530318 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530319 * @return the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530320 */
321 public List<String> getKeyList() {
322 return keyList;
323 }
324
325 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530326 * Sets the list of key field names.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530327 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530328 * @param keyList the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530329 */
330 private void setKeyList(List<String> keyList) {
331 this.keyList = keyList;
332 }
333
334 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530335 * Adds a key field name.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530336 *
337 * @param key key field name.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530338 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530339 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530340 public void addKey(String key)
341 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530342 if (getKeyList() == null) {
343 setKeyList(new LinkedList<String>());
344 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530345
346 if (getKeyList().contains(key)) {
347 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
348 " key");
349 }
350
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530351 getKeyList().add(key);
352 }
353
354 /**
janani b23ccc312016-07-14 19:35:22 +0530355 * Adds a unique field name.
356 *
357 * @param unique unique field name.
358 * @throws DataModelException a violation of data model rules
359 */
360 public void addUnique(String unique)
361 throws DataModelException {
362 if (getUniqueList() == null) {
363 setUniqueList(new LinkedList<>());
364 }
365 if (getUniqueList().contains(unique)) {
366 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
367 " unique");
368 }
369 getUniqueList().add(unique);
370 }
371
372 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530373 * Returns the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530374 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530375 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530376 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530377 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530378 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530379 return listOfLeaf;
380 }
381
382 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530383 * Sets the list of leaves.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530384 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530385 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530386 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530387 @Override
388 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530389 listOfLeaf = leafsList;
390 }
391
392 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530393 * Adds a leaf.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530394 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530395 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530396 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530397 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530398 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530399 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530400 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530401 }
402
403 getListOfLeaf().add(leaf);
404 }
405
406 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530407 * Returns the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530408 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530409 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530410 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530411 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530412 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 return listOfLeafList;
414 }
415
416 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530417 * Sets the list of leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530418 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530419 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530420 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530421 @Override
422 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530423 this.listOfLeafList = listOfLeafList;
424 }
425
426 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530427 * Adds a leaf-list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530428 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530429 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530430 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530431 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530432 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530433 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530434 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530435 }
436
437 getListOfLeafList().add(leafList);
438 }
439
440 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530441 * Returns the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530442 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530443 * @return the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530444 */
rama-huawei6c728a92016-07-11 14:48:12 +0530445 public YangMaxElement getMaxElements() {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530446 return maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530447 }
448
449 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530450 * Sets the max elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530451 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530452 * @param max the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530453 */
rama-huawei6c728a92016-07-11 14:48:12 +0530454 public void setMaxElements(YangMaxElement max) {
455 this.maxElements = max;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530456 }
457
458 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530459 * Returns the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530460 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530461 * @return the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530462 */
rama-huawei6c728a92016-07-11 14:48:12 +0530463 public YangMinElement getMinElements() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530464 return minElements;
465 }
466
467 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530468 * Sets the minimum elements.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530469 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530470 * @param minElements the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530471 */
rama-huawei6c728a92016-07-11 14:48:12 +0530472 public void setMinElements(YangMinElement minElements) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530473 this.minElements = minElements;
474 }
475
476 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530477 * Returns the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530478 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530479 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530480 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530481 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530482 public String getReference() {
483 return reference;
484 }
485
486 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530487 * Sets the textual reference.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530488 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530489 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530490 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530491 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530492 public void setReference(String reference) {
493 this.reference = reference;
494 }
495
496 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530497 * Returns the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530498 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530499 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530500 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530501 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530502 public YangStatusType getStatus() {
503 return status;
504 }
505
506 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530507 * Sets the status.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530508 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530509 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530510 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530511 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530512 public void setStatus(YangStatusType status) {
513 this.status = status;
514 }
515
516 /**
517 * Returns the type of the parsed data.
518 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530519 * @return returns LIST_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530520 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530521 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530522 public YangConstructType getYangConstructType() {
523 return YangConstructType.LIST_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530524 }
525
526 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530527 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530528 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530529 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530530 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530531 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530532 public void validateDataOnEntry()
533 throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530534 // TODO auto-generated method stub, to be implemented by parser
535 }
536
537 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530538 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530539 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530540 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530541 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530542 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530543 public void validateDataOnExit()
544 throws DataModelException {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530545 List<String> keys = getKeyList();
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530546 List<YangLeaf> leaves = getListOfLeaf();
547 List<YangLeafList> leafLists = getListOfLeafList();
548
549 setDefaultConfigValueToChild(leaves, leafLists);
550 validateConfig(leaves, leafLists);
551
552 /* A list must have atleast one key leaf if config is true */
janani b23ccc312016-07-14 19:35:22 +0530553 if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList()
janani bdd1314f2016-05-19 17:39:50 +0530554 && !isListPresentInGrouping()) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530555 throw new DataModelException("A list must have atleast one key leaf if config is true;");
556 } else if (keys != null) {
janani b23ccc312016-07-14 19:35:22 +0530557 validateKey(leaves, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530558 }
559 }
560
561 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530562 * Sets the config's value to all leaf if leaf's config statement is not
563 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530564 *
janani b23ccc312016-07-14 19:35:22 +0530565 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530566 * @param leafLists list of leaf-list attributes of YANG list
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530567 */
568 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
569
Vinod Kumar S71cba682016-02-25 15:52:16 +0530570 /*
571 * If "config" is not specified, the default is the same as the parent
572 * schema node's "config" value.
573 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530574 if (leaves != null) {
575 for (YangLeaf leaf : leaves) {
576 if (leaf.isConfig() == null) {
577 leaf.setConfig(isConfig);
578 }
579 }
580 }
581
Vinod Kumar S71cba682016-02-25 15:52:16 +0530582 /*
583 * If "config" is not specified, the default is the same as the parent
584 * schema node's "config" value.
585 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530586 if (leafLists != null) {
587 for (YangLeafList leafList : leafLists) {
588 if (leafList.isConfig() == null) {
589 leafList.setConfig(isConfig);
590 }
591 }
592 }
593 }
594
595 /**
596 * Validates config statement of YANG list.
597 *
janani b23ccc312016-07-14 19:35:22 +0530598 * @param leaves list of leaf attributes of YANG list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530599 * @param leafLists list of leaf-list attributes of YANG list
600 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530601 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530602 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
603 throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530604
Vinod Kumar S71cba682016-02-25 15:52:16 +0530605 /*
606 * If a node has "config" set to "false", no node underneath it can have
607 * "config" set to "true".
608 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530609 if (!isConfig && leaves != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530610 for (YangLeaf leaf : leaves) {
611 if (leaf.isConfig()) {
612 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
613 "it can have \"config\" set to \"true\".");
614 }
615 }
616 }
617
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530618 if (!isConfig && leafLists != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530619 for (YangLeafList leafList : leafLists) {
620 if (leafList.isConfig()) {
621 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
622 "it can have \"config\" set to \"true\".");
623 }
624 }
625 }
626 }
627
628 /**
629 * Validates key statement of list.
630 *
Bharat saraswal2d90b0c2016-08-04 02:00:03 +0530631 * @param leaves list of leaf attributes of list
632 * @param keys list of key attributes of list
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530633 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530634 */
janani b23ccc312016-07-14 19:35:22 +0530635 private void validateKey(List<YangLeaf> leaves, List<String> keys)
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530636 throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530637 boolean leafFound = false;
638 List<YangLeaf> keyLeaves = new LinkedList<>();
639
Vinod Kumar S71cba682016-02-25 15:52:16 +0530640 /*
641 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
642 * that is part of the key must not be the built-in type "empty".
643 */
644 for (String key : keys) {
Vidyashree Rama1db15562016-05-17 16:16:15 +0530645 if (leaves != null && !leaves.isEmpty()) {
646 for (YangLeaf leaf : leaves) {
647 if (key.equals(leaf.getName())) {
648 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
649 throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
650 "type \"empty\".");
651 }
652 leafFound = true;
653 keyLeaves.add(leaf);
654 break;
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530655 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530656 }
657 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530658
janani bdd1314f2016-05-19 17:39:50 +0530659 if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) {
Vidyashree Rama1db15562016-05-17 16:16:15 +0530660 throw new DataModelException("An identifier, in key, must refer to a child leaf of the list");
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530661 }
662 leafFound = false;
663 }
664
Vinod Kumar S71cba682016-02-25 15:52:16 +0530665 /*
666 * All key leafs in a list MUST have the same value for their "config"
667 * as the list itself.
668 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530669 for (YangLeaf keyLeaf : keyLeaves) {
670 if (isConfig != keyLeaf.isConfig()) {
671 throw new DataModelException("All key leafs in a list must have the same value for their" +
672 " \"config\" as the list itself.");
673 }
674 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530675 }
676
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530677 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530678 public void detectCollidingChild(String identifierName, YangConstructType dataType)
679 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530680 // Asks helper to detect colliding child.
681 detectCollidingChildUtil(identifierName, dataType, this);
682 }
683
684 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530685 public void detectSelfCollision(String identifierName, YangConstructType dataType)
686 throws DataModelException {
Vinod Kumar S38046502016-03-23 15:30:27 +0530687 if (getName().equals(identifierName)) {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530688 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
Vinod Kumar S38046502016-03-23 15:30:27 +0530689 getName() + "\"");
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530690 }
691 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530692
693 private boolean isUsesPresentInList() {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530694 YangNode node = getChild();
Vidyashree Rama1db15562016-05-17 16:16:15 +0530695 while (node != null) {
696 if (node instanceof YangUses) {
697 return true;
698 }
699 node = node.getNextSibling();
700 }
701 return false;
janani bdd1314f2016-05-19 17:39:50 +0530702 // TODO When grouping linking is done this method has to be modified.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530703 }
704
janani bdd1314f2016-05-19 17:39:50 +0530705 private boolean isListPresentInGrouping() {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530706 YangNode node = getParent();
janani bdd1314f2016-05-19 17:39:50 +0530707 while (node != null) {
708 if (node instanceof YangGrouping) {
709 return true;
710 }
711 node = node.getParent();
712 }
713 return false;
714 // TODO When grouping linking is done this method has to be modified.
715 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530716
717 @Override
718 public List<YangIfFeature> getIfFeatureList() {
719 return ifFeatureList;
720 }
721
722 @Override
723 public void addIfFeatureList(YangIfFeature ifFeature) {
724 if (getIfFeatureList() == null) {
725 setIfFeatureList(new LinkedList<>());
726 }
727 getIfFeatureList().add(ifFeature);
728 }
729
730 @Override
731 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
732 this.ifFeatureList = ifFeatureList;
733 }
734
735 @Override
736 public List<YangMust> getListOfMust() {
737 return mustConstraintList;
738 }
739
740 @Override
741 public void setListOfMust(List<YangMust> mustConstraintList) {
742 this.mustConstraintList = mustConstraintList;
743 }
744
745 @Override
746 public void addMust(YangMust must) {
747 if (getListOfMust() == null) {
748 setListOfMust(new LinkedList<>());
749 }
750 getListOfMust().add(must);
751 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530752
753 @Override
754 public void addAugmentation(YangAugmentedInfo augmentInfo) {
755 yangAugmentedInfo.add(augmentInfo);
756 }
757
758 @Override
759 public void removeAugmentation(YangAugmentedInfo augmentInfo) {
760 yangAugmentedInfo.remove(augmentInfo);
761 }
762
763 @Override
764 public List<YangAugmentedInfo> getAugmentedInfoList() {
765 return yangAugmentedInfo;
766 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530767}