blob: 83091b1c3e2a8c59733360bfee7378448d59c4af [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 */
56/**
Bharat saraswald9822e92016-04-05 15:13:44 +053057 * Represents leaf data represented in YANG.
Vinod Kumar S19f39c72016-02-09 20:12:31 +053058 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053059public class YangLeaf implements YangCommonInfo, Parsable {
Vinod Kumar S19f39c72016-02-09 20:12:31 +053060
61 /**
62 * Name of leaf.
63 */
64 private String name;
65
66 /**
67 * If the leaf is a config parameter.
68 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +053069 private Boolean isConfig;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053070
71 /**
72 * description of leaf.
73 */
74 private String description;
75
76 /**
77 * If mandatory leaf.
78 */
79 private boolean isMandatory;
80
81 /**
82 * The textual reference to this leaf.
83 */
84 private String reference;
85
86 /**
87 * Status of leaf in YANG definition.
88 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053089 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S19f39c72016-02-09 20:12:31 +053090
91 /**
92 * Textual units info.
93 */
94 private String units;
95
96 /**
97 * Data type of the leaf.
98 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053099 private YangType<?> dataType;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530100
101 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530102 * Creates a YANG leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530103 */
104 public YangLeaf() {
105 }
106
107 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530108 * Returns the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530109 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530110 * @return the leaf name
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530111 */
112 public String getLeafName() {
113 return name;
114 }
115
116 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530117 * Sets the name of leaf.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530118 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530119 * @param leafName the leaf name to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530120 */
121 public void setLeafName(String leafName) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 name = leafName;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530123 }
124
125 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530126 * Returns the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530127 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530128 * @return if config flag
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530129 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530130 public Boolean isConfig() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530131 return isConfig;
132 }
133
134 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530135 * Sets the config flag.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530136 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530137 * @param isCfg the flag value to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530138 */
139 public void setConfig(boolean isCfg) {
140 isConfig = isCfg;
141 }
142
143 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530144 * Returns the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530145 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530146 * @return the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530147 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530148 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530149 public String getDescription() {
150 return description;
151 }
152
153 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530154 * Sets the description.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530155 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530156 * @param description set the description
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530157 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530158 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530159 public void setDescription(String description) {
160 this.description = description;
161 }
162
163 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530164 * Returns if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530165 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530166 * @return if leaf is mandatory
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530167 */
168 public boolean isMandatory() {
169 return isMandatory;
170 }
171
172 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530173 * Sets if the leaf is mandatory.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530174 *
175 * @param isReq if the leaf is mandatory
176 */
177 public void setMandatory(boolean isReq) {
178 isMandatory = isReq;
179 }
180
181 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530182 * Returns the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530183 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530184 * @return the reference
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530185 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530186 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530187 public String getReference() {
188 return reference;
189 }
190
191 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530192 * Sets the textual reference.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530193 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530194 * @param reference the reference to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530195 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530196 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530197 public void setReference(String reference) {
198 this.reference = reference;
199 }
200
201 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530202 * Returns the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530203 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530204 * @return the status
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530205 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530206 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530207 public YangStatusType getStatus() {
208 return status;
209 }
210
211 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530212 * Sets the status.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530213 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530214 * @param status the status to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530215 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530216 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530217 public void setStatus(YangStatusType status) {
218 this.status = status;
219 }
220
221 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530222 * Returns the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530223 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530224 * @return the units
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530225 */
226 public String getUnits() {
227 return units;
228 }
229
230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Sets the units.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530232 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530233 * @param units the units to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530234 */
235 public void setUnits(String units) {
236 this.units = units;
237 }
238
239 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530240 * Returns the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530241 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530242 * @return the data type
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530243 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530244 public YangType<?> getDataType() {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530245 return dataType;
246 }
247
248 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530249 * Sets the data type.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530250 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530251 * @param dataType the data type to set
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530252 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530253 public void setDataType(YangType<?> dataType) {
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530254 this.dataType = dataType;
255 }
256
257 /**
258 * Returns the type of the parsed data.
259 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530260 * @return returns LEAF_DATA
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530261 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530262 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530263 public YangConstructType getYangConstructType() {
264 return YangConstructType.LEAF_DATA;
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530265 }
266
267 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530268 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530269 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530270 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530271 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530272 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530273 public void validateDataOnEntry() throws DataModelException {
274 // TODO auto-generated method stub, to be implemented by parser
275
276 }
277
278 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530279 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530280 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530281 * @throws DataModelException a violation of data model rules
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530282 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530283 @Override
Vinod Kumar S19f39c72016-02-09 20:12:31 +0530284 public void validateDataOnExit() throws DataModelException {
285 // TODO auto-generated method stub, to be implemented by parser
286
287 }
288}