Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
| 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 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 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 56 | |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 57 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 58 | * Represents leaf data represented in YANG. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 59 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 60 | public class YangLeaf |
| 61 | implements YangCommonInfo, Parsable { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Name of leaf. |
| 65 | */ |
| 66 | private String name; |
| 67 | |
| 68 | /** |
| 69 | * If the leaf is a config parameter. |
| 70 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 71 | private Boolean isConfig; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 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 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 91 | private YangStatusType status = YangStatusType.CURRENT; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Textual units info. |
| 95 | */ |
| 96 | private String units; |
| 97 | |
| 98 | /** |
| 99 | * Data type of the leaf. |
| 100 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 101 | private YangType<?> dataType; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 102 | |
| 103 | /** |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 104 | * 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 saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 110 | * Creates a YANG leaf. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 111 | */ |
| 112 | public YangLeaf() { |
| 113 | } |
| 114 | |
| 115 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 116 | * Returns the name of leaf. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 117 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 118 | * @return the leaf name |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 119 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 120 | public String getName() { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 121 | return name; |
| 122 | } |
| 123 | |
| 124 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 125 | * Sets the name of leaf. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 126 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 127 | * @param leafName the leaf name to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 128 | */ |
| 129 | public void setLeafName(String leafName) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 130 | name = leafName; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 134 | * Returns the config flag. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 135 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 136 | * @return if config flag |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 137 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 138 | public Boolean isConfig() { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 139 | return isConfig; |
| 140 | } |
| 141 | |
| 142 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 143 | * Sets the config flag. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 144 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 145 | * @param isCfg the flag value to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 146 | */ |
| 147 | public void setConfig(boolean isCfg) { |
| 148 | isConfig = isCfg; |
| 149 | } |
| 150 | |
| 151 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 152 | * Returns the description. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 153 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 154 | * @return the description |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 155 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 156 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 157 | public String getDescription() { |
| 158 | return description; |
| 159 | } |
| 160 | |
| 161 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 162 | * Sets the description. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 163 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 164 | * @param description set the description |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 165 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 166 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 167 | public void setDescription(String description) { |
| 168 | this.description = description; |
| 169 | } |
| 170 | |
| 171 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 172 | * Returns if the leaf is mandatory. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 173 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 174 | * @return if leaf is mandatory |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 175 | */ |
| 176 | public boolean isMandatory() { |
| 177 | return isMandatory; |
| 178 | } |
| 179 | |
| 180 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 181 | * Sets if the leaf is mandatory. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 182 | * |
| 183 | * @param isReq if the leaf is mandatory |
| 184 | */ |
| 185 | public void setMandatory(boolean isReq) { |
| 186 | isMandatory = isReq; |
| 187 | } |
| 188 | |
| 189 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 190 | * Returns the textual reference. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 191 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 192 | * @return the reference |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 193 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 194 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 195 | public String getReference() { |
| 196 | return reference; |
| 197 | } |
| 198 | |
| 199 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 200 | * Sets the textual reference. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 201 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 202 | * @param reference the reference to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 203 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 204 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 205 | public void setReference(String reference) { |
| 206 | this.reference = reference; |
| 207 | } |
| 208 | |
| 209 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 210 | * Returns the status. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 211 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 212 | * @return the status |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 213 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 214 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 215 | public YangStatusType getStatus() { |
| 216 | return status; |
| 217 | } |
| 218 | |
| 219 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 220 | * Sets the status. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 221 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 222 | * @param status the status to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 223 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 224 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 225 | public void setStatus(YangStatusType status) { |
| 226 | this.status = status; |
| 227 | } |
| 228 | |
| 229 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 230 | * Returns the units. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 231 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 232 | * @return the units |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 233 | */ |
| 234 | public String getUnits() { |
| 235 | return units; |
| 236 | } |
| 237 | |
| 238 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 239 | * Sets the units. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 240 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 241 | * @param units the units to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 242 | */ |
| 243 | public void setUnits(String units) { |
| 244 | this.units = units; |
| 245 | } |
| 246 | |
| 247 | /** |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 248 | * 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 saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 266 | * Returns the data type. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 267 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 268 | * @return the data type |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 269 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 270 | public YangType<?> getDataType() { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 271 | return dataType; |
| 272 | } |
| 273 | |
| 274 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 275 | * Sets the data type. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 276 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 277 | * @param dataType the data type to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 278 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 279 | public void setDataType(YangType<?> dataType) { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 280 | this.dataType = dataType; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Returns the type of the parsed data. |
| 285 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 286 | * @return returns LEAF_DATA |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 287 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 288 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 289 | public YangConstructType getYangConstructType() { |
| 290 | return YangConstructType.LEAF_DATA; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 294 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 295 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 296 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 297 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 298 | @Override |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 299 | public void validateDataOnEntry() |
| 300 | throws DataModelException { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 301 | // TODO auto-generated method stub, to be implemented by parser |
| 302 | |
| 303 | } |
| 304 | |
| 305 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 306 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 307 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 308 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 309 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 310 | @Override |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 311 | public void validateDataOnExit() |
| 312 | throws DataModelException { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 313 | // TODO auto-generated method stub, to be implemented by parser |
| 314 | |
| 315 | } |
| 316 | } |