blob: f59cdcc356a1e9969975b6e866fb594c757e2d46 [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
61 implements YangCommonInfo, Parsable {
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530110 * Creates a YANG leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530111 */
112 public YangLeaf() {
113 }
114
115 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530116 * Returns the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530117 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530118 * @return the leaf name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530119 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530120 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530121 return name;
122 }
123
124 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530125 * Sets the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530126 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530127 * @param leafName the leaf name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530128 */
129 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530130 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530131 }
132
133 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530134 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530135 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530136 * @return if config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530137 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530138 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530139 return isConfig;
140 }
141
142 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530143 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530144 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530145 * @param isCfg the flag value to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530146 */
147 public void setConfig(boolean isCfg) {
148 isConfig = isCfg;
149 }
150
151 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530152 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530153 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530154 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530155 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530156 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530157 public String getDescription() {
158 return description;
159 }
160
161 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530162 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530163 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530164 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530165 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530166 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530167 public void setDescription(String description) {
168 this.description = description;
169 }
170
171 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530172 * Returns if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530173 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530174 * @return if leaf is mandatory
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530175 */
176 public boolean isMandatory() {
177 return isMandatory;
178 }
179
180 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530181 * Sets if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530182 *
183 * @param isReq if the leaf is mandatory
184 */
185 public void setMandatory(boolean isReq) {
186 isMandatory = isReq;
187 }
188
189 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530190 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530191 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530192 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530193 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530194 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530195 public String getReference() {
196 return reference;
197 }
198
199 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530200 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530201 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530202 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530203 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530204 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530205 public void setReference(String reference) {
206 this.reference = reference;
207 }
208
209 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530210 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530211 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530212 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530213 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530214 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530215 public YangStatusType getStatus() {
216 return status;
217 }
218
219 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530220 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530221 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530222 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530223 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530224 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530225 public void setStatus(YangStatusType status) {
226 this.status = status;
227 }
228
229 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530230 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530231 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530232 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530233 */
234 public String getUnits() {
235 return units;
236 }
237
238 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530239 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530242 */
243 public void setUnits(String units) {
244 this.units = units;
245 }
246
247 /**
Vidyashree Rama1db15562016-05-17 16:16:15 +0530248 * Returns the default value.
249 *
250 * @return the default value
251 */
252 public String getDefaultValueInString() {
253 return defaultValueInString;
254 }
255
256 /**
257 * Sets the default value.
258 *
259 * @param defaultValueInString the default value
260 */
261 public void setDefaultValueInString(String defaultValueInString) {
262 this.defaultValueInString = defaultValueInString;
263 }
264
265 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530266 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530267 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530268 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530269 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530270 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530271 return dataType;
272 }
273
274 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530275 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530276 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530277 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530278 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530279 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530280 this.dataType = dataType;
281 }
282
283 /**
284 * Returns the type of the parsed data.
285 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530286 * @return returns LEAF_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530287 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530288 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530289 public YangConstructType getYangConstructType() {
290 return YangConstructType.LEAF_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530291 }
292
293 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530294 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530295 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530296 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530297 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530298 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530299 public void validateDataOnEntry()
300 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530301 // TODO auto-generated method stub, to be implemented by parser
302
303 }
304
305 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530306 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530307 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530308 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530309 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530310 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530311 public void validateDataOnExit()
312 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530313 // TODO auto-generated method stub, to be implemented by parser
314
315 }
316}