blob: d2837da90fdfc8e6344516567033a4ca591b4b06 [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 *
59 * @param <T> YANG data type
60 */
61public class YangLeaf<T> implements YangCommonInfo, Parsable {
62
63 /**
64 * Name of leaf.
65 */
66 private String name;
67
68 /**
69 * If the leaf is a config parameter.
70 */
71 private boolean isConfig;
72
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 */
91 private YangStatusType status;
92
93 /**
94 * Textual units info.
95 */
96 private String units;
97
98 /**
99 * Data type of the leaf.
100 */
101 private YangType<T> dataType;
102
103 /**
104 * Default constructor to create a YANG leaf.
105 */
106 public YangLeaf() {
107 }
108
109 /**
110 * Get the name of leaf.
111 *
112 * @return the leaf name.
113 */
114 public String getLeafName() {
115 return name;
116 }
117
118 /**
119 * Set the name of leaf.
120 *
121 * @param leafName the leaf name to set.
122 */
123 public void setLeafName(String leafName) {
124 this.name = leafName;
125 }
126
127 /**
128 * Get the config flag.
129 *
130 * @return if config flag.
131 */
132 public boolean isConfig() {
133 return isConfig;
134 }
135
136 /**
137 * Set the config flag.
138 *
139 * @param isCfg the flag value to set.
140 */
141 public void setConfig(boolean isCfg) {
142 isConfig = isCfg;
143 }
144
145 /**
146 * Get the description.
147 *
148 * @return the description.
149 */
150 public String getDescription() {
151 return description;
152 }
153
154 /**
155 * Set the description.
156 *
157 * @param description set the description.
158 */
159 public void setDescription(String description) {
160 this.description = description;
161 }
162
163 /**
164 * Get if the leaf is mandatory.
165 *
166 * @return if leaf is mandatory.
167 */
168 public boolean isMandatory() {
169 return isMandatory;
170 }
171
172 /**
173 * Set if the leaf is mandatory.
174 *
175 * @param isReq if the leaf is mandatory
176 */
177 public void setMandatory(boolean isReq) {
178 isMandatory = isReq;
179 }
180
181 /**
182 * Get the textual reference.
183 *
184 * @return the reference.
185 */
186 public String getReference() {
187 return reference;
188 }
189
190 /**
191 * Set the textual reference.
192 *
193 * @param reference the reference to set.
194 */
195 public void setReference(String reference) {
196 this.reference = reference;
197 }
198
199 /**
200 * Get the status.
201 *
202 * @return the status.
203 */
204 public YangStatusType getStatus() {
205 return status;
206 }
207
208 /**
209 * Set the status.
210 *
211 * @param status the status to set.
212 */
213 public void setStatus(YangStatusType status) {
214 this.status = status;
215 }
216
217 /**
218 * Get the units.
219 *
220 * @return the units.
221 */
222 public String getUnits() {
223 return units;
224 }
225
226 /**
227 * Set the units.
228 *
229 * @param units the units to set.
230 */
231 public void setUnits(String units) {
232 this.units = units;
233 }
234
235 /**
236 * Get the data type.
237 *
238 * @return the data type.
239 */
240 public YangType<T> getDataType() {
241 return dataType;
242 }
243
244 /**
245 * Set the data type.
246 *
247 * @param dataType the data type to set.
248 */
249 public void setDataType(YangType<T> dataType) {
250 this.dataType = dataType;
251 }
252
253 /**
254 * Returns the type of the parsed data.
255 *
256 * @return returns LEAF_DATA.
257 */
258 public ParsableDataType getParsableDataType() {
259 return ParsableDataType.LEAF_DATA;
260 }
261
262 /**
263 * Validate the data on entering the corresponding parse tree node.
264 *
265 * @throws DataModelException a violation of data model rules.
266 */
267 public void validateDataOnEntry() throws DataModelException {
268 // TODO auto-generated method stub, to be implemented by parser
269
270 }
271
272 /**
273 * Validate the data on exiting the corresponding parse tree node.
274 *
275 * @throws DataModelException a violation of data model rules.
276 */
277 public void validateDataOnExit() throws DataModelException {
278 // TODO auto-generated method stub, to be implemented by parser
279
280 }
281}