blob: c0b569be0e295da2ba0c11bee13a6411d06d41f8 [file] [log] [blame]
Vinod Kumar S67e7be62016-02-11 20:13:28 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053019import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
21import org.onosproject.yangutils.parser.Parsable;
22import org.onosproject.yangutils.translator.CachedFileHandle;
23import org.onosproject.yangutils.utils.YangConstructType;
24
Vinod Kumar S67e7be62016-02-11 20:13:28 +053025import java.util.LinkedList;
26import java.util.List;
27
Vinod Kumar S67e7be62016-02-11 20:13:28 +053028/*-
29 * The "list" statement is used to define an interior data node in the
30 * schema tree. A list node may exist in multiple instances in the data
31 * tree. Each such instance is known as a list entry. The "list"
32 * statement takes one argument, which is an identifier, followed by a
33 * block of sub-statements that holds detailed list information.
34 *
35 * A list entry is uniquely identified by the values of the list's keys,
36 * if defined.
37 *
38 * The list's sub-statements
39 *
40 * +--------------+---------+-------------+------------------+
41 * | substatement | section | cardinality |data model mapping|
42 * +--------------+---------+-------------+------------------+
43 * | anyxml | 7.10 | 0..n |-not supported |
44 * | choice | 7.9 | 0..n |-child nodes |
45 * | config | 7.19.1 | 0..1 |-boolean |
46 * | container | 7.5 | 0..n |-child nodes |
47 * | description | 7.19.3 | 0..1 |-string |
48 * | grouping | 7.11 | 0..n |-child nodes |
49 * | if-feature | 7.18.2 | 0..n |-TODO |
50 * | key | 7.8.2 | 0..1 |-String list |
51 * | leaf | 7.6 | 0..n |-YangLeaf |
52 * | leaf-list | 7.7 | 0..n |-YangLeafList |
53 * | list | 7.8 | 0..n |-child nodes |
54 * | max-elements | 7.7.4 | 0..1 |-int |
55 * | min-elements | 7.7.3 | 0..1 |-int |
56 * | must | 7.5.3 | 0..n |-TODO |
57 * | ordered-by | 7.7.5 | 0..1 |-TODO |
58 * | reference | 7.19.4 | 0..1 |-string |
59 * | status | 7.19.2 | 0..1 |-YangStatus |
60 * | typedef | 7.3 | 0..n |-child nodes |
61 * | unique | 7.8.3 | 0..n |-TODO |
62 * | uses | 7.12 | 0..n |-child nodes(TODO)|
63 * | when | 7.19.5 | 0..1 |-TODO |
64 * +--------------+---------+-------------+------------------+
65 */
66
67/**
68 * List data represented in YANG.
69 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053070public class YangList extends YangNode
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053071 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053072
73 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053074 * Name of the YANG list.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053075 */
76 private String name;
77
78 /**
79 * If list maintains config data.
80 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053081 private Boolean isConfig;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053082
83 /**
84 * Description of list.
85 */
86 private String description;
87
88 /**
89 * Reference RFC 6020.
90 *
91 * The "key" statement, which MUST be present if the list represents
92 * configuration, and MAY be present otherwise, takes as an argument a
93 * string that specifies a space-separated list of leaf identifiers of this
94 * list. A leaf identifier MUST NOT appear more than once in the key. Each
95 * such leaf identifier MUST refer to a child leaf of the list. The leafs
96 * can be defined directly in sub-statements to the list, or in groupings
97 * used in the list.
98 *
99 * The combined values of all the leafs specified in the key are used to
100 * uniquely identify a list entry. All key leafs MUST be given values when a
101 * list entry is created. Thus, any default values in the key leafs or their
102 * types are ignored. It also implies that any mandatory statement in the
103 * key leafs are ignored.
104 *
105 * A leaf that is part of the key can be of any built-in or derived type,
106 * except it MUST NOT be the built-in type "empty".
107 *
108 * All key leafs in a list MUST have the same value for their "config" as
109 * the list itself.
110 *
111 * List of key leaf names.
112 */
113 private List<String> keyList;
114
115 /**
116 * List of leaves.
117 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530119
120 /**
121 * List of leaf-lists.
122 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530124
125 /**
126 * The "max-elements" statement, which is optional, takes as an argument a
127 * positive integer or the string "unbounded", which puts a constraint on
128 * valid list entries. A valid leaf-list or list always has at most
129 * max-elements entries.
130 *
131 * If no "max-elements" statement is present, it defaults to "unbounded".
132 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530133 private int maxElelements = Integer.MAX_VALUE;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530134
135 /**
136 * The "min-elements" statement, which is optional, takes as an argument a
137 * non-negative integer that puts a constraint on valid list entries. A
138 * valid leaf-list or list MUST have at least min-elements entries.
139 *
140 * If no "min-elements" statement is present, it defaults to zero.
141 *
142 * The behavior of the constraint depends on the type of the leaf-list's or
143 * list's closest ancestor node in the schema tree that is not a non-
144 * presence container:
145 *
146 * o If this ancestor is a case node, the constraint is enforced if any
147 * other node from the case exists.
148 *
149 * o Otherwise, it is enforced if the ancestor node exists.
150 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530151 private int minElements = 0;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530152
153 /**
154 * reference.
155 */
156 private String reference;
157
158 /**
159 * Status of the node.
160 */
161
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530162 private YangStatusType status = YangStatusType.CURRENT;
163
164 /**
165 * package of the generated java code.
166 */
167 private String pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530168
169 /**
170 * Constructor.
171 *
172 * @param type list node
173 */
174 public YangList(YangNodeType type) {
175 super(type);
176 }
177
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530178 /**
179 * Get the YANG list name.
180 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530181 * @return YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530182 */
183 @Override
184 public String getName() {
185 return name;
186 }
187
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530188 /**
189 * Set the YANG list name.
190 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530191 * @param name YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530192 */
193 @Override
194 public void setName(String name) {
195 this.name = name;
196 }
197
198 /**
199 * Get the config flag.
200 *
201 * @return the isConfig
202 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530203 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530204 return isConfig;
205 }
206
207 /**
208 * Set the config flag.
209 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530210 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530211 */
212 public void setConfig(boolean isCfg) {
213 isConfig = isCfg;
214 }
215
216 /**
217 * Get the description.
218 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530219 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530220 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530221 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530222 public String getDescription() {
223 return description;
224 }
225
226 /**
227 * Set the description.
228 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530229 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530230 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530231 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530232 public void setDescription(String description) {
233 this.description = description;
234 }
235
236 /**
237 * Get the list of key field names.
238 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530239 * @return the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530240 */
241 public List<String> getKeyList() {
242 return keyList;
243 }
244
245 /**
246 * Set the list of key field names.
247 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530248 * @param keyList the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530249 */
250 private void setKeyList(List<String> keyList) {
251 this.keyList = keyList;
252 }
253
254 /**
255 * Add a key field name.
256 *
257 * @param key key field name.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530258 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530259 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530260 public void addKey(String key) throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530261 if (getKeyList() == null) {
262 setKeyList(new LinkedList<String>());
263 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530264
265 if (getKeyList().contains(key)) {
266 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
267 " key");
268 }
269
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530270 getKeyList().add(key);
271 }
272
273 /**
274 * Get the list of leaves.
275 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530277 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530278 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530279 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530280 return listOfLeaf;
281 }
282
283 /**
284 * Set the list of leaves.
285 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530286 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530287 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530288 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530289 listOfLeaf = leafsList;
290 }
291
292 /**
293 * Add a leaf.
294 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530295 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530296 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530297 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530298 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530299 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530300 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530301 }
302
303 getListOfLeaf().add(leaf);
304 }
305
306 /**
307 * Get the list of leaf-list.
308 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530309 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530310 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530311 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530312 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530313 return listOfLeafList;
314 }
315
316 /**
317 * Set the list of leaf-list.
318 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530319 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530320 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530321 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530322 this.listOfLeafList = listOfLeafList;
323 }
324
325 /**
326 * Add a leaf-list.
327 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530328 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530329 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530330 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530331 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530332 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530333 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530334 }
335
336 getListOfLeafList().add(leafList);
337 }
338
339 /**
340 * Get the max elements.
341 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530342 * @return the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530343 */
344 public int getMaxElelements() {
345 return maxElelements;
346 }
347
348 /**
349 * Set the max elements.
350 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530351 * @param maxElelements the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530352 */
353 public void setMaxElelements(int maxElelements) {
354 this.maxElelements = maxElelements;
355 }
356
357 /**
358 * Get the minimum elements.
359 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530360 * @return the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530361 */
362 public int getMinElements() {
363 return minElements;
364 }
365
366 /**
367 * Set the minimum elements.
368 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530369 * @param minElements the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530370 */
371 public void setMinElements(int minElements) {
372 this.minElements = minElements;
373 }
374
375 /**
376 * Get the textual reference.
377 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530378 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530379 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530380 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530381 public String getReference() {
382 return reference;
383 }
384
385 /**
386 * Set the textual reference.
387 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530388 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530389 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530390 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530391 public void setReference(String reference) {
392 this.reference = reference;
393 }
394
395 /**
396 * Get the status.
397 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530398 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530399 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530400 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530401 public YangStatusType getStatus() {
402 return status;
403 }
404
405 /**
406 * Set the status.
407 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530408 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530409 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530410 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530411 public void setStatus(YangStatusType status) {
412 this.status = status;
413 }
414
415 /**
416 * Returns the type of the parsed data.
417 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530418 * @return returns LIST_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530419 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530420 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530421 public YangConstructType getYangConstructType() {
422 return YangConstructType.LIST_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530423 }
424
425 /**
426 * Validate the data on entering the corresponding parse tree node.
427 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530428 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530429 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530430 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530431 public void validateDataOnEntry() throws DataModelException {
432 // TODO auto-generated method stub, to be implemented by parser
433 }
434
435 /**
436 * Validate the data on exiting the corresponding parse tree node.
437 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530438 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530439 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530440 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530441 public void validateDataOnExit() throws DataModelException {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530442 List<String> keys = getKeyList();
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530443 List<YangLeaf> leaves = getListOfLeaf();
444 List<YangLeafList> leafLists = getListOfLeafList();
445
446 setDefaultConfigValueToChild(leaves, leafLists);
447 validateConfig(leaves, leafLists);
448
449 /* A list must have atleast one key leaf if config is true */
450 if ((isConfig)
Vinod Kumar S71cba682016-02-25 15:52:16 +0530451 && ((keys == null) || ((leaves == null) && (leafLists == null)))) {
452 throw new DataModelException("A list must have atleast one key leaf if config is true;");
453 } else if (keys != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530454 if (leaves != null) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530455 validateLeafKey(leaves, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530456 }
457
458 if (leafLists != null) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530459 validateLeafListKey(leafLists, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530460 }
461 }
462 }
463
464 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530465 * Sets the config's value to all leaf if leaf's config statement is not
466 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530467 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530468 * @param leaves list of leaf attributes of YANG list
469 * @param leafLists list of leaf-list attributes of YANG list
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530470 */
471 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
472
Vinod Kumar S71cba682016-02-25 15:52:16 +0530473 /*
474 * If "config" is not specified, the default is the same as the parent
475 * schema node's "config" value.
476 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530477 if (leaves != null) {
478 for (YangLeaf leaf : leaves) {
479 if (leaf.isConfig() == null) {
480 leaf.setConfig(isConfig);
481 }
482 }
483 }
484
Vinod Kumar S71cba682016-02-25 15:52:16 +0530485 /*
486 * If "config" is not specified, the default is the same as the parent
487 * schema node's "config" value.
488 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530489 if (leafLists != null) {
490 for (YangLeafList leafList : leafLists) {
491 if (leafList.isConfig() == null) {
492 leafList.setConfig(isConfig);
493 }
494 }
495 }
496 }
497
498 /**
499 * Validates config statement of YANG list.
500 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530501 * @param leaves list of leaf attributes of YANG list
502 * @param leafLists list of leaf-list attributes of YANG list
503 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530504 */
505 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
506
Vinod Kumar S71cba682016-02-25 15:52:16 +0530507 /*
508 * If a node has "config" set to "false", no node underneath it can have
509 * "config" set to "true".
510 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530511 if ((!isConfig) && (leaves != null)) {
512 for (YangLeaf leaf : leaves) {
513 if (leaf.isConfig()) {
514 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
515 "it can have \"config\" set to \"true\".");
516 }
517 }
518 }
519
520 if ((!isConfig) && (leafLists != null)) {
521 for (YangLeafList leafList : leafLists) {
522 if (leafList.isConfig()) {
523 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
524 "it can have \"config\" set to \"true\".");
525 }
526 }
527 }
528 }
529
530 /**
531 * Validates key statement of list.
532 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530533 * @param leaves list of leaf attributes of list
534 * @param keys list of key attributes of list
535 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530536 */
Vinod Kumar S71cba682016-02-25 15:52:16 +0530537 private void validateLeafKey(List<YangLeaf> leaves, List<String> keys) throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530538 boolean leafFound = false;
539 List<YangLeaf> keyLeaves = new LinkedList<>();
540
Vinod Kumar S71cba682016-02-25 15:52:16 +0530541 /*
542 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
543 * that is part of the key must not be the built-in type "empty".
544 */
545 for (String key : keys) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530546 for (YangLeaf leaf : leaves) {
547 if (key.equals(leaf.getLeafName())) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530548 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530549 throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
550 "type \"empty\".");
551 }
552 leafFound = true;
553 keyLeaves.add(leaf);
554 break;
555 }
556 }
557 if (!leafFound) {
558 throw new DataModelException("Leaf identifier must refer to a child leaf of the list");
559 }
560 leafFound = false;
561 }
562
Vinod Kumar S71cba682016-02-25 15:52:16 +0530563 /*
564 * All key leafs in a list MUST have the same value for their "config"
565 * as the list itself.
566 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530567 for (YangLeaf keyLeaf : keyLeaves) {
568 if (isConfig != keyLeaf.isConfig()) {
569 throw new DataModelException("All key leafs in a list must have the same value for their" +
570 " \"config\" as the list itself.");
571 }
572 }
573 }
574
575 /**
576 * Validates key statement of list.
577 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530578 * @param leafLists list of leaf-list attributes of list
579 * @param keys list of key attributes of list
580 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530581 */
Vinod Kumar S71cba682016-02-25 15:52:16 +0530582 private void validateLeafListKey(List<YangLeafList> leafLists, List<String> keys) throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530583 boolean leafFound = false;
584 List<YangLeafList> keyLeafLists = new LinkedList<>();
585
Vinod Kumar S71cba682016-02-25 15:52:16 +0530586 /*
587 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
588 * that is part of the key must not be the built-in type "empty".
589 */
590 for (String key : keys) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530591 for (YangLeafList leafList : leafLists) {
592 if (key.equals(leafList.getLeafName())) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530593 if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530594 throw new DataModelException(" A leaf-list that is part of the key must not be the built-in " +
595 "type \"empty\".");
596 }
597 leafFound = true;
598 keyLeafLists.add(leafList);
599 break;
600 }
601 }
602 if (!leafFound) {
603 throw new DataModelException("Leaf-list identifier must refer to a child leaf of the list");
604 }
605 leafFound = false;
606 }
607
Vinod Kumar S71cba682016-02-25 15:52:16 +0530608 /*
609 * All key leafs in a list MUST have the same value for their "config"
610 * as the list itself.
611 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530612 for (YangLeafList keyLeafList : keyLeafLists) {
613 if (isConfig() != keyLeafList.isConfig()) {
614 throw new DataModelException("All key leaf-lists in a list must have the same value for their" +
615 " \"config\" as the list itself.");
616 }
617 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530618 }
619
Vinod Kumar S71cba682016-02-25 15:52:16 +0530620 /**
621 * Populate the cached handle with information about the list attributes to
622 * generate java code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530623 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530624 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530625 public void generateJavaCodeEntry() {
626 // TODO Auto-generated method stub
627
628 }
629
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530630 /**
631 * Free the resources used to generate the java file corresponding to YANG
632 * list info.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530633 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530634 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530635 public void generateJavaCodeExit() {
636 // TODO Auto-generated method stub
637
638 }
639
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530640 /**
641 * Get the mapped java package.
642 *
643 * @return the java package
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530644 */
645 @Override
646 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530647 return pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530648 }
649
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530650 /**
651 * Set the mapped java package.
652 *
653 * @param pakg the package to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530654 */
655 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530656 public void setPackage(String pakg) {
657 pkg = pakg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530658
659 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530660
661 @Override
662 public CachedFileHandle getFileHandle() {
663 // TODO Auto-generated method stub
664 return null;
665 }
666
667 @Override
668 public void setFileHandle(CachedFileHandle fileHandle) {
669 // TODO Auto-generated method stub
670
671 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530672
673 @Override
674 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
675 // Asks helper to detect colliding child.
676 detectCollidingChildUtil(identifierName, dataType, this);
677 }
678
679 @Override
680 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
681 if (this.getName().equals(identifierName)) {
682 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
683 this.getName() + "\"");
684 }
685 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530686}