blob: 0391518d9a76db565eb9fb5ce0f5fc2713329e21 [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 * The "leaf" statement is used to define a leaf node in the schema
28 * tree. It takes one argument, which is an identifier, followed by a
29 * block of sub-statements that holds detailed leaf information.
30 *
31 * A leaf node has a value, but no child nodes in the data tree.
32 * Conceptually, the value in the data tree is always in the canonical
33 * form.
34 *
35 * A leaf node exists in zero or one instances in the data tree.
36 *
37 * The "leaf" statement is used to define a scalar variable of a
38 * particular built-in or derived type.
39 *
40 * The leaf's sub-statements
41 *
42 * +--------------+---------+-------------+------------------+
43 * | substatement | section | cardinality |data model mapping|
44 * +--------------+---------+-------------+------------------+
45 * | config | 7.19.1 | 0..1 | - boolean |
46 * | default | 7.6.4 | 0..1 | - TODO |
47 * | description | 7.19.3 | 0..1 | - string |
48 * | if-feature | 7.18.2 | 0..n | - TODO |
49 * | mandatory | 7.6.5 | 0..1 | - boolean |
50 * | must | 7.5.3 | 0..n | - TODO |
51 * | reference | 7.19.4 | 0..1 | - string |
52 * | status | 7.19.2 | 0..1 | - YangStatus |
53 * | type | 7.6.3 | 1 | - YangType |
54 * | units | 7.3.3 | 0..1 | - String |
55 * | when | 7.19.5 | 0..1 | - TODO |
56 * +--------------+---------+-------------+------------------+
57 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053058
Vinod Kumar S19f39c72016-02-09 20:12:31 +053059/**
Bharat saraswald9822e92016-04-05 15:13:44 +053060 * Represents leaf data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053061 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053062public class YangLeaf
Bharat saraswal96dfef02016-06-16 00:29:12 +053063 implements YangCommonInfo, Parsable, Cloneable, Serializable {
64
65 private static final long serialVersionUID = 806201635L;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053066
67 /**
68 * Name of leaf.
69 */
70 private String name;
71
72 /**
73 * If the leaf is a config parameter.
74 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053075 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053076
77 /**
78 * description of leaf.
79 */
80 private String description;
81
82 /**
83 * If mandatory leaf.
84 */
85 private boolean isMandatory;
86
87 /**
88 * The textual reference to this leaf.
89 */
90 private String reference;
91
92 /**
93 * Status of leaf in YANG definition.
94 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053095 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053096
97 /**
98 * Textual units info.
99 */
100 private String units;
101
102 /**
103 * Data type of the leaf.
104 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530105 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530106
107 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +0530108 * Default value in string, needs to be converted to the target object,
109 * based on the type.
110 */
111 private String defaultValueInString;
112
113 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530114 * YANG Node in which the leaf is contained.
115 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530116 private transient YangLeavesHolder containedIn;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530117
118 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530119 * Creates a YANG leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530120 */
121 public YangLeaf() {
122 }
123
124 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530125 * Returns the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530126 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530127 * @return the leaf name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530128 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530129 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530130 return name;
131 }
132
133 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530134 * Sets the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530135 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530136 * @param leafName the leaf name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530137 */
138 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530139 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530140 }
141
142 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530143 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530144 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530145 * @return if config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530146 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530147 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530148 return isConfig;
149 }
150
151 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530152 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530153 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530154 * @param isCfg the flag value to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530155 */
156 public void setConfig(boolean isCfg) {
157 isConfig = isCfg;
158 }
159
160 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530161 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530162 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530163 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530164 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530165 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530166 public String getDescription() {
167 return description;
168 }
169
170 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530171 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530172 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530173 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530174 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530175 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530176 public void setDescription(String description) {
177 this.description = description;
178 }
179
180 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530181 * Returns if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530183 * @return if leaf is mandatory
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530184 */
185 public boolean isMandatory() {
186 return isMandatory;
187 }
188
189 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530190 * Sets if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530191 *
192 * @param isReq if the leaf is mandatory
193 */
194 public void setMandatory(boolean isReq) {
195 isMandatory = isReq;
196 }
197
198 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530199 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530200 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530201 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530202 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530203 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530204 public String getReference() {
205 return reference;
206 }
207
208 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530209 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530210 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530211 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530212 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530213 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530214 public void setReference(String reference) {
215 this.reference = reference;
216 }
217
218 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530219 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530220 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530221 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530222 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530223 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530224 public YangStatusType getStatus() {
225 return status;
226 }
227
228 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530229 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530230 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530231 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530232 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530233 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530234 public void setStatus(YangStatusType status) {
235 this.status = status;
236 }
237
238 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530239 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530242 */
243 public String getUnits() {
244 return units;
245 }
246
247 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530248 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530249 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530250 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530251 */
252 public void setUnits(String units) {
253 this.units = units;
254 }
255
256 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +0530257 * Returns the default value.
258 *
259 * @return the default value
260 */
261 public String getDefaultValueInString() {
262 return defaultValueInString;
263 }
264
265 /**
266 * Sets the default value.
267 *
268 * @param defaultValueInString the default value
269 */
270 public void setDefaultValueInString(String defaultValueInString) {
271 this.defaultValueInString = defaultValueInString;
272 }
273
274 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530275 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530276 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530277 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530278 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530279 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530280 return dataType;
281 }
282
283 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530284 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530285 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530286 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530287 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530288 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530289 this.dataType = dataType;
290 }
291
292 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530293 * Retrieves the YANG node in which the leaf is defined.
294 *
295 * @return the YANG node in which the leaf is defined
296 */
297 public YangLeavesHolder getContainedIn() {
298 return containedIn;
299 }
300
301 /**
302 * Assigns the YANG node in which the leaf is defined.
303 *
304 * @param containedIn the YANG node in which the leaf is defined
305 */
306 public void setContainedIn(YangLeavesHolder containedIn) {
307 this.containedIn = containedIn;
308 }
309
310 @Override
311 public YangLeaf clone()
312 throws CloneNotSupportedException {
313 return (YangLeaf) super.clone();
314 }
315
316 /**
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530317 * Returns the type of the parsed data.
318 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530319 * @return returns LEAF_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530320 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530321 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530322 public YangConstructType getYangConstructType() {
323 return YangConstructType.LEAF_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530324 }
325
326 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530327 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530328 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530329 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530330 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530331 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530332 public void validateDataOnEntry()
333 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530334 // TODO auto-generated method stub, to be implemented by parser
335
336 }
337
338 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530339 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530340 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530341 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530342 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530343 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530344 public void validateDataOnExit()
345 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530346 // TODO auto-generated method stub, to be implemented by parser
347
348 }
349}