blob: 9adeff781329ad6f8c77f85d1babd846ab658e65 [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 * The "leaf" statement is used to define a leaf node in the schema
26 * tree. It takes one argument, which is an identifier, followed by a
27 * block of sub-statements that holds detailed leaf information.
28 *
29 * A leaf node has a value, but no child nodes in the data tree.
30 * Conceptually, the value in the data tree is always in the canonical
31 * form.
32 *
33 * A leaf node exists in zero or one instances in the data tree.
34 *
35 * The "leaf" statement is used to define a scalar variable of a
36 * particular built-in or derived type.
37 *
38 * The leaf's sub-statements
39 *
40 * +--------------+---------+-------------+------------------+
41 * | substatement | section | cardinality |data model mapping|
42 * +--------------+---------+-------------+------------------+
43 * | config | 7.19.1 | 0..1 | - boolean |
44 * | default | 7.6.4 | 0..1 | - TODO |
45 * | description | 7.19.3 | 0..1 | - string |
46 * | if-feature | 7.18.2 | 0..n | - TODO |
47 * | mandatory | 7.6.5 | 0..1 | - boolean |
48 * | must | 7.5.3 | 0..n | - TODO |
49 * | reference | 7.19.4 | 0..1 | - string |
50 * | status | 7.19.2 | 0..1 | - YangStatus |
51 * | type | 7.6.3 | 1 | - YangType |
52 * | units | 7.3.3 | 0..1 | - String |
53 * | when | 7.19.5 | 0..1 | - TODO |
54 * +--------------+---------+-------------+------------------+
55 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053056
Vinod Kumar S19f39c72016-02-09 20:12:31 +053057/**
Bharat saraswald9822e92016-04-05 15:13:44 +053058 * Represents leaf data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053059 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053060public class YangLeaf
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053061 implements YangCommonInfo, Parsable, Cloneable {
Vinod Kumar S19f39c72016-02-09 20:12:31 +053062
63 /**
64 * Name of leaf.
65 */
66 private String name;
67
68 /**
69 * If the leaf 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.
75 */
76 private String description;
77
78 /**
79 * If mandatory leaf.
80 */
81 private boolean isMandatory;
82
83 /**
84 * The textual reference to this leaf.
85 */
86 private String reference;
87
88 /**
89 * Status of leaf in YANG definition.
90 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053091 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053092
93 /**
94 * Textual units info.
95 */
96 private String units;
97
98 /**
99 * Data type of the leaf.
100 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530101 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530102
103 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +0530104 * Default value in string, needs to be converted to the target object,
105 * based on the type.
106 */
107 private String defaultValueInString;
108
109 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530110 * YANG Node in which the leaf is contained.
111 */
112 YangLeavesHolder containedIn;
113
114 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530115 * Creates a YANG leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530116 */
117 public YangLeaf() {
118 }
119
120 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530121 * Returns the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530122 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530123 * @return the leaf name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530124 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530125 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530126 return name;
127 }
128
129 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530130 * Sets the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530131 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530132 * @param leafName the leaf name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530133 */
134 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530135 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530136 }
137
138 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530139 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530140 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530141 * @return if config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530142 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530143 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530144 return isConfig;
145 }
146
147 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530148 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530149 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530150 * @param isCfg the flag value to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530151 */
152 public void setConfig(boolean isCfg) {
153 isConfig = isCfg;
154 }
155
156 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530157 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530158 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530159 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530160 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530161 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530162 public String getDescription() {
163 return description;
164 }
165
166 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530167 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530168 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530169 * @param description set 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 void setDescription(String description) {
173 this.description = description;
174 }
175
176 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530177 * Returns if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530178 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530179 * @return if leaf is mandatory
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530180 */
181 public boolean isMandatory() {
182 return isMandatory;
183 }
184
185 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530186 * Sets if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530187 *
188 * @param isReq if the leaf is mandatory
189 */
190 public void setMandatory(boolean isReq) {
191 isMandatory = isReq;
192 }
193
194 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530195 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530196 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530197 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530198 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530199 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530200 public String getReference() {
201 return reference;
202 }
203
204 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530205 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530206 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530207 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530208 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530209 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530210 public void setReference(String reference) {
211 this.reference = reference;
212 }
213
214 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530215 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530216 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530217 * @return the status
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 YangStatusType getStatus() {
221 return status;
222 }
223
224 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530225 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530226 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 * @param status the status to set
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 setStatus(YangStatusType status) {
231 this.status = status;
232 }
233
234 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530235 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530236 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530237 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530238 */
239 public String getUnits() {
240 return units;
241 }
242
243 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530244 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530246 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530247 */
248 public void setUnits(String units) {
249 this.units = units;
250 }
251
252 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +0530253 * Returns the default value.
254 *
255 * @return the default value
256 */
257 public String getDefaultValueInString() {
258 return defaultValueInString;
259 }
260
261 /**
262 * Sets the default value.
263 *
264 * @param defaultValueInString the default value
265 */
266 public void setDefaultValueInString(String defaultValueInString) {
267 this.defaultValueInString = defaultValueInString;
268 }
269
270 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530271 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530272 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530273 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530274 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530275 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530276 return dataType;
277 }
278
279 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530280 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530281 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530282 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530283 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530284 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530285 this.dataType = dataType;
286 }
287
288 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530289 * Retrieves the YANG node in which the leaf is defined.
290 *
291 * @return the YANG node in which the leaf is defined
292 */
293 public YangLeavesHolder getContainedIn() {
294 return containedIn;
295 }
296
297 /**
298 * Assigns the YANG node in which the leaf is defined.
299 *
300 * @param containedIn the YANG node in which the leaf is defined
301 */
302 public void setContainedIn(YangLeavesHolder containedIn) {
303 this.containedIn = containedIn;
304 }
305
306 @Override
307 public YangLeaf clone()
308 throws CloneNotSupportedException {
309 return (YangLeaf) super.clone();
310 }
311
312 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530313 * Returns the type of the parsed data.
314 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530315 * @return returns LEAF_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530316 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530317 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530318 public YangConstructType getYangConstructType() {
319 return YangConstructType.LEAF_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530320 }
321
322 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530323 * Validates the data on entering 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 validateDataOnEntry()
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
334 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530335 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530336 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530337 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530338 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530339 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530340 public void validateDataOnExit()
341 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530342 // TODO auto-generated method stub, to be implemented by parser
343
344 }
345}