blob: 809bb8c11778e1288b1effc6968afde5204ac219 [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 */
52/**
Bharat saraswald9822e92016-04-05 15:13:44 +053053 * Represents leaf-list data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053054 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053055public class YangLeafList implements YangCommonInfo, Parsable {
Vinod Kumar S19f39c72016-02-09 20:12:31 +053056
57 /**
58 * Name of leaf-list.
59 */
60 private String name;
61
62 /**
63 * If the leaf-list is a config parameter.
64 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053065 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053066
67 /**
68 * Description of leaf-list.
69 */
70 private String description;
71
72 /**
73 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053074 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053075 * The "max-elements" statement, which is optional, takes as an argument a
76 * positive integer or the string "unbounded", which puts a constraint on
77 * valid list entries. A valid leaf-list or list always has at most
78 * max-elements entries.
79 *
80 * If no "max-elements" statement is present, it defaults to "unbounded".
81 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053082 private int maxElelements = Integer.MAX_VALUE;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053083
84 /**
85 * Reference:RFC 6020.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053086 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053087 * The "min-elements" statement, which is optional, takes as an argument a
88 * non-negative integer that puts a constraint on valid list entries. A
89 * valid leaf-list or list MUST have at least min-elements entries.
90 *
91 * If no "min-elements" statement is present, it defaults to zero.
92 *
93 * The behavior of the constraint depends on the type of the leaf-list's or
94 * list's closest ancestor node in the schema tree that is not a non-
95 * presence container:
96 *
97 * o If this ancestor is a case node, the constraint is enforced if any
98 * other node from the case exists.
99 *
100 * o Otherwise, it is enforced if the ancestor node exists.
101 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530102 private int minElements = 0;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530103
104 /**
105 * The textual reference to this leaf-list.
106 */
107 private String reference;
108
109 /**
110 * Status of the leaf-list in the YANG definition.
111 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530112 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530113
114 /**
115 * Textual units.
116 */
117 private String units;
118
119 /**
120 * Data type of leaf-list.
121 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530123
124 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530125 * Creates a YANG leaf-list.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530126 */
127 public YangLeafList() {
128 }
129
130 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530131 * Returns the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530132 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530133 * @return the leaf-list name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530134 */
135 public String getLeafName() {
136 return name;
137 }
138
139 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530140 * Sets the leaf-list name.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530141 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530142 * @param leafListName the leaf-list name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530143 */
144 public void setLeafName(String leafListName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530145 name = leafListName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530146 }
147
148 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530149 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530150 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530151 * @return the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530152 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530153 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530154 return isConfig;
155 }
156
157 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530158 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530159 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530160 * @param isCfg the config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530161 */
162 public void setConfig(boolean isCfg) {
163 isConfig = isCfg;
164 }
165
166 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530167 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530168 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530169 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530170 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530171 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530172 public String getDescription() {
173 return description;
174 }
175
176 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530177 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530178 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530179 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530180 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530181 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 public void setDescription(String description) {
183 this.description = description;
184 }
185
186 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530187 * Returns the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530188 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530189 * @return the max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530190 */
191 public int getMaxElelements() {
192 return maxElelements;
193 }
194
195 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530196 * Sets the max elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530197 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530198 * @param maxElelements max elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530199 */
200 public void setMaxElelements(int maxElelements) {
201 this.maxElelements = maxElelements;
202 }
203
204 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530205 * Returns the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530206 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530207 * @return the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530208 */
209 public int getMinElements() {
210 return minElements;
211 }
212
213 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530214 * Sets the min elements no.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530215 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530216 * @param minElements the min elements no
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530217 */
218 public void setMinElements(int minElements) {
219 this.minElements = minElements;
220 }
221
222 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530223 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530224 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530225 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530226 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530227 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530228 public String getReference() {
229 return reference;
230 }
231
232 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530233 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530234 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530235 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530236 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530237 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530238 public void setReference(String reference) {
239 this.reference = reference;
240 }
241
242 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530243 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530244 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530245 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530246 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530247 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530248 public YangStatusType getStatus() {
249 return status;
250 }
251
252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530254 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530256 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530257 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530258 public void setStatus(YangStatusType status) {
259 this.status = status;
260 }
261
262 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530263 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530264 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530265 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530266 */
267 public String getUnits() {
268 return units;
269 }
270
271 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530272 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530273 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530274 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530275 */
276 public void setUnits(String units) {
277 this.units = units;
278 }
279
280 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530281 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530282 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530283 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530285 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530286 return dataType;
287 }
288
289 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530290 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530291 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530292 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530293 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530294 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530295 this.dataType = dataType;
296 }
297
298 /**
299 * Returns the type of the parsed data.
300 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530301 * @return returns LEAF_LIST_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530302 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530303 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530304 public YangConstructType getYangConstructType() {
305 return YangConstructType.LEAF_LIST_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530306 }
307
308 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530309 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530310 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530311 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530312 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530313 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530314 public void validateDataOnEntry() throws DataModelException {
315 // TODO auto-generated method stub, to be implemented by parser
316
317 }
318
319 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530320 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530321 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530322 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530323 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530324 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530325 public void validateDataOnExit() throws DataModelException {
326 // TODO auto-generated method stub, to be implemented by parser
327
328 }
329}