blob: 49030349bf42e149ff449ddd33908db05ca04637 [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 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530126 * Reference RFC 6020.
127 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530128 * The "max-elements" statement, which is optional, takes as an argument a
129 * positive integer or the string "unbounded", which puts a constraint on
130 * valid list entries. A valid leaf-list or list always has at most
131 * max-elements entries.
132 *
133 * If no "max-elements" statement is present, it defaults to "unbounded".
134 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530135 private int maxElements = Integer.MAX_VALUE;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530136
137 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530138 * Reference RFC 6020.
139 *
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530140 * The "min-elements" statement, which is optional, takes as an argument a
141 * non-negative integer that puts a constraint on valid list entries. A
142 * valid leaf-list or list MUST have at least min-elements entries.
143 *
144 * If no "min-elements" statement is present, it defaults to zero.
145 *
146 * The behavior of the constraint depends on the type of the leaf-list's or
147 * list's closest ancestor node in the schema tree that is not a non-
148 * presence container:
149 *
150 * o If this ancestor is a case node, the constraint is enforced if any
151 * other node from the case exists.
152 *
153 * o Otherwise, it is enforced if the ancestor node exists.
154 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530155 private int minElements = 0;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530156
157 /**
158 * reference.
159 */
160 private String reference;
161
162 /**
163 * Status of the node.
164 */
165
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530166 private YangStatusType status = YangStatusType.CURRENT;
167
168 /**
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530169 * Package of the generated java code.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530170 */
171 private String pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530172
173 /**
174 * Constructor.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530175 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530176 public YangList() {
177 super(YangNodeType.LIST_NODE);
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530178 }
179
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530180 /**
181 * Get the YANG list name.
182 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530183 * @return YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530184 */
185 @Override
186 public String getName() {
187 return name;
188 }
189
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530190 /**
191 * Set the YANG list name.
192 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530193 * @param name YANG list name
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530194 */
195 @Override
196 public void setName(String name) {
197 this.name = name;
198 }
199
200 /**
201 * Get the config flag.
202 *
203 * @return the isConfig
204 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530205 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530206 return isConfig;
207 }
208
209 /**
210 * Set the config flag.
211 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530212 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530213 */
214 public void setConfig(boolean isCfg) {
215 isConfig = isCfg;
216 }
217
218 /**
219 * Get the description.
220 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530221 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530222 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530223 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530224 public String getDescription() {
225 return description;
226 }
227
228 /**
229 * Set the description.
230 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530231 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530232 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530233 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530234 public void setDescription(String description) {
235 this.description = description;
236 }
237
238 /**
239 * Get the list of key field names.
240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @return the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530242 */
243 public List<String> getKeyList() {
244 return keyList;
245 }
246
247 /**
248 * Set the list of key field names.
249 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530250 * @param keyList the list of key field names
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530251 */
252 private void setKeyList(List<String> keyList) {
253 this.keyList = keyList;
254 }
255
256 /**
257 * Add a key field name.
258 *
259 * @param key key field name.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530260 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530261 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530262 public void addKey(String key) throws DataModelException {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530263 if (getKeyList() == null) {
264 setKeyList(new LinkedList<String>());
265 }
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530266
267 if (getKeyList().contains(key)) {
268 throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
269 " key");
270 }
271
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530272 getKeyList().add(key);
273 }
274
275 /**
276 * Get the list of leaves.
277 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530278 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530279 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530280 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530281 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530282 return listOfLeaf;
283 }
284
285 /**
286 * Set the list of leaves.
287 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530288 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530289 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530290 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530291 listOfLeaf = leafsList;
292 }
293
294 /**
295 * Add a leaf.
296 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530297 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530298 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530299 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530300 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530301 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530302 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530303 }
304
305 getListOfLeaf().add(leaf);
306 }
307
308 /**
309 * Get the list of leaf-list.
310 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530311 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530312 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530313 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530314 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530315 return listOfLeafList;
316 }
317
318 /**
319 * Set the list of leaf-list.
320 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530321 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530322 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530323 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530324 this.listOfLeafList = listOfLeafList;
325 }
326
327 /**
328 * Add a leaf-list.
329 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530330 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530331 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530332 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530333 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530334 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530335 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530336 }
337
338 getListOfLeafList().add(leafList);
339 }
340
341 /**
342 * Get the max elements.
343 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530344 * @return the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530345 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530346 public int getMaxElements() {
347 return maxElements;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530348 }
349
350 /**
351 * Set the max elements.
352 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530353 * @param max the max elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530354 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530355 public void setMaxElements(int max) {
356 maxElements = max;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530357 }
358
359 /**
360 * Get the minimum elements.
361 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530362 * @return the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530363 */
364 public int getMinElements() {
365 return minElements;
366 }
367
368 /**
369 * Set the minimum elements.
370 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530371 * @param minElements the minimum elements
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530372 */
373 public void setMinElements(int minElements) {
374 this.minElements = minElements;
375 }
376
377 /**
378 * Get the textual reference.
379 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530380 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530381 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530382 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530383 public String getReference() {
384 return reference;
385 }
386
387 /**
388 * Set the textual reference.
389 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530390 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530391 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530392 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530393 public void setReference(String reference) {
394 this.reference = reference;
395 }
396
397 /**
398 * Get the status.
399 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530400 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530401 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530402 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530403 public YangStatusType getStatus() {
404 return status;
405 }
406
407 /**
408 * Set the status.
409 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530410 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530411 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530412 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 public void setStatus(YangStatusType status) {
414 this.status = status;
415 }
416
417 /**
418 * Returns the type of the parsed data.
419 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530420 * @return returns LIST_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530421 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530422 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530423 public YangConstructType getYangConstructType() {
424 return YangConstructType.LIST_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530425 }
426
427 /**
428 * Validate the data on entering the corresponding parse tree node.
429 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530430 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530431 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530432 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530433 public void validateDataOnEntry() throws DataModelException {
434 // TODO auto-generated method stub, to be implemented by parser
435 }
436
437 /**
438 * Validate the data on exiting the corresponding parse tree node.
439 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530440 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530441 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530442 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530443 public void validateDataOnExit() throws DataModelException {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530444 List<String> keys = getKeyList();
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530445 List<YangLeaf> leaves = getListOfLeaf();
446 List<YangLeafList> leafLists = getListOfLeafList();
447
448 setDefaultConfigValueToChild(leaves, leafLists);
449 validateConfig(leaves, leafLists);
450
451 /* A list must have atleast one key leaf if config is true */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530452 if (isConfig
453 && (keys == null || leaves == null && leafLists == null)) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530454 throw new DataModelException("A list must have atleast one key leaf if config is true;");
455 } else if (keys != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530456 if (leaves != null) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530457 validateLeafKey(leaves, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530458 }
459
460 if (leafLists != null) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530461 validateLeafListKey(leafLists, keys);
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530462 }
463 }
464 }
465
466 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530467 * Sets the config's value to all leaf if leaf's config statement is not
468 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530469 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530470 * @param leaves list of leaf attributes of YANG list
471 * @param leafLists list of leaf-list attributes of YANG list
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530472 */
473 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
474
Vinod Kumar S71cba682016-02-25 15:52:16 +0530475 /*
476 * If "config" is not specified, the default is the same as the parent
477 * schema node's "config" value.
478 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530479 if (leaves != null) {
480 for (YangLeaf leaf : leaves) {
481 if (leaf.isConfig() == null) {
482 leaf.setConfig(isConfig);
483 }
484 }
485 }
486
Vinod Kumar S71cba682016-02-25 15:52:16 +0530487 /*
488 * If "config" is not specified, the default is the same as the parent
489 * schema node's "config" value.
490 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530491 if (leafLists != null) {
492 for (YangLeafList leafList : leafLists) {
493 if (leafList.isConfig() == null) {
494 leafList.setConfig(isConfig);
495 }
496 }
497 }
498 }
499
500 /**
501 * Validates config statement of YANG list.
502 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530503 * @param leaves list of leaf attributes of YANG list
504 * @param leafLists list of leaf-list attributes of YANG list
505 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530506 */
507 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
508
Vinod Kumar S71cba682016-02-25 15:52:16 +0530509 /*
510 * If a node has "config" set to "false", no node underneath it can have
511 * "config" set to "true".
512 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530513 if (!isConfig && leaves != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530514 for (YangLeaf leaf : leaves) {
515 if (leaf.isConfig()) {
516 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
517 "it can have \"config\" set to \"true\".");
518 }
519 }
520 }
521
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530522 if (!isConfig && leafLists != null) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530523 for (YangLeafList leafList : leafLists) {
524 if (leafList.isConfig()) {
525 throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
526 "it can have \"config\" set to \"true\".");
527 }
528 }
529 }
530 }
531
532 /**
533 * Validates key statement of list.
534 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530535 * @param leaves list of leaf attributes of list
536 * @param keys list of key attributes of list
537 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530538 */
Vinod Kumar S71cba682016-02-25 15:52:16 +0530539 private void validateLeafKey(List<YangLeaf> leaves, List<String> keys) throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530540 boolean leafFound = false;
541 List<YangLeaf> keyLeaves = new LinkedList<>();
542
Vinod Kumar S71cba682016-02-25 15:52:16 +0530543 /*
544 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
545 * that is part of the key must not be the built-in type "empty".
546 */
547 for (String key : keys) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530548 for (YangLeaf leaf : leaves) {
549 if (key.equals(leaf.getLeafName())) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530550 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530551 throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
552 "type \"empty\".");
553 }
554 leafFound = true;
555 keyLeaves.add(leaf);
556 break;
557 }
558 }
559 if (!leafFound) {
560 throw new DataModelException("Leaf identifier must refer to a child leaf of the list");
561 }
562 leafFound = false;
563 }
564
Vinod Kumar S71cba682016-02-25 15:52:16 +0530565 /*
566 * All key leafs in a list MUST have the same value for their "config"
567 * as the list itself.
568 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530569 for (YangLeaf keyLeaf : keyLeaves) {
570 if (isConfig != keyLeaf.isConfig()) {
571 throw new DataModelException("All key leafs in a list must have the same value for their" +
572 " \"config\" as the list itself.");
573 }
574 }
575 }
576
577 /**
578 * Validates key statement of list.
579 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530580 * @param leafLists list of leaf-list attributes of list
581 * @param keys list of key attributes of list
582 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530583 */
Vinod Kumar S71cba682016-02-25 15:52:16 +0530584 private void validateLeafListKey(List<YangLeafList> leafLists, List<String> keys) throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530585 boolean leafFound = false;
586 List<YangLeafList> keyLeafLists = new LinkedList<>();
587
Vinod Kumar S71cba682016-02-25 15:52:16 +0530588 /*
589 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
590 * that is part of the key must not be the built-in type "empty".
591 */
592 for (String key : keys) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530593 for (YangLeafList leafList : leafLists) {
594 if (key.equals(leafList.getLeafName())) {
Vinod Kumar S71cba682016-02-25 15:52:16 +0530595 if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530596 throw new DataModelException(" A leaf-list that is part of the key must not be the built-in " +
597 "type \"empty\".");
598 }
599 leafFound = true;
600 keyLeafLists.add(leafList);
601 break;
602 }
603 }
604 if (!leafFound) {
605 throw new DataModelException("Leaf-list identifier must refer to a child leaf of the list");
606 }
607 leafFound = false;
608 }
609
Vinod Kumar S71cba682016-02-25 15:52:16 +0530610 /*
611 * All key leafs in a list MUST have the same value for their "config"
612 * as the list itself.
613 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530614 for (YangLeafList keyLeafList : keyLeafLists) {
615 if (isConfig() != keyLeafList.isConfig()) {
616 throw new DataModelException("All key leaf-lists in a list must have the same value for their" +
617 " \"config\" as the list itself.");
618 }
619 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530620 }
621
Vinod Kumar S71cba682016-02-25 15:52:16 +0530622 /**
623 * Populate the cached handle with information about the list attributes to
624 * generate java code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530625 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530626 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530627 public void generateJavaCodeEntry() {
628 // TODO Auto-generated method stub
629
630 }
631
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530632 /**
633 * Free the resources used to generate the java file corresponding to YANG
634 * list info.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530635 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530636 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530637 public void generateJavaCodeExit() {
638 // TODO Auto-generated method stub
639
640 }
641
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530642 /**
643 * Get the mapped java package.
644 *
645 * @return the java package
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530646 */
647 @Override
648 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530649 return pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530650 }
651
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530652 /**
653 * Set the mapped java package.
654 *
655 * @param pakg the package to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530656 */
657 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530658 public void setPackage(String pakg) {
659 pkg = pakg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530660
661 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530662
663 @Override
664 public CachedFileHandle getFileHandle() {
665 // TODO Auto-generated method stub
666 return null;
667 }
668
669 @Override
670 public void setFileHandle(CachedFileHandle fileHandle) {
671 // TODO Auto-generated method stub
672
673 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530674
675 @Override
676 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
677 // Asks helper to detect colliding child.
678 detectCollidingChildUtil(identifierName, dataType, this);
679 }
680
681 @Override
682 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
683 if (this.getName().equals(identifierName)) {
684 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
685 this.getName() + "\"");
686 }
687 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530688}