blob: 2ce44fbb1ddfbcb6f808ffb1ed5ebd3affca6c0e [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;
20
Vinod Kumar S19f39c72016-02-09 20:12:31 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022import org.onosproject.yangutils.datamodel.utils.Parsable;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053024
25/*
26 * Reference:RFC 6020.
27 * Where the "leaf" statement is used to define a simple scalar variable
28 * of a particular type, the "leaf-list" statement is used to define an
29 * array of a particular type. The "leaf-list" statement takes one
30 * argument, which is an identifier, followed by a block of
31 * sub-statements that holds detailed leaf-list information.
32 *
33 * The values in a leaf-list MUST be unique.
34 *
35 * The leaf-list's sub-statements
36 *
37 * +--------------+---------+-------------+------------------+
38 * | substatement | section | cardinality |data model mapping|
39 * +--------------+---------+-------------+------------------+
40 * | config | 7.19.1 | 0..1 | -boolean |
41 * | description | 7.19.3 | 0..1 | -string |
42 * | if-feature | 7.18.2 | 0..n | -TODO |
43 * | max-elements | 7.7.4 | 0..1 | -int |
44 * | min-elements | 7.7.3 | 0..1 | -int |
45 * | must | 7.5.3 | 0..n | -TODO |
46 * | ordered-by | 7.7.5 | 0..1 | -TODO |
47 * | reference | 7.19.4 | 0..1 | -string |
48 * | status | 7.19.2 | 0..1 | -YangStatus |
49 * | type | 7.4 | 1 | -YangType |
50 * | units | 7.3.3 | 0..1 | -string |
51 * | when | 7.19.5 | 0..1 | -TODO |
52 * +--------------+---------+-------------+------------------+
53 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053054
Vinod Kumar S19f39c72016-02-09 20:12:31 +053055/**
Bharat saraswald9822e92016-04-05 15:13:44 +053056 * Represents leaf-list data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053057 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053058public class YangLeafList
Bharat saraswal96dfef02016-06-16 00:29:12 +053059 implements YangCommonInfo, Parsable, Cloneable, Serializable {
60
61 private static final long serialVersionUID = 806201637L;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053062
63 /**
64 * Name of leaf-list.
65 */
66 private String name;
67
68 /**
69 * If the leaf-list is a config parameter.
70 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053071 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053072
73 /**
74 * Description of leaf-list.
75 */
76 private String description;
77
78 /**
79 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053080 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053081 * The "max-elements" statement, which is optional, takes as an argument a
82 * positive integer or the string "unbounded", which puts a constraint on
83 * valid list entries. A valid leaf-list or list always has at most
84 * max-elements entries.
85 *
86 * If no "max-elements" statement is present, it defaults to "unbounded".
87 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053088 private int maxElelements = Integer.MAX_VALUE;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053089
90 /**
91 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053092 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053093 * The "min-elements" statement, which is optional, takes as an argument a
94 * non-negative integer that puts a constraint on valid list entries. A
95 * valid leaf-list or list MUST have at least min-elements entries.
96 *
97 * If no "min-elements" statement is present, it defaults to zero.
98 *
99 * The behavior of the constraint depends on the type of the leaf-list's or
100 * list's closest ancestor node in the schema tree that is not a non-
101 * presence container:
102 *
103 * o If this ancestor is a case node, the constraint is enforced if any
104 * other node from the case exists.
105 *
106 * o Otherwise, it is enforced if the ancestor node exists.
107 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530108 private int minElements = 0;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530109
110 /**
111 * The textual reference to this leaf-list.
112 */
113 private String reference;
114
115 /**
116 * Status of the leaf-list in the YANG definition.
117 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530119
120 /**
121 * Textual units.
122 */
123 private String units;
124
125 /**
126 * Data type of leaf-list.
127 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530128 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530129
130 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530131 * YANG Node in which the leaf is contained.
132 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530133 private transient YangLeavesHolder containedIn;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530134
135 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Creates a YANG leaf-list.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530137 */
138 public YangLeafList() {
139 }
140
141 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530142 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530143 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530144 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530145 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530146 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530147 return name;
148 }
149
150 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530151 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530152 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530153 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530154 */
155 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530156 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530157 }
158
159 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530160 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530161 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530162 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530163 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530164 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530165 return isConfig;
166 }
167
168 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530169 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530170 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530171 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530172 */
173 public void setConfig(boolean isCfg) {
174 isConfig = isCfg;
175 }
176
177 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530178 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530179 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530180 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530181 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530182 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530183 public String getDescription() {
184 return description;
185 }
186
187 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530188 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530189 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530190 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530191 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530192 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530193 public void setDescription(String description) {
194 this.description = description;
195 }
196
197 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530198 * Returns the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530199 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530200 * @return the max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530201 */
202 public int getMaxElelements() {
203 return maxElelements;
204 }
205
206 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530207 * Sets the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530208 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530209 * @param maxElelements max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530210 */
211 public void setMaxElelements(int maxElelements) {
212 this.maxElelements = maxElelements;
213 }
214
215 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530216 * Returns the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530217 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530218 * @return the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530219 */
220 public int getMinElements() {
221 return minElements;
222 }
223
224 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530225 * Sets the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530226 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 * @param minElements the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530228 */
229 public void setMinElements(int minElements) {
230 this.minElements = minElements;
231 }
232
233 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530234 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530235 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530236 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530237 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530238 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530239 public String getReference() {
240 return reference;
241 }
242
243 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530244 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530246 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530247 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530248 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530249 public void setReference(String reference) {
250 this.reference = reference;
251 }
252
253 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530254 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530255 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530256 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530257 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530258 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530259 public YangStatusType getStatus() {
260 return status;
261 }
262
263 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530264 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530265 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530266 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530267 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530268 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530269 public void setStatus(YangStatusType status) {
270 this.status = status;
271 }
272
273 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530274 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530275 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530277 */
278 public String getUnits() {
279 return units;
280 }
281
282 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530283 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530286 */
287 public void setUnits(String units) {
288 this.units = units;
289 }
290
291 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530292 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530293 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530294 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530295 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530296 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530297 return dataType;
298 }
299
300 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530301 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530302 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530303 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530304 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530305 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530306 this.dataType = dataType;
307 }
308
309 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530310 * Retrieves the YANG node in which the leaf is defined.
311 *
312 * @return the YANG node in which the leaf is defined
313 */
314 public YangLeavesHolder getContainedIn() {
315 return containedIn;
316 }
317
318 /**
319 * Assigns the YANG node in which the leaf is defined.
320 *
321 * @param containedIn the YANG node in which the leaf is defined
322 */
323 public void setContainedIn(YangLeavesHolder containedIn) {
324 this.containedIn = containedIn;
325 }
326
327 @Override
328 public YangLeafList clone()
329 throws CloneNotSupportedException {
330 return (YangLeafList) super.clone();
331 }
332
333 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530334 * Returns the type of the parsed data.
335 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530336 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530337 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530338 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530339 public YangConstructType getYangConstructType() {
340 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530341 }
342
343 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530344 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530345 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530346 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530347 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530348 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530349 public void validateDataOnEntry()
350 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530351 // TODO auto-generated method stub, to be implemented by parser
352
353 }
354
355 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530356 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530357 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530358 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530359 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530360 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530361 public void validateDataOnExit()
362 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530363 // TODO auto-generated method stub, to be implemented by parser
364
365 }
366}