blob: c9808a21dfc8d2d49fa19f2aba5fb5e0a6d7af1d [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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530104 * Creates a YANG leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530105 */
106 public YangLeaf() {
107 }
108
109 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530110 * Returns the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530111 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530112 * @return the leaf name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530113 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530114 public String getName() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530115 return name;
116 }
117
118 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530119 * Sets the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530120 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530121 * @param leafName the leaf name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530122 */
123 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530125 }
126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530129 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530130 * @return if config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530131 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530132 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530133 return isConfig;
134 }
135
136 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530137 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530138 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530139 * @param isCfg the flag value to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530140 */
141 public void setConfig(boolean isCfg) {
142 isConfig = isCfg;
143 }
144
145 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530146 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530147 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530148 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530149 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530150 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530151 public String getDescription() {
152 return description;
153 }
154
155 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530156 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530159 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530160 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530161 public void setDescription(String description) {
162 this.description = description;
163 }
164
165 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530166 * Returns if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530167 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530168 * @return if leaf is mandatory
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530169 */
170 public boolean isMandatory() {
171 return isMandatory;
172 }
173
174 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530175 * Sets if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530176 *
177 * @param isReq if the leaf is mandatory
178 */
179 public void setMandatory(boolean isReq) {
180 isMandatory = isReq;
181 }
182
183 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530184 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530185 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530186 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530187 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530188 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530189 public String getReference() {
190 return reference;
191 }
192
193 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530194 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530195 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530196 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530197 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530198 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530199 public void setReference(String reference) {
200 this.reference = reference;
201 }
202
203 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530204 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530205 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530206 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530207 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530208 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530209 public YangStatusType getStatus() {
210 return status;
211 }
212
213 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530214 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530215 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530216 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530217 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530218 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530219 public void setStatus(YangStatusType status) {
220 this.status = status;
221 }
222
223 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530224 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530225 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530226 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530227 */
228 public String getUnits() {
229 return units;
230 }
231
232 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530233 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530234 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530235 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530236 */
237 public void setUnits(String units) {
238 this.units = units;
239 }
240
241 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530242 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530243 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530244 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530246 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530247 return dataType;
248 }
249
250 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530251 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530252 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530253 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530254 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530255 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530256 this.dataType = dataType;
257 }
258
259 /**
260 * Returns the type of the parsed data.
261 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530262 * @return returns LEAF_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530263 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530264 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530265 public YangConstructType getYangConstructType() {
266 return YangConstructType.LEAF_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530267 }
268
269 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530270 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530271 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530272 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530273 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530274 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530275 public void validateDataOnEntry()
276 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530277 // TODO auto-generated method stub, to be implemented by parser
278
279 }
280
281 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530282 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530283 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530284 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530285 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530286 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530287 public void validateDataOnExit()
288 throws DataModelException {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530289 // TODO auto-generated method stub, to be implemented by parser
290
291 }
292}