blob: cbb2038c900dab81b830079378831da9c23faf65 [file] [log] [blame]
Vinod Kumar S19f39c72016-02-09 20:12:31 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S19f39c72016-02-09 20:12:31 +05303 *
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
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053020import java.util.LinkedList;
21import java.util.List;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053023import org.onosproject.yangutils.datamodel.utils.Parsable;
24import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053025
26/*
27 * Reference:RFC 6020.
28 * Where the "leaf" statement is used to define a simple scalar variable
29 * of a particular type, the "leaf-list" statement is used to define an
30 * array of a particular type. The "leaf-list" statement takes one
31 * argument, which is an identifier, followed by a block of
32 * sub-statements that holds detailed leaf-list information.
33 *
34 * The values in a leaf-list MUST be unique.
35 *
36 * The leaf-list's sub-statements
37 *
38 * +--------------+---------+-------------+------------------+
39 * | substatement | section | cardinality |data model mapping|
40 * +--------------+---------+-------------+------------------+
41 * | config | 7.19.1 | 0..1 | -boolean |
42 * | description | 7.19.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053043 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Vinod Kumar S19f39c72016-02-09 20:12:31 +053044 * | max-elements | 7.7.4 | 0..1 | -int |
45 * | min-elements | 7.7.3 | 0..1 | -int |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053046 * | must | 7.5.3 | 0..n | -YangMust |
Vinod Kumar S19f39c72016-02-09 20:12:31 +053047 * | ordered-by | 7.7.5 | 0..1 | -TODO |
48 * | reference | 7.19.4 | 0..1 | -string |
49 * | status | 7.19.2 | 0..1 | -YangStatus |
50 * | type | 7.4 | 1 | -YangType |
51 * | units | 7.3.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053052 * | when | 7.19.5 | 0..1 | -YangWhen |
Vinod Kumar S19f39c72016-02-09 20:12:31 +053053 * +--------------+---------+-------------+------------------+
54 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053055
Vinod Kumar S19f39c72016-02-09 20:12:31 +053056/**
Bharat saraswald9822e92016-04-05 15:13:44 +053057 * Represents leaf-list data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053058 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053059public class YangLeafList
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053060 implements YangCommonInfo, Parsable, Cloneable, Serializable,
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053061 YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
Bharat saraswal96dfef02016-06-16 00:29:12 +053062
63 private static final long serialVersionUID = 806201637L;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053064
65 /**
66 * Name of leaf-list.
67 */
68 private String name;
69
70 /**
71 * If the leaf-list is a config parameter.
72 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053073 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053074
75 /**
76 * Description of leaf-list.
77 */
78 private String description;
79
80 /**
81 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053082 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053083 * The "max-elements" statement, which is optional, takes as an argument a
84 * positive integer or the string "unbounded", which puts a constraint on
85 * valid list entries. A valid leaf-list or list always has at most
86 * max-elements entries.
87 *
88 * If no "max-elements" statement is present, it defaults to "unbounded".
89 */
rama-huawei6c728a92016-07-11 14:48:12 +053090 private YangMaxElement maxElement;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053091
92 /**
93 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053094 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053095 * The "min-elements" statement, which is optional, takes as an argument a
96 * non-negative integer that puts a constraint on valid list entries. A
97 * valid leaf-list or list MUST have at least min-elements entries.
98 *
99 * If no "min-elements" statement is present, it defaults to zero.
100 *
101 * The behavior of the constraint depends on the type of the leaf-list's or
102 * list's closest ancestor node in the schema tree that is not a non-
103 * presence container:
104 *
105 * o If this ancestor is a case node, the constraint is enforced if any
106 * other node from the case exists.
107 *
108 * o Otherwise, it is enforced if the ancestor node exists.
109 */
rama-huawei6c728a92016-07-11 14:48:12 +0530110 private YangMinElement minElements;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530111
112 /**
113 * The textual reference to this leaf-list.
114 */
115 private String reference;
116
117 /**
118 * Status of the leaf-list in the YANG definition.
119 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530120 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530121
122 /**
123 * Textual units.
124 */
125 private String units;
126
127 /**
128 * Data type of leaf-list.
129 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530130 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530131
132 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530133 * YANG Node in which the leaf is contained.
134 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530135 private transient YangLeavesHolder containedIn;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530136
137 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530138 * List of must statement constraints.
139 */
140 private List<YangMust> mustConstraintList;
141
142 /**
143 * When data of the leaf.
144 */
145 private YangWhen when;
146
147 /**
148 * List of if-feature.
149 */
150 private List<YangIfFeature> ifFeatureList;
151
152 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530153 * Creates a YANG leaf-list.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530154 */
155 public YangLeafList() {
rama-huawei6c728a92016-07-11 14:48:12 +0530156 setMinElements(new YangMinElement());
157 setMaxElements(new YangMaxElement());
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530158 }
159
160 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530161 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530162 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530163 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530164 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530165 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530166 return name;
167 }
168
169 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530170 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530171 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530172 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530173 */
174 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530175 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530176 }
177
178 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530179 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530180 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530181 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530183 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530184 return isConfig;
185 }
186
187 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530188 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530189 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530190 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530191 */
192 public void setConfig(boolean isCfg) {
193 isConfig = isCfg;
194 }
195
196 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530197 * Returns the when.
198 *
199 * @return the when
200 */
201 @Override
202 public YangWhen getWhen() {
203 return when;
204 }
205
206 /**
207 * Sets the when.
208 *
209 * @param when the when to set
210 */
211 @Override
212 public void setWhen(YangWhen when) {
213 this.when = when;
214 }
215
216 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530217 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530218 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530219 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530220 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530221 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530222 public String getDescription() {
223 return description;
224 }
225
226 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530227 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530228 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530229 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530230 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530231 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530232 public void setDescription(String description) {
233 this.description = description;
234 }
235
236 /**
rama-huawei6c728a92016-07-11 14:48:12 +0530237 * Returns the maximum elements number.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530238 *
rama-huawei6c728a92016-07-11 14:48:12 +0530239 * @return the maximum elements number
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530240 */
rama-huawei6c728a92016-07-11 14:48:12 +0530241 public YangMaxElement getMaxElements() {
242 return maxElement;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530243 }
244
245 /**
rama-huawei6c728a92016-07-11 14:48:12 +0530246 * Sets the maximum elements number.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530247 *
rama-huawei6c728a92016-07-11 14:48:12 +0530248 * @param maxElement maximum elements number
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530249 */
rama-huawei6c728a92016-07-11 14:48:12 +0530250 public void setMaxElements(YangMaxElement maxElement) {
251 this.maxElement = maxElement;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530252 }
253
254 /**
rama-huawei6c728a92016-07-11 14:48:12 +0530255 * Returns the minimum elements number.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530256 *
rama-huawei6c728a92016-07-11 14:48:12 +0530257 * @return the minimum elements number
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530258 */
rama-huawei6c728a92016-07-11 14:48:12 +0530259 public YangMinElement getMinElements() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530260 return minElements;
261 }
262
263 /**
rama-huawei6c728a92016-07-11 14:48:12 +0530264 * Sets the minimum elements number.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530265 *
rama-huawei6c728a92016-07-11 14:48:12 +0530266 * @param minElements the minimum elements number
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530267 */
rama-huawei6c728a92016-07-11 14:48:12 +0530268 public void setMinElements(YangMinElement minElements) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530269 this.minElements = minElements;
270 }
271
272 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530273 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530274 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530275 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530276 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530277 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530278 public String getReference() {
279 return reference;
280 }
281
282 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530283 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530286 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530287 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530288 public void setReference(String reference) {
289 this.reference = reference;
290 }
291
292 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530293 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530294 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530295 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530296 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530297 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530298 public YangStatusType getStatus() {
299 return status;
300 }
301
302 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530303 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530304 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530305 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530306 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530307 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530308 public void setStatus(YangStatusType status) {
309 this.status = status;
310 }
311
312 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530313 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530314 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530315 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530316 */
317 public String getUnits() {
318 return units;
319 }
320
321 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530322 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530323 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530324 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530325 */
326 public void setUnits(String units) {
327 this.units = units;
328 }
329
330 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530331 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530332 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530333 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530334 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530335 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530336 return dataType;
337 }
338
339 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530340 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530341 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530342 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530343 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530344 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530345 this.dataType = dataType;
346 }
347
348 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530349 * Retrieves the YANG node in which the leaf is defined.
350 *
351 * @return the YANG node in which the leaf is defined
352 */
353 public YangLeavesHolder getContainedIn() {
354 return containedIn;
355 }
356
357 /**
358 * Assigns the YANG node in which the leaf is defined.
359 *
360 * @param containedIn the YANG node in which the leaf is defined
361 */
362 public void setContainedIn(YangLeavesHolder containedIn) {
363 this.containedIn = containedIn;
364 }
365
366 @Override
367 public YangLeafList clone()
368 throws CloneNotSupportedException {
369 return (YangLeafList) super.clone();
370 }
371
372 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530373 * Returns the type of the parsed data.
374 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530375 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530376 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530377 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530378 public YangConstructType getYangConstructType() {
379 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530380 }
381
382 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530383 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530384 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530385 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530386 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530387 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530388 public void validateDataOnEntry()
389 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530390 // TODO auto-generated method stub, to be implemented by parser
391
392 }
393
394 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530395 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530396 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530397 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530398 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530399 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530400 public void validateDataOnExit()
401 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530402 // TODO auto-generated method stub, to be implemented by parser
403
404 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530405
406 @Override
407 public List<YangIfFeature> getIfFeatureList() {
408 return ifFeatureList;
409 }
410
411 @Override
412 public void addIfFeatureList(YangIfFeature ifFeature) {
413 if (getIfFeatureList() == null) {
414 setIfFeatureList(new LinkedList<>());
415 }
416 getIfFeatureList().add(ifFeature);
417 }
418
419 @Override
420 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
421 this.ifFeatureList = ifFeatureList;
422 }
423
424 @Override
425 public List<YangMust> getListOfMust() {
426 return mustConstraintList;
427 }
428
429 @Override
430 public void setListOfMust(List<YangMust> mustConstraintList) {
431 this.mustConstraintList = mustConstraintList;
432 }
433
434 @Override
435 public void addMust(YangMust must) {
436 if (getListOfMust() == null) {
437 setListOfMust(new LinkedList<>());
438 }
439 getListOfMust().add(must);
440 }
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530441}