blob: 888094e9b73158b4e3e928a1aef25b21f9ce7b31 [file] [log] [blame]
Vinod Kumar S19f39c72016-02-09 20:12:31 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
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;
21import org.onosproject.yangutils.parser.ParsableDataType;
22
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 */
56/**
57 * Leaf data represented in YANG.
58 *
Vinod Kumar S19f39c72016-02-09 20:12:31 +053059 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053060public class YangLeaf implements YangCommonInfo, Parsable {
Vinod Kumar S19f39c72016-02-09 20:12:31 +053061
62 /**
63 * Name of leaf.
64 */
65 private String name;
66
67 /**
68 * If the leaf is a config parameter.
69 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053070 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053071
72 /**
73 * description of leaf.
74 */
75 private String description;
76
77 /**
78 * If mandatory leaf.
79 */
80 private boolean isMandatory;
81
82 /**
83 * The textual reference to this leaf.
84 */
85 private String reference;
86
87 /**
88 * Status of leaf in YANG definition.
89 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053090 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053091
92 /**
93 * Textual units info.
94 */
95 private String units;
96
97 /**
98 * Data type of the leaf.
99 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530100 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530101
102 /**
103 * Default constructor to create a YANG leaf.
104 */
105 public YangLeaf() {
106 }
107
108 /**
109 * Get the name of leaf.
110 *
111 * @return the leaf name.
112 */
113 public String getLeafName() {
114 return name;
115 }
116
117 /**
118 * Set the name of leaf.
119 *
120 * @param leafName the leaf name to set.
121 */
122 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530124 }
125
126 /**
127 * Get the config flag.
128 *
129 * @return if config flag.
130 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530131 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530132 return isConfig;
133 }
134
135 /**
136 * Set the config flag.
137 *
138 * @param isCfg the flag value to set.
139 */
140 public void setConfig(boolean isCfg) {
141 isConfig = isCfg;
142 }
143
144 /**
145 * Get the description.
146 *
147 * @return the description.
148 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530149 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530150 public String getDescription() {
151 return description;
152 }
153
154 /**
155 * Set the description.
156 *
157 * @param description set the description.
158 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530159 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530160 public void setDescription(String description) {
161 this.description = description;
162 }
163
164 /**
165 * Get if the leaf is mandatory.
166 *
167 * @return if leaf is mandatory.
168 */
169 public boolean isMandatory() {
170 return isMandatory;
171 }
172
173 /**
174 * Set if the leaf is mandatory.
175 *
176 * @param isReq if the leaf is mandatory
177 */
178 public void setMandatory(boolean isReq) {
179 isMandatory = isReq;
180 }
181
182 /**
183 * Get the textual reference.
184 *
185 * @return the reference.
186 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530187 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530188 public String getReference() {
189 return reference;
190 }
191
192 /**
193 * Set the textual reference.
194 *
195 * @param reference the reference to set.
196 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530197 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530198 public void setReference(String reference) {
199 this.reference = reference;
200 }
201
202 /**
203 * Get the status.
204 *
205 * @return the status.
206 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530207 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530208 public YangStatusType getStatus() {
209 return status;
210 }
211
212 /**
213 * Set the status.
214 *
215 * @param status the status to set.
216 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530217 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530218 public void setStatus(YangStatusType status) {
219 this.status = status;
220 }
221
222 /**
223 * Get the units.
224 *
225 * @return the units.
226 */
227 public String getUnits() {
228 return units;
229 }
230
231 /**
232 * Set the units.
233 *
234 * @param units the units to set.
235 */
236 public void setUnits(String units) {
237 this.units = units;
238 }
239
240 /**
241 * Get the data type.
242 *
243 * @return the data type.
244 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530245 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530246 return dataType;
247 }
248
249 /**
250 * Set the data type.
251 *
252 * @param dataType the data type to set.
253 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530254 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530255 this.dataType = dataType;
256 }
257
258 /**
259 * Returns the type of the parsed data.
260 *
261 * @return returns LEAF_DATA.
262 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530263 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530264 public ParsableDataType getParsableDataType() {
265 return ParsableDataType.LEAF_DATA;
266 }
267
268 /**
269 * Validate the data on entering the corresponding parse tree node.
270 *
271 * @throws DataModelException a violation of data model rules.
272 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530273 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530274 public void validateDataOnEntry() throws DataModelException {
275 // TODO auto-generated method stub, to be implemented by parser
276
277 }
278
279 /**
280 * Validate the data on exiting the corresponding parse tree node.
281 *
282 * @throws DataModelException a violation of data model rules.
283 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530284 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530285 public void validateDataOnExit() throws DataModelException {
286 // TODO auto-generated method stub, to be implemented by parser
287
288 }
289}