blob: 68f75879a8433d4598bfc5b3e843310a6c2c6c68 [file] [log] [blame]
Vinod Kumar S5a39e012016-02-16 01:37:16 +05301/*
Brian O'Connor0f7908b2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S5a39e012016-02-16 01:37:16 +05303 *
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 */
16package org.onosproject.yangutils.datamodel;
17
18import java.util.LinkedList;
19import java.util.List;
Bharat saraswal63f26fb2016-04-05 15:13:44 +053020
Vinod Kumar S5a39e012016-02-16 01:37:16 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +053023import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S5a39e012016-02-16 01:37:16 +053024
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +053025import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26
Vinod Kumar S5a39e012016-02-16 01:37:16 +053027/*-
28 * Reference RFC 6020.
29 *
30 * The "grouping" statement is used to define a reusable block of nodes,
31 * which may be used locally in the module, in modules that include it,
32 * and by other modules that import from it. It takes one argument,
33 * which is an identifier, followed by a block of sub-statements that
34 * holds detailed grouping information.
35 *
36 * The "grouping" statement is not a data definition statement and, as
37 * such, does not define any nodes in the schema tree.
38 *
39 * A grouping is like a "structure" or a "record" in conventional
40 * programming languages.
41 * Once a grouping is defined, it can be referenced in a "uses"
42 * statement. A grouping MUST NOT reference itself,
43 * neither directly nor indirectly through a chain of other groupings.
44 *
45 * If the grouping is defined at the top level of a YANG module or
46 * submodule, the grouping's identifier MUST be unique within the
47 * module.
48 *
49 * A grouping is more than just a mechanism for textual substitution,
50 * but defines a collection of nodes. Identifiers appearing inside the
51 * grouping are resolved relative to the scope in which the grouping is
52 * defined, not where it is used. Prefix mappings, type names, grouping
53 * names, and extension usage are evaluated in the hierarchy where the
54 * "grouping" statement appears. For extensions, this means that
55 * extensions are applied to the grouping node, not the uses node.
56 *
57 * The grouping's sub-statements
58 *
59 * +--------------+---------+-------------+------------------+
60 * | substatement | section | cardinality |data model mapping|
61 * +--------------+---------+-------------+------------------+
62 * | anyxml | 7.10 | 0..n |-not supported |
63 * | choice | 7.9 | 0..n |-child nodes |
64 * | container | 7.5 | 0..n |-child nodes |
65 * | description | 7.19.3 | 0..1 |-string |
66 * | grouping | 7.11 | 0..n |-child nodes |
67 * | leaf | 7.6 | 0..n |-YangLeaf |
68 * | leaf-list | 7.7 | 0..n |-YangLeafList |
69 * | list | 7.8 | 0..n |-child nodes |
70 * | reference | 7.19.4 | 0..1 |-string |
71 * | status | 7.19.2 | 0..1 |-YangStatus |
72 * | typedef | 7.3 | 0..n |-child nodes |
73 * | uses | 7.12 | 0..n |-child nodes |
74 * +--------------+---------+-------------+------------------+
75 */
76
77/**
Bharat saraswal63f26fb2016-04-05 15:13:44 +053078 * Represents data model node to maintain information defined in YANG grouping.
Vinod Kumar S5a39e012016-02-16 01:37:16 +053079 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053080public class YangGrouping
81 extends YangNode
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +053082 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S5a39e012016-02-16 01:37:16 +053083
84 /**
85 * Name of the grouping.
86 */
87 private String name;
88
89 /**
90 * Description.
91 */
92 private String description;
93
94 /**
95 * List of leaves.
96 */
Vinod Kumar Sc26bf192016-02-23 22:36:57 +053097 private List<YangLeaf> listOfLeaf;
Vinod Kumar S5a39e012016-02-16 01:37:16 +053098
99 /**
100 * List of leaf lists.
101 */
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530102 private List<YangLeafList> listOfLeafList;
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530103
104 /**
105 * Reference of the module.
106 */
107 private String reference;
108
109 /**
110 * Status of the node.
111 */
112 private YangStatusType status;
113
114 /**
115 * Creates the grouping node.
116 */
117 public YangGrouping() {
118 super(YangNodeType.GROUPING_NODE);
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +0530119 listOfLeaf = new LinkedList<YangLeaf>();
120 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530121 }
122
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530123 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530124 * Returns YANG grouping name.
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530125 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530126 * @return YANG grouping name
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530127 */
128 @Override
129 public String getName() {
130 return name;
131 }
132
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530133 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530134 * Sets YANG grouping name.
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530135 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530136 * @param name YANG grouping name
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530137 */
138 @Override
139 public void setName(String name) {
140 this.name = name;
141 }
142
143 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530144 * Returns the description.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530145 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530146 * @return the description
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530147 */
Bharat saraswal97459962016-02-20 21:57:16 +0530148 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530149 public String getDescription() {
150 return description;
151 }
152
153 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530154 * Sets the description.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530155 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530156 * @param description set the description
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530157 */
Bharat saraswal97459962016-02-20 21:57:16 +0530158 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530159 public void setDescription(String description) {
160 this.description = description;
161 }
162
163 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530164 * Returns the list of leaves.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530165 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530166 * @return the list of leaves
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530167 */
Bharat saraswal97459962016-02-20 21:57:16 +0530168 @Override
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530169 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530170 return listOfLeaf;
171 }
172
173 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530174 * Sets the list of leaves.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530175 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530176 * @param leafsList the list of leaf to set
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530177 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530178 @Override
179 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530180 listOfLeaf = leafsList;
181 }
182
183 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530184 * Adds a leaf.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530185 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530186 * @param leaf the leaf to be added
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530187 */
Bharat saraswal97459962016-02-20 21:57:16 +0530188 @Override
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530189 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530190 getListOfLeaf().add(leaf);
191 }
192
193 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530194 * Returns the list of leaf-list.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530195 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530196 * @return the list of leaf-list
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530197 */
Bharat saraswal97459962016-02-20 21:57:16 +0530198 @Override
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530199 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530200 return listOfLeafList;
201 }
202
203 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530204 * Sets the list of leaf-list.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530205 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530206 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530207 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530208 @Override
209 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530210 this.listOfLeafList = listOfLeafList;
211 }
212
213 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530214 * Adds a leaf-list.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530215 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530216 * @param leafList the leaf-list to be added
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530217 */
Bharat saraswal97459962016-02-20 21:57:16 +0530218 @Override
Vinod Kumar Sc26bf192016-02-23 22:36:57 +0530219 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530220 getListOfLeafList().add(leafList);
221 }
222
223 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530224 * Returns the textual reference.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530225 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530226 * @return the reference
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530227 */
Bharat saraswal97459962016-02-20 21:57:16 +0530228 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530229 public String getReference() {
230 return reference;
231 }
232
233 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530234 * Sets the textual reference.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530235 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530236 * @param reference the reference to set
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530237 */
Bharat saraswal97459962016-02-20 21:57:16 +0530238 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530239 public void setReference(String reference) {
240 this.reference = reference;
241 }
242
243 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530244 * Returns the status.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530245 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530246 * @return the status
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530247 */
Bharat saraswal97459962016-02-20 21:57:16 +0530248 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530249 public YangStatusType getStatus() {
250 return status;
251 }
252
253 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530254 * Sets the status.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530255 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530256 * @param status the status to set
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530257 */
Bharat saraswal97459962016-02-20 21:57:16 +0530258 @Override
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530259 public void setStatus(YangStatusType status) {
260 this.status = status;
261 }
262
263 /**
264 * Returns the type of the data.
265 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530266 * @return returns GROUPING_DATA
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530267 */
Bharat saraswal97459962016-02-20 21:57:16 +0530268 @Override
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530269 public YangConstructType getYangConstructType() {
270 return YangConstructType.GROUPING_DATA;
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530271 }
272
273 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530274 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530275 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530276 * @throws DataModelException a violation of data model rules
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530277 */
Bharat saraswal97459962016-02-20 21:57:16 +0530278 @Override
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530279 public void validateDataOnEntry()
280 throws DataModelException {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530281 // TODO auto-generated method stub, to be implemented by parser
282 }
283
284 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530285 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530286 *
Gaurav Agrawaldb828bd2016-02-27 03:57:50 +0530287 * @throws DataModelException a violation of data model rules
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530288 */
Bharat saraswal97459962016-02-20 21:57:16 +0530289 @Override
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530290 public void validateDataOnExit()
291 throws DataModelException {
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530292 // TODO auto-generated method stub, to be implemented by parser
293 }
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +0530294
295 /*
296 * Reference RFC6020
297 *
298 * Once a grouping is defined, it can be referenced in a "uses"
299 * statement (see Section 7.12). A grouping MUST NOT reference itself,
300 * neither directly nor indirectly through a chain of other groupings.
301 *
302 * If the grouping is defined at the top level of a YANG module or
303 * submodule, the grouping's identifier MUST be unique within the
304 * module.
305 */
306 @Override
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530307 public void detectCollidingChild(String identifierName, YangConstructType dataType)
308 throws DataModelException {
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +0530309 // Asks helper to detect colliding child.
310 detectCollidingChildUtil(identifierName, dataType, this);
311 }
312
313 @Override
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530314 public void detectSelfCollision(String identifierName, YangConstructType dataType)
315 throws DataModelException {
Gaurav Agrawalf6ccc972016-03-25 11:25:36 +0530316 if (getName().equals(identifierName)) {
317 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
318 getName() + "\"");
319 }
320 }
321 // TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings.
Vinod Kumar S5a39e012016-02-16 01:37:16 +0530322}