blob: 8a328e0077037b9f0ffec28fb6241992e648432d [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
19import java.util.LinkedList;
20import java.util.List;
21
22import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23import org.onosproject.yangutils.parser.Parsable;
24import org.onosproject.yangutils.parser.ParsableDataType;
Bharat saraswal594bc6d2016-02-22 22:15:21 +053025import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053026
27/*-
28 * The "list" statement is used to define an interior data node in the
29 * schema tree. A list node may exist in multiple instances in the data
30 * tree. Each such instance is known as a list entry. The "list"
31 * statement takes one argument, which is an identifier, followed by a
32 * block of sub-statements that holds detailed list information.
33 *
34 * A list entry is uniquely identified by the values of the list's keys,
35 * if defined.
36 *
37 * The list's sub-statements
38 *
39 * +--------------+---------+-------------+------------------+
40 * | substatement | section | cardinality |data model mapping|
41 * +--------------+---------+-------------+------------------+
42 * | anyxml | 7.10 | 0..n |-not supported |
43 * | choice | 7.9 | 0..n |-child nodes |
44 * | config | 7.19.1 | 0..1 |-boolean |
45 * | container | 7.5 | 0..n |-child nodes |
46 * | description | 7.19.3 | 0..1 |-string |
47 * | grouping | 7.11 | 0..n |-child nodes |
48 * | if-feature | 7.18.2 | 0..n |-TODO |
49 * | key | 7.8.2 | 0..1 |-String list |
50 * | leaf | 7.6 | 0..n |-YangLeaf |
51 * | leaf-list | 7.7 | 0..n |-YangLeafList |
52 * | list | 7.8 | 0..n |-child nodes |
53 * | max-elements | 7.7.4 | 0..1 |-int |
54 * | min-elements | 7.7.3 | 0..1 |-int |
55 * | must | 7.5.3 | 0..n |-TODO |
56 * | ordered-by | 7.7.5 | 0..1 |-TODO |
57 * | reference | 7.19.4 | 0..1 |-string |
58 * | status | 7.19.2 | 0..1 |-YangStatus |
59 * | typedef | 7.3 | 0..n |-child nodes |
60 * | unique | 7.8.3 | 0..n |-TODO |
61 * | uses | 7.12 | 0..n |-child nodes(TODO)|
62 * | when | 7.19.5 | 0..1 |-TODO |
63 * +--------------+---------+-------------+------------------+
64 */
65
66/**
67 * List data represented in YANG.
68 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053069public class YangList extends YangNode
70 implements YangLeavesHolder, YangCommonInfo, Parsable {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053071
72 /**
73 * name of the YANG list.
74 */
75 private String name;
76
77 /**
78 * If list maintains config data.
79 */
80 private boolean isConfig;
81
82 /**
83 * Description of list.
84 */
85 private String description;
86
87 /**
88 * Reference RFC 6020.
89 *
90 * The "key" statement, which MUST be present if the list represents
91 * configuration, and MAY be present otherwise, takes as an argument a
92 * string that specifies a space-separated list of leaf identifiers of this
93 * list. A leaf identifier MUST NOT appear more than once in the key. Each
94 * such leaf identifier MUST refer to a child leaf of the list. The leafs
95 * can be defined directly in sub-statements to the list, or in groupings
96 * used in the list.
97 *
98 * The combined values of all the leafs specified in the key are used to
99 * uniquely identify a list entry. All key leafs MUST be given values when a
100 * list entry is created. Thus, any default values in the key leafs or their
101 * types are ignored. It also implies that any mandatory statement in the
102 * key leafs are ignored.
103 *
104 * A leaf that is part of the key can be of any built-in or derived type,
105 * except it MUST NOT be the built-in type "empty".
106 *
107 * All key leafs in a list MUST have the same value for their "config" as
108 * the list itself.
109 *
110 * List of key leaf names.
111 */
112 private List<String> keyList;
113
114 /**
115 * List of leaves.
116 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530117 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530118
119 /**
120 * List of leaf-lists.
121 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530123
124 /**
125 * The "max-elements" statement, which is optional, takes as an argument a
126 * positive integer or the string "unbounded", which puts a constraint on
127 * valid list entries. A valid leaf-list or list always has at most
128 * max-elements entries.
129 *
130 * If no "max-elements" statement is present, it defaults to "unbounded".
131 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530132 private int maxElelements = Integer.MAX_VALUE;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530133
134 /**
135 * The "min-elements" statement, which is optional, takes as an argument a
136 * non-negative integer that puts a constraint on valid list entries. A
137 * valid leaf-list or list MUST have at least min-elements entries.
138 *
139 * If no "min-elements" statement is present, it defaults to zero.
140 *
141 * The behavior of the constraint depends on the type of the leaf-list's or
142 * list's closest ancestor node in the schema tree that is not a non-
143 * presence container:
144 *
145 * o If this ancestor is a case node, the constraint is enforced if any
146 * other node from the case exists.
147 *
148 * o Otherwise, it is enforced if the ancestor node exists.
149 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530150 private int minElements = 0;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530151
152 /**
153 * reference.
154 */
155 private String reference;
156
157 /**
158 * Status of the node.
159 */
160
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530161 private YangStatusType status = YangStatusType.CURRENT;
162
163 /**
164 * package of the generated java code.
165 */
166 private String pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530167
168 /**
169 * Constructor.
170 *
171 * @param type list node
172 */
173 public YangList(YangNodeType type) {
174 super(type);
175 }
176
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530177 /**
178 * Get the YANG list name.
179 *
180 * @return YANG list name.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530181 */
182 @Override
183 public String getName() {
184 return name;
185 }
186
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530187 /**
188 * Set the YANG list name.
189 *
190 * @param name YANG list name.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530191 */
192 @Override
193 public void setName(String name) {
194 this.name = name;
195 }
196
197 /**
198 * Get the config flag.
199 *
200 * @return the isConfig
201 */
202 public boolean isConfig() {
203 return isConfig;
204 }
205
206 /**
207 * Set the config flag.
208 *
209 * @param isCfg the config flag.
210 */
211 public void setConfig(boolean isCfg) {
212 isConfig = isCfg;
213 }
214
215 /**
216 * Get the description.
217 *
218 * @return the description.
219 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530220 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530221 public String getDescription() {
222 return description;
223 }
224
225 /**
226 * Set the description.
227 *
228 * @param description set the description.
229 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530230 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530231 public void setDescription(String description) {
232 this.description = description;
233 }
234
235 /**
236 * Get the list of key field names.
237 *
238 * @return the list of key field names.
239 */
240 public List<String> getKeyList() {
241 return keyList;
242 }
243
244 /**
245 * Set the list of key field names.
246 *
247 * @param keyList the list of key field names.
248 */
249 private void setKeyList(List<String> keyList) {
250 this.keyList = keyList;
251 }
252
253 /**
254 * Add a key field name.
255 *
256 * @param key key field name.
257 */
258 public void addKey(String key) {
259 if (getKeyList() == null) {
260 setKeyList(new LinkedList<String>());
261 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 getKeyList().add(key);
263 }
264
265 /**
266 * Get the list of leaves.
267 *
268 * @return the list of leaves.
269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530271 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530272 return listOfLeaf;
273 }
274
275 /**
276 * Set the list of leaves.
277 *
278 * @param leafsList the list of leaf to set.
279 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530280 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530281 listOfLeaf = leafsList;
282 }
283
284 /**
285 * Add a leaf.
286 *
287 * @param leaf the leaf to be added.
288 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530289 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530290 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530291 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530292 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530293 }
294
295 getListOfLeaf().add(leaf);
296 }
297
298 /**
299 * Get the list of leaf-list.
300 *
301 * @return the list of leaf-list.
302 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530303 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530304 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530305 return listOfLeafList;
306 }
307
308 /**
309 * Set the list of leaf-list.
310 *
311 * @param listOfLeafList the list of leaf-list to set.
312 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530313 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530314 this.listOfLeafList = listOfLeafList;
315 }
316
317 /**
318 * Add a leaf-list.
319 *
320 * @param leafList the leaf-list to be added.
321 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530322 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530323 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530324 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530325 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530326 }
327
328 getListOfLeafList().add(leafList);
329 }
330
331 /**
332 * Get the max elements.
333 *
334 * @return the max elements.
335 */
336 public int getMaxElelements() {
337 return maxElelements;
338 }
339
340 /**
341 * Set the max elements.
342 *
343 * @param maxElelements the max elements.
344 */
345 public void setMaxElelements(int maxElelements) {
346 this.maxElelements = maxElelements;
347 }
348
349 /**
350 * Get the minimum elements.
351 *
352 * @return the minimum elements.
353 */
354 public int getMinElements() {
355 return minElements;
356 }
357
358 /**
359 * Set the minimum elements.
360 *
361 * @param minElements the minimum elements.
362 */
363 public void setMinElements(int minElements) {
364 this.minElements = minElements;
365 }
366
367 /**
368 * Get the textual reference.
369 *
370 * @return the reference.
371 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530372 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530373 public String getReference() {
374 return reference;
375 }
376
377 /**
378 * Set the textual reference.
379 *
380 * @param reference the reference to set.
381 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530382 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530383 public void setReference(String reference) {
384 this.reference = reference;
385 }
386
387 /**
388 * Get the status.
389 *
390 * @return the status.
391 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530392 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530393 public YangStatusType getStatus() {
394 return status;
395 }
396
397 /**
398 * Set the status.
399 *
400 * @param status the status to set.
401 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530402 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530403 public void setStatus(YangStatusType status) {
404 this.status = status;
405 }
406
407 /**
408 * Returns the type of the parsed data.
409 *
410 * @return returns LIST_DATA.
411 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530412 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 public ParsableDataType getParsableDataType() {
414 return ParsableDataType.LIST_DATA;
415 }
416
417 /**
418 * Validate the data on entering the corresponding parse tree node.
419 *
420 * @throws DataModelException a violation of data model rules.
421 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530422 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530423 public void validateDataOnEntry() throws DataModelException {
424 // TODO auto-generated method stub, to be implemented by parser
425 }
426
427 /**
428 * Validate the data on exiting the corresponding parse tree node.
429 *
430 * @throws DataModelException a violation of data model rules.
431 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530432 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530433 public void validateDataOnExit() throws DataModelException {
434 // TODO auto-generated method stub, to be implemented by parser
435 }
436
437 /* (non-Javadoc)
438 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
439 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530440 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530441 public void generateJavaCodeEntry() {
442 // TODO Auto-generated method stub
443
444 }
445
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530446 /**
447 * Free the resources used to generate the java file corresponding to YANG
448 * list info.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530449 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530450 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530451 public void generateJavaCodeExit() {
452 // TODO Auto-generated method stub
453
454 }
455
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530456 /**
457 * Get the mapped java package.
458 *
459 * @return the java package
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530460 */
461 @Override
462 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530463 return pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530464 }
465
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530466 /**
467 * Set the mapped java package.
468 *
469 * @param pakg the package to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530470 */
471 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530472 public void setPackage(String pakg) {
473 pkg = pakg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530474
475 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530476
477 @Override
478 public CachedFileHandle getFileHandle() {
479 // TODO Auto-generated method stub
480 return null;
481 }
482
483 @Override
484 public void setFileHandle(CachedFileHandle fileHandle) {
485 // TODO Auto-generated method stub
486
487 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530488}