Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.yangutils.datamodel; |
| 17 | |
| 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 22 | import org.onosproject.yangutils.parser.Parsable; |
| 23 | import org.onosproject.yangutils.parser.ParsableDataType; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.translator.CachedFileHandle; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 25 | |
| 26 | /*- |
| 27 | * Reference RFC 6020. |
| 28 | * |
| 29 | * The "case" statement is used to define branches of the choice. It takes as an |
| 30 | * argument an identifier, followed by a block of sub-statements that holds |
| 31 | * detailed case information. |
| 32 | * |
| 33 | * The identifier is used to identify the case node in the schema tree. A case |
| 34 | * node does not exist in the data tree. |
| 35 | * |
| 36 | * Within a "case" statement, the "anyxml", "choice", "container", "leaf", |
| 37 | * "list", "leaf-list", and "uses" statements can be used to define child nodes |
| 38 | * to the case node. The identifiers of all these child nodes MUST be unique |
| 39 | * within all cases in a choice. For example, the following is illegal: |
| 40 | * |
| 41 | * choice interface-type { // This example is illegal YANG |
| 42 | * case a { |
| 43 | * leaf ethernet { ... } |
| 44 | * } |
| 45 | * case b { |
| 46 | * container ethernet { ...} |
| 47 | * } |
| 48 | * } |
| 49 | * |
| 50 | * As a shorthand, the "case" statement can be omitted if the branch |
| 51 | * contains a single "anyxml", "container", "leaf", "list", or |
| 52 | * "leaf-list" statement. In this case, the identifier of the case node |
| 53 | * is the same as the identifier in the branch statement. The following |
| 54 | * example: |
| 55 | * |
| 56 | * choice interface-type { |
| 57 | * container ethernet { ... } |
| 58 | * } |
| 59 | * |
| 60 | * is equivalent to: |
| 61 | * |
| 62 | * choice interface-type { |
| 63 | * case ethernet { |
| 64 | * container ethernet { ... } |
| 65 | * } |
| 66 | * } |
| 67 | * |
| 68 | * The case identifier MUST be unique within a choice. |
| 69 | * |
| 70 | * The case's sub-statements |
| 71 | * |
| 72 | * +--------------+---------+-------------+------------------+ |
| 73 | * | substatement | section | cardinality |data model mapping| |
| 74 | * +--------------+---------+-------------+------------------+ |
| 75 | * | anyxml | 7.10 | 0..n |-not supported | |
| 76 | * | choice | 7.9 | 0..n |-child nodes | |
| 77 | * | container | 7.5 | 0..n |-child nodes | |
| 78 | * | description | 7.19.3 | 0..1 |-string | |
| 79 | * | if-feature | 7.18.2 | 0..n |-TODO | |
| 80 | * | leaf | 7.6 | 0..n |-YangLeaf | |
| 81 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
| 82 | * | list | 7.8 | 0..n |-child nodes | |
| 83 | * | reference | 7.19.4 | 0..1 |-string | |
| 84 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 85 | * | uses | 7.12 | 0..n |-child node | |
| 86 | * | when | 7.19.5 | 0..1 |-TODO | |
| 87 | * +--------------+---------+-------------+------------------+ |
| 88 | */ |
| 89 | /** |
| 90 | * Data model node to maintain information defined in YANG case. |
| 91 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 92 | public class YangCase extends YangNode |
| 93 | implements YangLeavesHolder, YangCommonInfo, Parsable { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Case name. |
| 97 | */ |
| 98 | private String name; |
| 99 | |
| 100 | // TODO: default field identification for the case |
| 101 | |
| 102 | /** |
| 103 | * Description of container. |
| 104 | */ |
| 105 | private String description; |
| 106 | |
| 107 | /** |
| 108 | * List of leaves. |
| 109 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 110 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * List of leaf lists. |
| 114 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 115 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Reference of the module. |
| 119 | */ |
| 120 | private String reference; |
| 121 | |
| 122 | /** |
| 123 | * Status of the node. |
| 124 | */ |
| 125 | private YangStatusType status; |
| 126 | |
| 127 | /** |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 128 | * package of the generated java code. |
| 129 | */ |
| 130 | private String pkg; |
| 131 | |
| 132 | /** |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 133 | * Create a choice node. |
| 134 | */ |
| 135 | public YangCase() { |
| 136 | super(YangNodeType.CASE_NODE); |
| 137 | } |
| 138 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 139 | /** |
| 140 | * Get the case name. |
| 141 | * |
| 142 | * @return case name. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 143 | */ |
| 144 | @Override |
| 145 | public String getName() { |
| 146 | return name; |
| 147 | } |
| 148 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 149 | /** |
| 150 | * Set the case name. |
| 151 | * |
| 152 | * @param name case name. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 153 | */ |
| 154 | @Override |
| 155 | public void setName(String name) { |
| 156 | this.name = name; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Get the description. |
| 161 | * |
| 162 | * @return the description. |
| 163 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 164 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 165 | public String getDescription() { |
| 166 | return description; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Set the description. |
| 171 | * |
| 172 | * @param description set the description. |
| 173 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 174 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 175 | public void setDescription(String description) { |
| 176 | this.description = description; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Get the list of leaves. |
| 181 | * |
| 182 | * @return the list of leaves. |
| 183 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 184 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 185 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 186 | return listOfLeaf; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Set the list of leaves. |
| 191 | * |
| 192 | * @param leafsList the list of leaf to set. |
| 193 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 194 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 195 | listOfLeaf = leafsList; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Add a leaf. |
| 200 | * |
| 201 | * @param leaf the leaf to be added. |
| 202 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 203 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 204 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 205 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 206 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | getListOfLeaf().add(leaf); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Get the list of leaf-list. |
| 214 | * |
| 215 | * @return the list of leaf-list. |
| 216 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 217 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 218 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 219 | return listOfLeafList; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Set the list of leaf-list. |
| 224 | * |
| 225 | * @param listOfLeafList the list of leaf-list to set. |
| 226 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 227 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 228 | this.listOfLeafList = listOfLeafList; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Add a leaf-list. |
| 233 | * |
| 234 | * @param leafList the leaf-list to be added. |
| 235 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 236 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 237 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 238 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 239 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | getListOfLeafList().add(leafList); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Get the textual reference. |
| 247 | * |
| 248 | * @return the reference. |
| 249 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 250 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 251 | public String getReference() { |
| 252 | return reference; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Set the textual reference. |
| 257 | * |
| 258 | * @param reference the reference to set. |
| 259 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 260 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 261 | public void setReference(String reference) { |
| 262 | this.reference = reference; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Get the status. |
| 267 | * |
| 268 | * @return the status. |
| 269 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 270 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 271 | public YangStatusType getStatus() { |
| 272 | return status; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Set the status. |
| 277 | * |
| 278 | * @param status the status to set. |
| 279 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 280 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 281 | public void setStatus(YangStatusType status) { |
| 282 | this.status = status; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Returns the type of the data. |
| 287 | * |
| 288 | * @return returns CASE_DATA |
| 289 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 290 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 291 | public ParsableDataType getParsableDataType() { |
| 292 | return ParsableDataType.CASE_DATA; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Validate the data on entering the corresponding parse tree node. |
| 297 | * |
| 298 | * @throws DataModelException a violation of data model rules. |
| 299 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 300 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 301 | public void validateDataOnEntry() throws DataModelException { |
| 302 | // TODO auto-generated method stub, to be implemented by parser |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Validate the data on exiting the corresponding parse tree node. |
| 307 | * |
| 308 | * @throws DataModelException a violation of data model rules. |
| 309 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 310 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 311 | public void validateDataOnExit() throws DataModelException { |
| 312 | // TODO auto-generated method stub, to be implemented by parser |
| 313 | } |
| 314 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 315 | /** |
| 316 | * Get the mapped java package. |
| 317 | * |
| 318 | * @return the java package |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 319 | */ |
| 320 | @Override |
| 321 | public String getPackage() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 322 | return pkg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 323 | } |
| 324 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 325 | /** |
| 326 | * Set the mapped java package. |
| 327 | * |
| 328 | * @param pakg the package to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 329 | */ |
| 330 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 331 | public void setPackage(String pakg) { |
| 332 | pkg = pakg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 333 | |
| 334 | } |
| 335 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 336 | /** |
| 337 | * Generate the code corresponding to YANG case info. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 338 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 339 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 340 | public void generateJavaCodeEntry() { |
| 341 | // TODO Auto-generated method stub |
| 342 | |
| 343 | } |
| 344 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 345 | /** |
| 346 | * Free resource used for generating code and generate valid java files |
| 347 | * corresponding to YANG case info. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 348 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 349 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 350 | public void generateJavaCodeExit() { |
| 351 | // TODO Auto-generated method stub |
| 352 | |
| 353 | } |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 354 | |
| 355 | @Override |
| 356 | public CachedFileHandle getFileHandle() { |
| 357 | // TODO Auto-generated method stub |
| 358 | return null; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void setFileHandle(CachedFileHandle fileHandle) { |
| 363 | // TODO Auto-generated method stub |
| 364 | |
| 365 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 366 | } |