blob: 577e160ff45b1735b16da7affb86d389617c2c65 [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 */
Bharat saraswal870c56f2016-02-20 21:57:16 +053069public class YangList extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053070
71 /**
72 * name of the YANG list.
73 */
74 private String name;
75
76 /**
77 * If list maintains config data.
78 */
79 private boolean isConfig;
80
81 /**
82 * Description of list.
83 */
84 private String description;
85
86 /**
87 * Reference RFC 6020.
88 *
89 * The "key" statement, which MUST be present if the list represents
90 * configuration, and MAY be present otherwise, takes as an argument a
91 * string that specifies a space-separated list of leaf identifiers of this
92 * list. A leaf identifier MUST NOT appear more than once in the key. Each
93 * such leaf identifier MUST refer to a child leaf of the list. The leafs
94 * can be defined directly in sub-statements to the list, or in groupings
95 * used in the list.
96 *
97 * The combined values of all the leafs specified in the key are used to
98 * uniquely identify a list entry. All key leafs MUST be given values when a
99 * list entry is created. Thus, any default values in the key leafs or their
100 * types are ignored. It also implies that any mandatory statement in the
101 * key leafs are ignored.
102 *
103 * A leaf that is part of the key can be of any built-in or derived type,
104 * except it MUST NOT be the built-in type "empty".
105 *
106 * All key leafs in a list MUST have the same value for their "config" as
107 * the list itself.
108 *
109 * List of key leaf names.
110 */
111 private List<String> keyList;
112
113 /**
114 * List of leaves.
115 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530116 private List<YangLeaf<?>> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530117
118 /**
119 * List of leaf-lists.
120 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530121 private List<YangLeafList<?>> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530122
123 /**
124 * The "max-elements" statement, which is optional, takes as an argument a
125 * positive integer or the string "unbounded", which puts a constraint on
126 * valid list entries. A valid leaf-list or list always has at most
127 * max-elements entries.
128 *
129 * If no "max-elements" statement is present, it defaults to "unbounded".
130 */
131 private int maxElelements;
132
133 /**
134 * The "min-elements" statement, which is optional, takes as an argument a
135 * non-negative integer that puts a constraint on valid list entries. A
136 * valid leaf-list or list MUST have at least min-elements entries.
137 *
138 * If no "min-elements" statement is present, it defaults to zero.
139 *
140 * The behavior of the constraint depends on the type of the leaf-list's or
141 * list's closest ancestor node in the schema tree that is not a non-
142 * presence container:
143 *
144 * o If this ancestor is a case node, the constraint is enforced if any
145 * other node from the case exists.
146 *
147 * o Otherwise, it is enforced if the ancestor node exists.
148 */
149 private int minElements;
150
151 /**
152 * reference.
153 */
154 private String reference;
155
156 /**
157 * Status of the node.
158 */
159
160 private YangStatusType status;
161
162 /**
163 * Constructor.
164 *
165 * @param type list node
166 */
167 public YangList(YangNodeType type) {
168 super(type);
169 }
170
171 /* (non-Javadoc)
172 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
173 */
174 @Override
175 public String getName() {
176 return name;
177 }
178
179 /* (non-Javadoc)
180 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
181 */
182 @Override
183 public void setName(String name) {
184 this.name = name;
185 }
186
187 /**
188 * Get the config flag.
189 *
190 * @return the isConfig
191 */
192 public boolean isConfig() {
193 return isConfig;
194 }
195
196 /**
197 * Set the config flag.
198 *
199 * @param isCfg the config flag.
200 */
201 public void setConfig(boolean isCfg) {
202 isConfig = isCfg;
203 }
204
205 /**
206 * Get the description.
207 *
208 * @return the description.
209 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530210 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530211 public String getDescription() {
212 return description;
213 }
214
215 /**
216 * Set the description.
217 *
218 * @param description set the description.
219 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530220 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530221 public void setDescription(String description) {
222 this.description = description;
223 }
224
225 /**
226 * Get the list of key field names.
227 *
228 * @return the list of key field names.
229 */
230 public List<String> getKeyList() {
231 return keyList;
232 }
233
234 /**
235 * Set the list of key field names.
236 *
237 * @param keyList the list of key field names.
238 */
239 private void setKeyList(List<String> keyList) {
240 this.keyList = keyList;
241 }
242
243 /**
244 * Add a key field name.
245 *
246 * @param key key field name.
247 */
248 public void addKey(String key) {
249 if (getKeyList() == null) {
250 setKeyList(new LinkedList<String>());
251 }
252
253 getKeyList().add(key);
254 }
255
256 /**
257 * Get the list of leaves.
258 *
259 * @return the list of leaves.
260 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530261 @Override
262 public List<YangLeaf<?>> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530263 return listOfLeaf;
264 }
265
266 /**
267 * Set the list of leaves.
268 *
269 * @param leafsList the list of leaf to set.
270 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530271 private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530272 listOfLeaf = leafsList;
273 }
274
275 /**
276 * Add a leaf.
277 *
278 * @param leaf the leaf to be added.
279 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530280 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530281 public void addLeaf(YangLeaf<?> leaf) {
282 if (getListOfLeaf() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530283 setListOfLeaf(new LinkedList<YangLeaf<?>>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530284 }
285
286 getListOfLeaf().add(leaf);
287 }
288
289 /**
290 * Get the list of leaf-list.
291 *
292 * @return the list of leaf-list.
293 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530294 @Override
295 public List<YangLeafList<?>> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530296 return listOfLeafList;
297 }
298
299 /**
300 * Set the list of leaf-list.
301 *
302 * @param listOfLeafList the list of leaf-list to set.
303 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530304 private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530305 this.listOfLeafList = listOfLeafList;
306 }
307
308 /**
309 * Add a leaf-list.
310 *
311 * @param leafList the leaf-list to be added.
312 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530313 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530314 public void addLeafList(YangLeafList<?> leafList) {
315 if (getListOfLeafList() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530316 setListOfLeafList(new LinkedList<YangLeafList<?>>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530317 }
318
319 getListOfLeafList().add(leafList);
320 }
321
322 /**
323 * Get the max elements.
324 *
325 * @return the max elements.
326 */
327 public int getMaxElelements() {
328 return maxElelements;
329 }
330
331 /**
332 * Set the max elements.
333 *
334 * @param maxElelements the max elements.
335 */
336 public void setMaxElelements(int maxElelements) {
337 this.maxElelements = maxElelements;
338 }
339
340 /**
341 * Get the minimum elements.
342 *
343 * @return the minimum elements.
344 */
345 public int getMinElements() {
346 return minElements;
347 }
348
349 /**
350 * Set the minimum elements.
351 *
352 * @param minElements the minimum elements.
353 */
354 public void setMinElements(int minElements) {
355 this.minElements = minElements;
356 }
357
358 /**
359 * Get the textual reference.
360 *
361 * @return the reference.
362 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530363 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530364 public String getReference() {
365 return reference;
366 }
367
368 /**
369 * Set the textual reference.
370 *
371 * @param reference the reference to set.
372 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530373 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530374 public void setReference(String reference) {
375 this.reference = reference;
376 }
377
378 /**
379 * Get the status.
380 *
381 * @return the status.
382 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530383 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530384 public YangStatusType getStatus() {
385 return status;
386 }
387
388 /**
389 * Set the status.
390 *
391 * @param status the status to set.
392 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530393 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530394 public void setStatus(YangStatusType status) {
395 this.status = status;
396 }
397
398 /**
399 * Returns the type of the parsed data.
400 *
401 * @return returns LIST_DATA.
402 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530403 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530404 public ParsableDataType getParsableDataType() {
405 return ParsableDataType.LIST_DATA;
406 }
407
408 /**
409 * Validate the data on entering the corresponding parse tree node.
410 *
411 * @throws DataModelException a violation of data model rules.
412 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530413 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530414 public void validateDataOnEntry() throws DataModelException {
415 // TODO auto-generated method stub, to be implemented by parser
416 }
417
418 /**
419 * Validate the data on exiting the corresponding parse tree node.
420 *
421 * @throws DataModelException a violation of data model rules.
422 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530423 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530424 public void validateDataOnExit() throws DataModelException {
425 // TODO auto-generated method stub, to be implemented by parser
426 }
427
428 /* (non-Javadoc)
429 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
430 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530431 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530432 public void generateJavaCodeEntry() {
433 // TODO Auto-generated method stub
434
435 }
436
437 /* (non-Javadoc)
438 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
439 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530440 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530441 public void generateJavaCodeExit() {
442 // TODO Auto-generated method stub
443
444 }
445
446 /* (non-Javadoc)
447 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
448 */
449 @Override
450 public String getPackage() {
451 // TODO Auto-generated method stub
452 return null;
453 }
454
455 /* (non-Javadoc)
456 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
457 */
458 @Override
459 public void setPackage(String pkg) {
460 // TODO Auto-generated method stub
461
462 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530463
464 @Override
465 public CachedFileHandle getFileHandle() {
466 // TODO Auto-generated method stub
467 return null;
468 }
469
470 @Override
471 public void setFileHandle(CachedFileHandle fileHandle) {
472 // TODO Auto-generated method stub
473
474 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530475}