blob: febae0e6099697dd1f55ef7dedcfe314f0932cc1 [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,
61 YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
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 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053090 private int maxElelements = Integer.MAX_VALUE;
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 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530110 private int minElements = 0;
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() {
156 }
157
158 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530159 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530160 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530161 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530162 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530163 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530164 return name;
165 }
166
167 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530168 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530169 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530170 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530171 */
172 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530173 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530174 }
175
176 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530177 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530178 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530179 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530180 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530181 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 return isConfig;
183 }
184
185 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530186 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530187 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530188 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530189 */
190 public void setConfig(boolean isCfg) {
191 isConfig = isCfg;
192 }
193
194 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530195 * Returns the when.
196 *
197 * @return the when
198 */
199 @Override
200 public YangWhen getWhen() {
201 return when;
202 }
203
204 /**
205 * Sets the when.
206 *
207 * @param when the when to set
208 */
209 @Override
210 public void setWhen(YangWhen when) {
211 this.when = when;
212 }
213
214 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530215 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530216 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530217 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530218 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530219 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530220 public String getDescription() {
221 return description;
222 }
223
224 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530225 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530226 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530228 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530229 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530230 public void setDescription(String description) {
231 this.description = description;
232 }
233
234 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530235 * Returns the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530236 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530237 * @return the max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530238 */
239 public int getMaxElelements() {
240 return maxElelements;
241 }
242
243 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530244 * Sets the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530246 * @param maxElelements max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530247 */
248 public void setMaxElelements(int maxElelements) {
249 this.maxElelements = maxElelements;
250 }
251
252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Returns the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530254 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 * @return the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530256 */
257 public int getMinElements() {
258 return minElements;
259 }
260
261 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530262 * Sets the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530263 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530264 * @param minElements the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530265 */
266 public void setMinElements(int minElements) {
267 this.minElements = minElements;
268 }
269
270 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530271 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530272 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530273 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530274 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530275 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530276 public String getReference() {
277 return reference;
278 }
279
280 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530281 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530282 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530283 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530285 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530286 public void setReference(String reference) {
287 this.reference = reference;
288 }
289
290 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530291 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530292 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530293 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530294 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530295 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530296 public YangStatusType getStatus() {
297 return status;
298 }
299
300 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530301 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530302 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530303 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530304 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530305 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530306 public void setStatus(YangStatusType status) {
307 this.status = status;
308 }
309
310 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530311 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530312 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530313 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530314 */
315 public String getUnits() {
316 return units;
317 }
318
319 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530320 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530321 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530322 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530323 */
324 public void setUnits(String units) {
325 this.units = units;
326 }
327
328 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530329 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530330 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530331 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530332 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530333 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530334 return dataType;
335 }
336
337 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530338 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530339 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530340 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530341 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530342 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530343 this.dataType = dataType;
344 }
345
346 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530347 * Retrieves the YANG node in which the leaf is defined.
348 *
349 * @return the YANG node in which the leaf is defined
350 */
351 public YangLeavesHolder getContainedIn() {
352 return containedIn;
353 }
354
355 /**
356 * Assigns the YANG node in which the leaf is defined.
357 *
358 * @param containedIn the YANG node in which the leaf is defined
359 */
360 public void setContainedIn(YangLeavesHolder containedIn) {
361 this.containedIn = containedIn;
362 }
363
364 @Override
365 public YangLeafList clone()
366 throws CloneNotSupportedException {
367 return (YangLeafList) super.clone();
368 }
369
370 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530371 * Returns the type of the parsed data.
372 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530373 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530374 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530375 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530376 public YangConstructType getYangConstructType() {
377 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530378 }
379
380 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530381 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530382 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530383 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530384 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530385 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530386 public void validateDataOnEntry()
387 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530388 // TODO auto-generated method stub, to be implemented by parser
389
390 }
391
392 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530393 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530394 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530395 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530396 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530397 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530398 public void validateDataOnExit()
399 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530400 // TODO auto-generated method stub, to be implemented by parser
401
402 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530403
404 @Override
405 public List<YangIfFeature> getIfFeatureList() {
406 return ifFeatureList;
407 }
408
409 @Override
410 public void addIfFeatureList(YangIfFeature ifFeature) {
411 if (getIfFeatureList() == null) {
412 setIfFeatureList(new LinkedList<>());
413 }
414 getIfFeatureList().add(ifFeature);
415 }
416
417 @Override
418 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
419 this.ifFeatureList = ifFeatureList;
420 }
421
422 @Override
423 public List<YangMust> getListOfMust() {
424 return mustConstraintList;
425 }
426
427 @Override
428 public void setListOfMust(List<YangMust> mustConstraintList) {
429 this.mustConstraintList = mustConstraintList;
430 }
431
432 @Override
433 public void addMust(YangMust must) {
434 if (getListOfMust() == null) {
435 setListOfMust(new LinkedList<>());
436 }
437 getListOfMust().add(must);
438 }
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530439}