blob: 0f6ba7aaa429b15a7e6cd35fadbdc7fb00331e55 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-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 saraswald9822e92016-04-05 15:13:44 +053020
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022import org.onosproject.yangutils.datamodel.utils.Parsable;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053024
Gaurav Agrawalbd804472016-03-25 11:25:36 +053025import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26
Vinod Kumar S2ff139c2016-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 saraswald9822e92016-04-05 15:13:44 +053078 * Represents data model node to maintain information defined in YANG grouping.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053080public class YangGrouping
81 extends YangNode
Gaurav Agrawalbd804472016-03-25 11:25:36 +053082 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053083
Bharat saraswal96dfef02016-06-16 00:29:12 +053084 private static final long serialVersionUID = 806201607L;
85
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053086 /**
87 * Name of the grouping.
88 */
89 private String name;
90
91 /**
92 * Description.
93 */
94 private String description;
95
96 /**
97 * List of leaves.
98 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053099 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530100
101 /**
102 * List of leaf lists.
103 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530104 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530105
106 /**
107 * Reference of the module.
108 */
109 private String reference;
110
111 /**
112 * Status of the node.
113 */
114 private YangStatusType status;
115
116 /**
117 * Creates the grouping node.
118 */
119 public YangGrouping() {
120 super(YangNodeType.GROUPING_NODE);
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530121 listOfLeaf = new LinkedList<YangLeaf>();
122 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530123 }
124
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530125 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530126 * Returns YANG grouping name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530127 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530128 * @return YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 */
130 @Override
131 public String getName() {
132 return name;
133 }
134
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530135 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Sets YANG grouping name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530137 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530138 * @param name YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530139 */
140 @Override
141 public void setName(String name) {
142 this.name = name;
143 }
144
145 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530146 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530147 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530148 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530150 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530151 public String getDescription() {
152 return description;
153 }
154
155 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530156 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530159 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530160 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530161 public void setDescription(String description) {
162 this.description = description;
163 }
164
165 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530166 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530167 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530168 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530170 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530171 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530172 return listOfLeaf;
173 }
174
175 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530176 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530177 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530178 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530180 @Override
181 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530182 listOfLeaf = leafsList;
183 }
184
185 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530186 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530187 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530188 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530189 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530190 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530191 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 getListOfLeaf().add(leaf);
193 }
194
195 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530196 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530198 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530199 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530200 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530201 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530202 return listOfLeafList;
203 }
204
205 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530206 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530207 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530208 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530209 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530210 @Override
211 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530212 this.listOfLeafList = listOfLeafList;
213 }
214
215 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530216 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530217 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530218 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530220 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530221 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530222 getListOfLeafList().add(leafList);
223 }
224
225 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530226 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530227 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530228 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530230 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530231 public String getReference() {
232 return reference;
233 }
234
235 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530236 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530238 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530239 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530240 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530241 public void setReference(String reference) {
242 this.reference = reference;
243 }
244
245 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530246 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530248 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530249 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530250 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530251 public YangStatusType getStatus() {
252 return status;
253 }
254
255 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530256 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530257 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530258 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530259 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530260 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 public void setStatus(YangStatusType status) {
262 this.status = status;
263 }
264
265 /**
266 * Returns the type of the data.
267 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530268 * @return returns GROUPING_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530271 public YangConstructType getYangConstructType() {
272 return YangConstructType.GROUPING_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530273 }
274
275 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530276 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530277 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530278 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530279 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530280 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530281 public void validateDataOnEntry()
282 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530283 // TODO auto-generated method stub, to be implemented by parser
284 }
285
286 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530287 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530288 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530289 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530290 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530291 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530292 public void validateDataOnExit()
293 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530294 // TODO auto-generated method stub, to be implemented by parser
295 }
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530296
297 /*
298 * Reference RFC6020
299 *
300 * Once a grouping is defined, it can be referenced in a "uses"
301 * statement (see Section 7.12). A grouping MUST NOT reference itself,
302 * neither directly nor indirectly through a chain of other groupings.
303 *
304 * If the grouping is defined at the top level of a YANG module or
305 * submodule, the grouping's identifier MUST be unique within the
306 * module.
307 */
308 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530309 public void detectCollidingChild(String identifierName, YangConstructType dataType)
310 throws DataModelException {
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530311 // Asks helper to detect colliding child.
312 detectCollidingChildUtil(identifierName, dataType, this);
313 }
314
315 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530316 public void detectSelfCollision(String identifierName, YangConstructType dataType)
317 throws DataModelException {
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530318 if (getName().equals(identifierName)) {
319 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
320 getName() + "\"");
321 }
322 }
323 // TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530324}