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; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.utils.YangConstructType; |
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 "grouping" statement is used to define a reusable block of nodes, |
| 30 | * which may be used locally in the module, in modules that include it, |
| 31 | * and by other modules that import from it. It takes one argument, |
| 32 | * which is an identifier, followed by a block of sub-statements that |
| 33 | * holds detailed grouping information. |
| 34 | * |
| 35 | * The "grouping" statement is not a data definition statement and, as |
| 36 | * such, does not define any nodes in the schema tree. |
| 37 | * |
| 38 | * A grouping is like a "structure" or a "record" in conventional |
| 39 | * programming languages. |
| 40 | * Once a grouping is defined, it can be referenced in a "uses" |
| 41 | * statement. A grouping MUST NOT reference itself, |
| 42 | * neither directly nor indirectly through a chain of other groupings. |
| 43 | * |
| 44 | * If the grouping is defined at the top level of a YANG module or |
| 45 | * submodule, the grouping's identifier MUST be unique within the |
| 46 | * module. |
| 47 | * |
| 48 | * A grouping is more than just a mechanism for textual substitution, |
| 49 | * but defines a collection of nodes. Identifiers appearing inside the |
| 50 | * grouping are resolved relative to the scope in which the grouping is |
| 51 | * defined, not where it is used. Prefix mappings, type names, grouping |
| 52 | * names, and extension usage are evaluated in the hierarchy where the |
| 53 | * "grouping" statement appears. For extensions, this means that |
| 54 | * extensions are applied to the grouping node, not the uses node. |
| 55 | * |
| 56 | * The grouping's sub-statements |
| 57 | * |
| 58 | * +--------------+---------+-------------+------------------+ |
| 59 | * | substatement | section | cardinality |data model mapping| |
| 60 | * +--------------+---------+-------------+------------------+ |
| 61 | * | anyxml | 7.10 | 0..n |-not supported | |
| 62 | * | choice | 7.9 | 0..n |-child nodes | |
| 63 | * | container | 7.5 | 0..n |-child nodes | |
| 64 | * | description | 7.19.3 | 0..1 |-string | |
| 65 | * | grouping | 7.11 | 0..n |-child nodes | |
| 66 | * | leaf | 7.6 | 0..n |-YangLeaf | |
| 67 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
| 68 | * | list | 7.8 | 0..n |-child nodes | |
| 69 | * | reference | 7.19.4 | 0..1 |-string | |
| 70 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 71 | * | typedef | 7.3 | 0..n |-child nodes | |
| 72 | * | uses | 7.12 | 0..n |-child nodes | |
| 73 | * +--------------+---------+-------------+------------------+ |
| 74 | */ |
| 75 | |
| 76 | /** |
| 77 | * Data model node to maintain information defined in YANG grouping. |
| 78 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 79 | public class YangGrouping extends YangNode |
| 80 | implements YangLeavesHolder, YangCommonInfo, Parsable { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Name of the grouping. |
| 84 | */ |
| 85 | private String name; |
| 86 | |
| 87 | /** |
| 88 | * Description. |
| 89 | */ |
| 90 | private String description; |
| 91 | |
| 92 | /** |
| 93 | * List of leaves. |
| 94 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 95 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * List of leaf lists. |
| 99 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 100 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Reference of the module. |
| 104 | */ |
| 105 | private String reference; |
| 106 | |
| 107 | /** |
| 108 | * Status of the node. |
| 109 | */ |
| 110 | private YangStatusType status; |
| 111 | |
| 112 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 113 | * Package of the generated java code. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 114 | */ |
| 115 | private String pkg; |
| 116 | |
| 117 | /** |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 118 | * Creates the grouping node. |
| 119 | */ |
| 120 | public YangGrouping() { |
| 121 | super(YangNodeType.GROUPING_NODE); |
| 122 | } |
| 123 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 124 | /** |
| 125 | * Get YANG grouping name. |
| 126 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 127 | * @return YANG grouping name |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 128 | */ |
| 129 | @Override |
| 130 | public String getName() { |
| 131 | return name; |
| 132 | } |
| 133 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 134 | /** |
| 135 | * Set YANG grouping name. |
| 136 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 137 | * @param name YANG grouping name |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 138 | */ |
| 139 | @Override |
| 140 | public void setName(String name) { |
| 141 | this.name = name; |
| 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 | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 148 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 149 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +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 | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 158 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 159 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 160 | public void setDescription(String description) { |
| 161 | this.description = description; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Get the list of leaves. |
| 166 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 167 | * @return the list of leaves |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 168 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 169 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 170 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 171 | return listOfLeaf; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Set the list of leaves. |
| 176 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 177 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 178 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 179 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 180 | listOfLeaf = leafsList; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Add a leaf. |
| 185 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 186 | * @param leaf the leaf to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 187 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 188 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 189 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 190 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 191 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | getListOfLeaf().add(leaf); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Get the list of leaf-list. |
| 199 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 200 | * @return the list of leaf-list |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 201 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 202 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 203 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 204 | return listOfLeafList; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Set the list of leaf-list. |
| 209 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 210 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 211 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 212 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 213 | this.listOfLeafList = listOfLeafList; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Add a leaf-list. |
| 218 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 219 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 220 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 221 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 222 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 223 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 224 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | getListOfLeafList().add(leafList); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Get the textual reference. |
| 232 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 233 | * @return the reference |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 234 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 235 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 236 | public String getReference() { |
| 237 | return reference; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Set the textual reference. |
| 242 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 243 | * @param reference the reference to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 244 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 245 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 246 | public void setReference(String reference) { |
| 247 | this.reference = reference; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Get the status. |
| 252 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 253 | * @return the status |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 254 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 255 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 256 | public YangStatusType getStatus() { |
| 257 | return status; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Set the status. |
| 262 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 263 | * @param status the status to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 264 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 265 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 266 | public void setStatus(YangStatusType status) { |
| 267 | this.status = status; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Returns the type of the data. |
| 272 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 273 | * @return returns GROUPING_DATA |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 274 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 275 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 276 | public YangConstructType getYangConstructType() { |
| 277 | return YangConstructType.GROUPING_DATA; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Validate the data on entering the corresponding parse tree node. |
| 282 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 283 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 284 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 285 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 286 | public void validateDataOnEntry() throws DataModelException { |
| 287 | // TODO auto-generated method stub, to be implemented by parser |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Validate the data on exiting the corresponding parse tree node. |
| 292 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 293 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 294 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 295 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 296 | public void validateDataOnExit() throws DataModelException { |
| 297 | // TODO auto-generated method stub, to be implemented by parser |
| 298 | } |
| 299 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 300 | /** |
| 301 | * Generate the code for YANG grouping. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 302 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 303 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 304 | public void generateJavaCodeEntry() { |
| 305 | // TODO Auto-generated method stub |
| 306 | |
| 307 | } |
| 308 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 309 | /** |
| 310 | * Free the resources used to generate java files corresponding to YANG |
| 311 | * grouping info and generate valid java files. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 312 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 313 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 314 | public void generateJavaCodeExit() { |
| 315 | // TODO Auto-generated method stub |
| 316 | |
| 317 | } |
| 318 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 319 | /** |
| 320 | * Get the mapped java package. |
| 321 | * |
| 322 | * @return the java package |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 323 | */ |
| 324 | @Override |
| 325 | public String getPackage() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 326 | return pkg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 327 | } |
| 328 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 329 | /** |
| 330 | * Set the mapped java package. |
| 331 | * |
| 332 | * @param pakg the package to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 333 | */ |
| 334 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 335 | public void setPackage(String pakg) { |
| 336 | pkg = pakg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 337 | |
| 338 | } |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 339 | |
| 340 | @Override |
| 341 | public CachedFileHandle getFileHandle() { |
| 342 | // TODO Auto-generated method stub |
| 343 | return null; |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public void setFileHandle(CachedFileHandle fileHandle) { |
| 348 | // TODO Auto-generated method stub |
| 349 | |
| 350 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 351 | } |