blob: 0e0bc3e7fef43602b135cd326b7d85c0846c4150 [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
57 implements YangCommonInfo, Parsable {
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Creates a YANG leaf-list.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530128 */
129 public YangLeafList() {
130 }
131
132 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530133 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530134 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530135 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530136 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530137 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530138 return name;
139 }
140
141 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530142 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530143 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530144 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530145 */
146 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530147 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530148 }
149
150 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530151 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530152 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530153 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530154 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530155 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530156 return isConfig;
157 }
158
159 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530160 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530161 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530162 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530163 */
164 public void setConfig(boolean isCfg) {
165 isConfig = isCfg;
166 }
167
168 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530169 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530170 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530171 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530172 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530173 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530174 public String getDescription() {
175 return description;
176 }
177
178 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530179 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530180 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530181 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530183 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530184 public void setDescription(String description) {
185 this.description = description;
186 }
187
188 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530189 * Returns the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530190 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530191 * @return the max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530192 */
193 public int getMaxElelements() {
194 return maxElelements;
195 }
196
197 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530198 * Sets the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530199 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530200 * @param maxElelements max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530201 */
202 public void setMaxElelements(int maxElelements) {
203 this.maxElelements = maxElelements;
204 }
205
206 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530207 * Returns the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530208 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530209 * @return the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530210 */
211 public int getMinElements() {
212 return minElements;
213 }
214
215 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530216 * Sets the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530217 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530218 * @param minElements the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530219 */
220 public void setMinElements(int minElements) {
221 this.minElements = minElements;
222 }
223
224 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530225 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530226 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 * @return the reference
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 String getReference() {
231 return reference;
232 }
233
234 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530235 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530236 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530237 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530238 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530239 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530240 public void setReference(String reference) {
241 this.reference = reference;
242 }
243
244 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530245 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530246 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530247 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530248 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530249 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530250 public YangStatusType getStatus() {
251 return status;
252 }
253
254 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530255 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530256 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530257 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530258 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530259 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530260 public void setStatus(YangStatusType status) {
261 this.status = status;
262 }
263
264 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530265 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530266 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530267 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530268 */
269 public String getUnits() {
270 return units;
271 }
272
273 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530274 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530275 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530277 */
278 public void setUnits(String units) {
279 this.units = units;
280 }
281
282 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530283 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530286 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530287 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530288 return dataType;
289 }
290
291 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530292 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530293 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530294 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530295 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530296 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530297 this.dataType = dataType;
298 }
299
300 /**
301 * Returns the type of the parsed data.
302 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530303 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530304 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530305 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530306 public YangConstructType getYangConstructType() {
307 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530308 }
309
310 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530311 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530312 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530313 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530314 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530315 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530316 public void validateDataOnEntry()
317 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530318 // TODO auto-generated method stub, to be implemented by parser
319
320 }
321
322 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530323 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530324 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530325 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530326 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530327 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530328 public void validateDataOnExit()
329 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530330 // TODO auto-generated method stub, to be implemented by parser
331
332 }
333}