blob: 57944203735f241cd1dd9175159f41c93894d6c3 [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
19import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053021import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053022
23/*
24 * Reference:RFC 6020.
25 * Where the "leaf" statement is used to define a simple scalar variable
26 * of a particular type, the "leaf-list" statement is used to define an
27 * array of a particular type. The "leaf-list" statement takes one
28 * argument, which is an identifier, followed by a block of
29 * sub-statements that holds detailed leaf-list information.
30 *
31 * The values in a leaf-list MUST be unique.
32 *
33 * The leaf-list's sub-statements
34 *
35 * +--------------+---------+-------------+------------------+
36 * | substatement | section | cardinality |data model mapping|
37 * +--------------+---------+-------------+------------------+
38 * | config | 7.19.1 | 0..1 | -boolean |
39 * | description | 7.19.3 | 0..1 | -string |
40 * | if-feature | 7.18.2 | 0..n | -TODO |
41 * | max-elements | 7.7.4 | 0..1 | -int |
42 * | min-elements | 7.7.3 | 0..1 | -int |
43 * | must | 7.5.3 | 0..n | -TODO |
44 * | ordered-by | 7.7.5 | 0..1 | -TODO |
45 * | reference | 7.19.4 | 0..1 | -string |
46 * | status | 7.19.2 | 0..1 | -YangStatus |
47 * | type | 7.4 | 1 | -YangType |
48 * | units | 7.3.3 | 0..1 | -string |
49 * | when | 7.19.5 | 0..1 | -TODO |
50 * +--------------+---------+-------------+------------------+
51 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053052
Vinod Kumar S19f39c72016-02-09 20:12:31 +053053/**
Bharat saraswald9822e92016-04-05 15:13:44 +053054 * Represents leaf-list data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053055 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053056public class YangLeafList
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053057 implements YangCommonInfo, Parsable, Cloneable {
Vinod Kumar S19f39c72016-02-09 20:12:31 +053058
59 /**
60 * Name of leaf-list.
61 */
62 private String name;
63
64 /**
65 * If the leaf-list is a config parameter.
66 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053067 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053068
69 /**
70 * Description of leaf-list.
71 */
72 private String description;
73
74 /**
75 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053077 * The "max-elements" statement, which is optional, takes as an argument a
78 * positive integer or the string "unbounded", which puts a constraint on
79 * valid list entries. A valid leaf-list or list always has at most
80 * max-elements entries.
81 *
82 * If no "max-elements" statement is present, it defaults to "unbounded".
83 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053084 private int maxElelements = Integer.MAX_VALUE;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053085
86 /**
87 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053088 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053089 * The "min-elements" statement, which is optional, takes as an argument a
90 * non-negative integer that puts a constraint on valid list entries. A
91 * valid leaf-list or list MUST have at least min-elements entries.
92 *
93 * If no "min-elements" statement is present, it defaults to zero.
94 *
95 * The behavior of the constraint depends on the type of the leaf-list's or
96 * list's closest ancestor node in the schema tree that is not a non-
97 * presence container:
98 *
99 * o If this ancestor is a case node, the constraint is enforced if any
100 * other node from the case exists.
101 *
102 * o Otherwise, it is enforced if the ancestor node exists.
103 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530104 private int minElements = 0;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530105
106 /**
107 * The textual reference to this leaf-list.
108 */
109 private String reference;
110
111 /**
112 * Status of the leaf-list in the YANG definition.
113 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530114 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530115
116 /**
117 * Textual units.
118 */
119 private String units;
120
121 /**
122 * Data type of leaf-list.
123 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530125
126 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530127 * YANG Node in which the leaf is contained.
128 */
129 YangLeavesHolder containedIn;
130
131 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530132 * Creates a YANG leaf-list.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530133 */
134 public YangLeafList() {
135 }
136
137 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530138 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530139 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530140 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530141 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530142 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530143 return name;
144 }
145
146 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530147 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530148 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530149 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530150 */
151 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530152 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530153 }
154
155 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530156 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530159 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530160 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530161 return isConfig;
162 }
163
164 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530165 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530166 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530167 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530168 */
169 public void setConfig(boolean isCfg) {
170 isConfig = isCfg;
171 }
172
173 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530174 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530175 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530176 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530177 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530178 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530179 public String getDescription() {
180 return description;
181 }
182
183 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530184 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530185 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530186 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530187 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530188 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530189 public void setDescription(String description) {
190 this.description = description;
191 }
192
193 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530194 * Returns the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530195 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530196 * @return the max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530197 */
198 public int getMaxElelements() {
199 return maxElelements;
200 }
201
202 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530203 * Sets the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530204 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530205 * @param maxElelements max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530206 */
207 public void setMaxElelements(int maxElelements) {
208 this.maxElelements = maxElelements;
209 }
210
211 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530212 * Returns the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530213 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530214 * @return the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530215 */
216 public int getMinElements() {
217 return minElements;
218 }
219
220 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530221 * Sets the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530222 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530223 * @param minElements the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530224 */
225 public void setMinElements(int minElements) {
226 this.minElements = minElements;
227 }
228
229 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530230 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530231 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530232 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530233 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530234 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530235 public String getReference() {
236 return reference;
237 }
238
239 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530240 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530241 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530242 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530243 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530244 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 public void setReference(String reference) {
246 this.reference = reference;
247 }
248
249 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530250 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530251 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530252 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530253 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530254 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530255 public YangStatusType getStatus() {
256 return status;
257 }
258
259 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530260 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530261 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530262 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530263 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530264 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530265 public void setStatus(YangStatusType status) {
266 this.status = status;
267 }
268
269 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530270 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530271 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530272 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530273 */
274 public String getUnits() {
275 return units;
276 }
277
278 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530279 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530280 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530281 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530282 */
283 public void setUnits(String units) {
284 this.units = units;
285 }
286
287 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530288 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530289 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530290 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530291 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530292 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530293 return dataType;
294 }
295
296 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530297 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530298 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530299 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530300 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530301 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530302 this.dataType = dataType;
303 }
304
305 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530306 * Retrieves the YANG node in which the leaf is defined.
307 *
308 * @return the YANG node in which the leaf is defined
309 */
310 public YangLeavesHolder getContainedIn() {
311 return containedIn;
312 }
313
314 /**
315 * Assigns the YANG node in which the leaf is defined.
316 *
317 * @param containedIn the YANG node in which the leaf is defined
318 */
319 public void setContainedIn(YangLeavesHolder containedIn) {
320 this.containedIn = containedIn;
321 }
322
323 @Override
324 public YangLeafList clone()
325 throws CloneNotSupportedException {
326 return (YangLeafList) super.clone();
327 }
328
329 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530330 * Returns the type of the parsed data.
331 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530332 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530333 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530334 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530335 public YangConstructType getYangConstructType() {
336 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530337 }
338
339 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530340 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530341 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530342 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530343 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530344 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530345 public void validateDataOnEntry()
346 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530347 // TODO auto-generated method stub, to be implemented by parser
348
349 }
350
351 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530352 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530353 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530354 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530355 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530356 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530357 public void validateDataOnExit()
358 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530359 // TODO auto-generated method stub, to be implemented by parser
360
361 }
362}