blob: d75c09d01aa361adc3ac5ebcb6334fb45d8aba3c [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 */
68public class YangList extends YangNode
69 implements YangLeavesHolder, YangCommonInfo, Parsable {
70
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 */
116 @SuppressWarnings("rawtypes")
117 private List<YangLeaf> listOfLeaf;
118
119 /**
120 * List of leaf-lists.
121 */
122 @SuppressWarnings("rawtypes")
123 private List<YangLeafList> listOfLeafList;
124
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 */
133 private int maxElelements;
134
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 */
151 private int minElements;
152
153 /**
154 * reference.
155 */
156 private String reference;
157
158 /**
159 * Status of the node.
160 */
161
162 private YangStatusType status;
163
164 /**
165 * Constructor.
166 *
167 * @param type list node
168 */
169 public YangList(YangNodeType type) {
170 super(type);
171 }
172
173 /* (non-Javadoc)
174 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
175 */
176 @Override
177 public String getName() {
178 return name;
179 }
180
181 /* (non-Javadoc)
182 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
183 */
184 @Override
185 public void setName(String name) {
186 this.name = name;
187 }
188
189 /**
190 * Get the config flag.
191 *
192 * @return the isConfig
193 */
194 public boolean isConfig() {
195 return isConfig;
196 }
197
198 /**
199 * Set the config flag.
200 *
201 * @param isCfg the config flag.
202 */
203 public void setConfig(boolean isCfg) {
204 isConfig = isCfg;
205 }
206
207 /**
208 * Get the description.
209 *
210 * @return the description.
211 */
212 public String getDescription() {
213 return description;
214 }
215
216 /**
217 * Set the description.
218 *
219 * @param description set the description.
220 */
221 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 */
261 @SuppressWarnings("rawtypes")
262 public List<YangLeaf> getListOfLeaf() {
263 return listOfLeaf;
264 }
265
266 /**
267 * Set the list of leaves.
268 *
269 * @param leafsList the list of leaf to set.
270 */
271 @SuppressWarnings("rawtypes")
272 private void setListOfLeaf(List<YangLeaf> leafsList) {
273 listOfLeaf = leafsList;
274 }
275
276 /**
277 * Add a leaf.
278 *
279 * @param leaf the leaf to be added.
280 */
281 @SuppressWarnings("rawtypes")
282 public void addLeaf(YangLeaf<?> leaf) {
283 if (getListOfLeaf() == null) {
284 setListOfLeaf(new LinkedList<YangLeaf>());
285 }
286
287 getListOfLeaf().add(leaf);
288 }
289
290 /**
291 * Get the list of leaf-list.
292 *
293 * @return the list of leaf-list.
294 */
295 @SuppressWarnings("rawtypes")
296 public List<YangLeafList> getListOfLeafList() {
297 return listOfLeafList;
298 }
299
300 /**
301 * Set the list of leaf-list.
302 *
303 * @param listOfLeafList the list of leaf-list to set.
304 */
305 @SuppressWarnings("rawtypes")
306 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
307 this.listOfLeafList = listOfLeafList;
308 }
309
310 /**
311 * Add a leaf-list.
312 *
313 * @param leafList the leaf-list to be added.
314 */
315 @SuppressWarnings("rawtypes")
316 public void addLeafList(YangLeafList<?> leafList) {
317 if (getListOfLeafList() == null) {
318 setListOfLeafList(new LinkedList<YangLeafList>());
319 }
320
321 getListOfLeafList().add(leafList);
322 }
323
324 /**
325 * Get the max elements.
326 *
327 * @return the max elements.
328 */
329 public int getMaxElelements() {
330 return maxElelements;
331 }
332
333 /**
334 * Set the max elements.
335 *
336 * @param maxElelements the max elements.
337 */
338 public void setMaxElelements(int maxElelements) {
339 this.maxElelements = maxElelements;
340 }
341
342 /**
343 * Get the minimum elements.
344 *
345 * @return the minimum elements.
346 */
347 public int getMinElements() {
348 return minElements;
349 }
350
351 /**
352 * Set the minimum elements.
353 *
354 * @param minElements the minimum elements.
355 */
356 public void setMinElements(int minElements) {
357 this.minElements = minElements;
358 }
359
360 /**
361 * Get the textual reference.
362 *
363 * @return the reference.
364 */
365 public String getReference() {
366 return reference;
367 }
368
369 /**
370 * Set the textual reference.
371 *
372 * @param reference the reference to set.
373 */
374 public void setReference(String reference) {
375 this.reference = reference;
376 }
377
378 /**
379 * Get the status.
380 *
381 * @return the status.
382 */
383 public YangStatusType getStatus() {
384 return status;
385 }
386
387 /**
388 * Set the status.
389 *
390 * @param status the status to set.
391 */
392 public void setStatus(YangStatusType status) {
393 this.status = status;
394 }
395
396 /**
397 * Returns the type of the parsed data.
398 *
399 * @return returns LIST_DATA.
400 */
401 public ParsableDataType getParsableDataType() {
402 return ParsableDataType.LIST_DATA;
403 }
404
405 /**
406 * Validate the data on entering the corresponding parse tree node.
407 *
408 * @throws DataModelException a violation of data model rules.
409 */
410 public void validateDataOnEntry() throws DataModelException {
411 // TODO auto-generated method stub, to be implemented by parser
412 }
413
414 /**
415 * Validate the data on exiting the corresponding parse tree node.
416 *
417 * @throws DataModelException a violation of data model rules.
418 */
419 public void validateDataOnExit() throws DataModelException {
420 // TODO auto-generated method stub, to be implemented by parser
421 }
422
423 /* (non-Javadoc)
424 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
425 */
426 public void generateJavaCodeEntry() {
427 // TODO Auto-generated method stub
428
429 }
430
431 /* (non-Javadoc)
432 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
433 */
434 public void generateJavaCodeExit() {
435 // TODO Auto-generated method stub
436
437 }
438
439 /* (non-Javadoc)
440 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
441 */
442 @Override
443 public String getPackage() {
444 // TODO Auto-generated method stub
445 return null;
446 }
447
448 /* (non-Javadoc)
449 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
450 */
451 @Override
452 public void setPackage(String pkg) {
453 // TODO Auto-generated method stub
454
455 }
456}