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; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 21 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 23 | |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 24 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 25 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 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 |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 80 | implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { |
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 | /** |
| 113 | * Creates the grouping node. |
| 114 | */ |
| 115 | public YangGrouping() { |
| 116 | super(YangNodeType.GROUPING_NODE); |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 117 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 118 | listOfLeafList = new LinkedList<YangLeafList>(); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 119 | } |
| 120 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 121 | /** |
| 122 | * Get YANG grouping name. |
| 123 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 124 | * @return YANG grouping name |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 125 | */ |
| 126 | @Override |
| 127 | public String getName() { |
| 128 | return name; |
| 129 | } |
| 130 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 131 | /** |
| 132 | * Set YANG grouping name. |
| 133 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 134 | * @param name YANG grouping name |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 135 | */ |
| 136 | @Override |
| 137 | public void setName(String name) { |
| 138 | this.name = name; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get the description. |
| 143 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 144 | * @return the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 145 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 146 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 147 | public String getDescription() { |
| 148 | return description; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Set the description. |
| 153 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 154 | * @param description set the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 155 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 156 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 157 | public void setDescription(String description) { |
| 158 | this.description = description; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Get the list of leaves. |
| 163 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 164 | * @return the list of leaves |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 165 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 166 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 167 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 168 | return listOfLeaf; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Set the list of leaves. |
| 173 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 174 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 175 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 176 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 177 | listOfLeaf = leafsList; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Add a leaf. |
| 182 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 183 | * @param leaf the leaf to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 184 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 185 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 186 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 187 | getListOfLeaf().add(leaf); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Get the list of leaf-list. |
| 192 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 193 | * @return the list of leaf-list |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 194 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 195 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 196 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 197 | return listOfLeafList; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Set the list of leaf-list. |
| 202 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 203 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 204 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 205 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 206 | this.listOfLeafList = listOfLeafList; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Add a leaf-list. |
| 211 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 212 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 213 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 214 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 215 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 216 | getListOfLeafList().add(leafList); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get the textual reference. |
| 221 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 222 | * @return the reference |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 223 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 224 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 225 | public String getReference() { |
| 226 | return reference; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Set the textual reference. |
| 231 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 232 | * @param reference the reference to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 233 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 234 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 235 | public void setReference(String reference) { |
| 236 | this.reference = reference; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Get the status. |
| 241 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 242 | * @return the status |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 243 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 244 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 245 | public YangStatusType getStatus() { |
| 246 | return status; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Set the status. |
| 251 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 252 | * @param status the status to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 253 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 254 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 255 | public void setStatus(YangStatusType status) { |
| 256 | this.status = status; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Returns the type of the data. |
| 261 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 262 | * @return returns GROUPING_DATA |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 263 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 264 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 265 | public YangConstructType getYangConstructType() { |
| 266 | return YangConstructType.GROUPING_DATA; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Validate the data on entering the corresponding parse tree node. |
| 271 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 272 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 273 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 274 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 275 | public void validateDataOnEntry() throws DataModelException { |
| 276 | // TODO auto-generated method stub, to be implemented by parser |
| 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 | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 283 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 284 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 285 | public void validateDataOnExit() throws DataModelException { |
| 286 | // TODO auto-generated method stub, to be implemented by parser |
| 287 | } |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 288 | |
| 289 | /* |
| 290 | * Reference RFC6020 |
| 291 | * |
| 292 | * Once a grouping is defined, it can be referenced in a "uses" |
| 293 | * statement (see Section 7.12). A grouping MUST NOT reference itself, |
| 294 | * neither directly nor indirectly through a chain of other groupings. |
| 295 | * |
| 296 | * If the grouping is defined at the top level of a YANG module or |
| 297 | * submodule, the grouping's identifier MUST be unique within the |
| 298 | * module. |
| 299 | */ |
| 300 | @Override |
| 301 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 302 | |
| 303 | // Asks helper to detect colliding child. |
| 304 | detectCollidingChildUtil(identifierName, dataType, this); |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
| 309 | if (getName().equals(identifierName)) { |
| 310 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" + |
| 311 | getName() + "\""); |
| 312 | } |
| 313 | } |
| 314 | // TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 315 | } |