blob: e09b94cd7eeb77216683cc7bfa2fa28c5723389f [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;
25
26/*-
27 * The "list" statement is used to define an interior data node in the
28 * schema tree. A list node may exist in multiple instances in the data
29 * tree. Each such instance is known as a list entry. The "list"
30 * statement takes one argument, which is an identifier, followed by a
31 * block of sub-statements that holds detailed list information.
32 *
33 * A list entry is uniquely identified by the values of the list's keys,
34 * if defined.
35 *
36 * The list's sub-statements
37 *
38 * +--------------+---------+-------------+------------------+
39 * | substatement | section | cardinality |data model mapping|
40 * +--------------+---------+-------------+------------------+
41 * | anyxml | 7.10 | 0..n |-not supported |
42 * | choice | 7.9 | 0..n |-child nodes |
43 * | config | 7.19.1 | 0..1 |-boolean |
44 * | container | 7.5 | 0..n |-child nodes |
45 * | description | 7.19.3 | 0..1 |-string |
46 * | grouping | 7.11 | 0..n |-child nodes |
47 * | if-feature | 7.18.2 | 0..n |-TODO |
48 * | key | 7.8.2 | 0..1 |-String list |
49 * | leaf | 7.6 | 0..n |-YangLeaf |
50 * | leaf-list | 7.7 | 0..n |-YangLeafList |
51 * | list | 7.8 | 0..n |-child nodes |
52 * | max-elements | 7.7.4 | 0..1 |-int |
53 * | min-elements | 7.7.3 | 0..1 |-int |
54 * | must | 7.5.3 | 0..n |-TODO |
55 * | ordered-by | 7.7.5 | 0..1 |-TODO |
56 * | reference | 7.19.4 | 0..1 |-string |
57 * | status | 7.19.2 | 0..1 |-YangStatus |
58 * | typedef | 7.3 | 0..n |-child nodes |
59 * | unique | 7.8.3 | 0..n |-TODO |
60 * | uses | 7.12 | 0..n |-child nodes(TODO)|
61 * | when | 7.19.5 | 0..1 |-TODO |
62 * +--------------+---------+-------------+------------------+
63 */
64
65/**
66 * List data represented in YANG.
67 */
Bharat saraswal870c56f2016-02-20 21:57:16 +053068public class YangList extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053069
70 /**
71 * name of the YANG list.
72 */
73 private String name;
74
75 /**
76 * If list maintains config data.
77 */
78 private boolean isConfig;
79
80 /**
81 * Description of list.
82 */
83 private String description;
84
85 /**
86 * Reference RFC 6020.
87 *
88 * The "key" statement, which MUST be present if the list represents
89 * configuration, and MAY be present otherwise, takes as an argument a
90 * string that specifies a space-separated list of leaf identifiers of this
91 * list. A leaf identifier MUST NOT appear more than once in the key. Each
92 * such leaf identifier MUST refer to a child leaf of the list. The leafs
93 * can be defined directly in sub-statements to the list, or in groupings
94 * used in the list.
95 *
96 * The combined values of all the leafs specified in the key are used to
97 * uniquely identify a list entry. All key leafs MUST be given values when a
98 * list entry is created. Thus, any default values in the key leafs or their
99 * types are ignored. It also implies that any mandatory statement in the
100 * key leafs are ignored.
101 *
102 * A leaf that is part of the key can be of any built-in or derived type,
103 * except it MUST NOT be the built-in type "empty".
104 *
105 * All key leafs in a list MUST have the same value for their "config" as
106 * the list itself.
107 *
108 * List of key leaf names.
109 */
110 private List<String> keyList;
111
112 /**
113 * List of leaves.
114 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530115 private List<YangLeaf<?>> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530116
117 /**
118 * List of leaf-lists.
119 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530120 private List<YangLeafList<?>> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530121
122 /**
123 * The "max-elements" statement, which is optional, takes as an argument a
124 * positive integer or the string "unbounded", which puts a constraint on
125 * valid list entries. A valid leaf-list or list always has at most
126 * max-elements entries.
127 *
128 * If no "max-elements" statement is present, it defaults to "unbounded".
129 */
130 private int maxElelements;
131
132 /**
133 * The "min-elements" statement, which is optional, takes as an argument a
134 * non-negative integer that puts a constraint on valid list entries. A
135 * valid leaf-list or list MUST have at least min-elements entries.
136 *
137 * If no "min-elements" statement is present, it defaults to zero.
138 *
139 * The behavior of the constraint depends on the type of the leaf-list's or
140 * list's closest ancestor node in the schema tree that is not a non-
141 * presence container:
142 *
143 * o If this ancestor is a case node, the constraint is enforced if any
144 * other node from the case exists.
145 *
146 * o Otherwise, it is enforced if the ancestor node exists.
147 */
148 private int minElements;
149
150 /**
151 * reference.
152 */
153 private String reference;
154
155 /**
156 * Status of the node.
157 */
158
159 private YangStatusType status;
160
161 /**
162 * Constructor.
163 *
164 * @param type list node
165 */
166 public YangList(YangNodeType type) {
167 super(type);
168 }
169
170 /* (non-Javadoc)
171 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
172 */
173 @Override
174 public String getName() {
175 return name;
176 }
177
178 /* (non-Javadoc)
179 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
180 */
181 @Override
182 public void setName(String name) {
183 this.name = name;
184 }
185
186 /**
187 * Get the config flag.
188 *
189 * @return the isConfig
190 */
191 public boolean isConfig() {
192 return isConfig;
193 }
194
195 /**
196 * Set the config flag.
197 *
198 * @param isCfg the config flag.
199 */
200 public void setConfig(boolean isCfg) {
201 isConfig = isCfg;
202 }
203
204 /**
205 * Get the description.
206 *
207 * @return the description.
208 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530209 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530210 public String getDescription() {
211 return description;
212 }
213
214 /**
215 * Set the description.
216 *
217 * @param description set the description.
218 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530219 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530220 public void setDescription(String description) {
221 this.description = description;
222 }
223
224 /**
225 * Get the list of key field names.
226 *
227 * @return the list of key field names.
228 */
229 public List<String> getKeyList() {
230 return keyList;
231 }
232
233 /**
234 * Set the list of key field names.
235 *
236 * @param keyList the list of key field names.
237 */
238 private void setKeyList(List<String> keyList) {
239 this.keyList = keyList;
240 }
241
242 /**
243 * Add a key field name.
244 *
245 * @param key key field name.
246 */
247 public void addKey(String key) {
248 if (getKeyList() == null) {
249 setKeyList(new LinkedList<String>());
250 }
251
252 getKeyList().add(key);
253 }
254
255 /**
256 * Get the list of leaves.
257 *
258 * @return the list of leaves.
259 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530260 @Override
261 public List<YangLeaf<?>> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 return listOfLeaf;
263 }
264
265 /**
266 * Set the list of leaves.
267 *
268 * @param leafsList the list of leaf to set.
269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530271 listOfLeaf = leafsList;
272 }
273
274 /**
275 * Add a leaf.
276 *
277 * @param leaf the leaf to be added.
278 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530279 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530280 public void addLeaf(YangLeaf<?> leaf) {
281 if (getListOfLeaf() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530282 setListOfLeaf(new LinkedList<YangLeaf<?>>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530283 }
284
285 getListOfLeaf().add(leaf);
286 }
287
288 /**
289 * Get the list of leaf-list.
290 *
291 * @return the list of leaf-list.
292 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530293 @Override
294 public List<YangLeafList<?>> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530295 return listOfLeafList;
296 }
297
298 /**
299 * Set the list of leaf-list.
300 *
301 * @param listOfLeafList the list of leaf-list to set.
302 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530303 private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530304 this.listOfLeafList = listOfLeafList;
305 }
306
307 /**
308 * Add a leaf-list.
309 *
310 * @param leafList the leaf-list to be added.
311 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530312 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530313 public void addLeafList(YangLeafList<?> leafList) {
314 if (getListOfLeafList() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530315 setListOfLeafList(new LinkedList<YangLeafList<?>>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530316 }
317
318 getListOfLeafList().add(leafList);
319 }
320
321 /**
322 * Get the max elements.
323 *
324 * @return the max elements.
325 */
326 public int getMaxElelements() {
327 return maxElelements;
328 }
329
330 /**
331 * Set the max elements.
332 *
333 * @param maxElelements the max elements.
334 */
335 public void setMaxElelements(int maxElelements) {
336 this.maxElelements = maxElelements;
337 }
338
339 /**
340 * Get the minimum elements.
341 *
342 * @return the minimum elements.
343 */
344 public int getMinElements() {
345 return minElements;
346 }
347
348 /**
349 * Set the minimum elements.
350 *
351 * @param minElements the minimum elements.
352 */
353 public void setMinElements(int minElements) {
354 this.minElements = minElements;
355 }
356
357 /**
358 * Get the textual reference.
359 *
360 * @return the reference.
361 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530362 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530363 public String getReference() {
364 return reference;
365 }
366
367 /**
368 * Set the textual reference.
369 *
370 * @param reference the reference to set.
371 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530372 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530373 public void setReference(String reference) {
374 this.reference = reference;
375 }
376
377 /**
378 * Get the status.
379 *
380 * @return the status.
381 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530382 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530383 public YangStatusType getStatus() {
384 return status;
385 }
386
387 /**
388 * Set the status.
389 *
390 * @param status the status to set.
391 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530392 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530393 public void setStatus(YangStatusType status) {
394 this.status = status;
395 }
396
397 /**
398 * Returns the type of the parsed data.
399 *
400 * @return returns LIST_DATA.
401 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530402 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530403 public ParsableDataType getParsableDataType() {
404 return ParsableDataType.LIST_DATA;
405 }
406
407 /**
408 * Validate the data on entering the corresponding parse tree node.
409 *
410 * @throws DataModelException a violation of data model rules.
411 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530412 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 public void validateDataOnEntry() throws DataModelException {
414 // TODO auto-generated method stub, to be implemented by parser
415 }
416
417 /**
418 * Validate the data on exiting 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 validateDataOnExit() throws DataModelException {
424 // TODO auto-generated method stub, to be implemented by parser
425 }
426
427 /* (non-Javadoc)
428 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
429 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530430 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530431 public void generateJavaCodeEntry() {
432 // TODO Auto-generated method stub
433
434 }
435
436 /* (non-Javadoc)
437 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
438 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530439 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530440 public void generateJavaCodeExit() {
441 // TODO Auto-generated method stub
442
443 }
444
445 /* (non-Javadoc)
446 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
447 */
448 @Override
449 public String getPackage() {
450 // TODO Auto-generated method stub
451 return null;
452 }
453
454 /* (non-Javadoc)
455 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
456 */
457 @Override
458 public void setPackage(String pkg) {
459 // TODO Auto-generated method stub
460
461 }
462}