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 | */ |
| 56 | /** |
| 57 | * Leaf data represented in YANG. |
| 58 | * |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 59 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 60 | public class YangLeaf implements YangCommonInfo, Parsable { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Name of leaf. |
| 64 | */ |
| 65 | private String name; |
| 66 | |
| 67 | /** |
| 68 | * If the leaf is a config parameter. |
| 69 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 70 | private Boolean isConfig; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 71 | |
| 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 S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 90 | private YangStatusType status = YangStatusType.CURRENT; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Textual units info. |
| 94 | */ |
| 95 | private String units; |
| 96 | |
| 97 | /** |
| 98 | * Data type of the leaf. |
| 99 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 100 | private YangType<?> dataType; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Default constructor to create a YANG leaf. |
| 104 | */ |
| 105 | public YangLeaf() { |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the name of leaf. |
| 110 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 111 | * @return the leaf name |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 112 | */ |
| 113 | public String getLeafName() { |
| 114 | return name; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Set the name of leaf. |
| 119 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 120 | * @param leafName the leaf name to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 121 | */ |
| 122 | public void setLeafName(String leafName) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 123 | name = leafName; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Get the config flag. |
| 128 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 129 | * @return if config flag |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 130 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 131 | public Boolean isConfig() { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 132 | return isConfig; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Set the config flag. |
| 137 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 138 | * @param isCfg the flag value to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 139 | */ |
| 140 | public void setConfig(boolean isCfg) { |
| 141 | isConfig = isCfg; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Get the description. |
| 146 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 147 | * @return the description |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 148 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 149 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 150 | public String getDescription() { |
| 151 | return description; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Set the description. |
| 156 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 157 | * @param description set the description |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 158 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 159 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 160 | public void setDescription(String description) { |
| 161 | this.description = description; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Get if the leaf is mandatory. |
| 166 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 167 | * @return if leaf is mandatory |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 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 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 185 | * @return the reference |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 186 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 187 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 188 | public String getReference() { |
| 189 | return reference; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Set the textual reference. |
| 194 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 195 | * @param reference the reference to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 196 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 197 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 198 | public void setReference(String reference) { |
| 199 | this.reference = reference; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Get the status. |
| 204 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 205 | * @return the status |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 206 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 207 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 208 | public YangStatusType getStatus() { |
| 209 | return status; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Set the status. |
| 214 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 215 | * @param status the status to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 216 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 217 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 218 | public void setStatus(YangStatusType status) { |
| 219 | this.status = status; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Get the units. |
| 224 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 225 | * @return the units |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 226 | */ |
| 227 | public String getUnits() { |
| 228 | return units; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Set the units. |
| 233 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 234 | * @param units the units to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 235 | */ |
| 236 | public void setUnits(String units) { |
| 237 | this.units = units; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Get the data type. |
| 242 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 243 | * @return the data type |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 244 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 245 | public YangType<?> getDataType() { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 246 | return dataType; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Set the data type. |
| 251 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 252 | * @param dataType the data type to set |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 253 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 254 | public void setDataType(YangType<?> dataType) { |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 255 | this.dataType = dataType; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Returns the type of the parsed data. |
| 260 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 261 | * @return returns LEAF_DATA |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 262 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 263 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 264 | public YangConstructType getYangConstructType() { |
| 265 | return YangConstructType.LEAF_DATA; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Validate the data on entering the corresponding parse tree node. |
| 270 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 271 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 272 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 273 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 274 | 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 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 282 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 283 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 284 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 285 | public void validateDataOnExit() throws DataModelException { |
| 286 | // TODO auto-generated method stub, to be implemented by parser |
| 287 | |
| 288 | } |
| 289 | } |