blob: 791b1d3a50b7ad2db178be10b2a3988f11275539 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
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 */
16package org.onosproject.yangutils.datamodel;
17
18import java.util.LinkedList;
19import java.util.List;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053020import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053022import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053023
Gaurav Agrawalbd804472016-03-25 11:25:36 +053024import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053026/*-
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 S0c330cd2016-02-23 22:36:57 +053079public class YangGrouping extends YangNode
Gaurav Agrawalbd804472016-03-25 11:25:36 +053080 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053081
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 S0c330cd2016-02-23 22:36:57 +053095 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053096
97 /**
98 * List of leaf lists.
99 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530100 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530101
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 Agrawalbd804472016-03-25 11:25:36 +0530117 listOfLeaf = new LinkedList<YangLeaf>();
118 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530119 }
120
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530121 /**
122 * Get YANG grouping name.
123 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530124 * @return YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530125 */
126 @Override
127 public String getName() {
128 return name;
129 }
130
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530131 /**
132 * Set YANG grouping name.
133 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530134 * @param name YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530135 */
136 @Override
137 public void setName(String name) {
138 this.name = name;
139 }
140
141 /**
142 * Get the description.
143 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530144 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530145 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530146 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530147 public String getDescription() {
148 return description;
149 }
150
151 /**
152 * Set the description.
153 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530154 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530155 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530156 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530157 public void setDescription(String description) {
158 this.description = description;
159 }
160
161 /**
162 * Get the list of leaves.
163 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530164 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530165 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530166 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530167 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530168 return listOfLeaf;
169 }
170
171 /**
172 * Set the list of leaves.
173 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530174 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530175 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530176 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530177 listOfLeaf = leafsList;
178 }
179
180 /**
181 * Add a leaf.
182 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530183 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530185 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530186 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530187 getListOfLeaf().add(leaf);
188 }
189
190 /**
191 * Get the list of leaf-list.
192 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530193 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530194 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530195 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530196 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 return listOfLeafList;
198 }
199
200 /**
201 * Set the list of leaf-list.
202 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530203 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530204 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530205 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 this.listOfLeafList = listOfLeafList;
207 }
208
209 /**
210 * Add a leaf-list.
211 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530212 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530214 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530215 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530216 getListOfLeafList().add(leafList);
217 }
218
219 /**
220 * Get the textual reference.
221 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530222 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530223 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530224 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 public String getReference() {
226 return reference;
227 }
228
229 /**
230 * Set the textual reference.
231 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530232 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530233 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530234 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530235 public void setReference(String reference) {
236 this.reference = reference;
237 }
238
239 /**
240 * Get the status.
241 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530242 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530243 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530244 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530245 public YangStatusType getStatus() {
246 return status;
247 }
248
249 /**
250 * Set the status.
251 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530252 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530253 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530254 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530255 public void setStatus(YangStatusType status) {
256 this.status = status;
257 }
258
259 /**
260 * Returns the type of the data.
261 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530262 * @return returns GROUPING_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530263 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530264 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530265 public YangConstructType getYangConstructType() {
266 return YangConstructType.GROUPING_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530267 }
268
269 /**
270 * Validate the data on entering the corresponding parse tree node.
271 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530272 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530273 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530274 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530275 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 Agrawal8e8770a2016-02-27 03:57:50 +0530282 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530283 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530284 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530285 public void validateDataOnExit() throws DataModelException {
286 // TODO auto-generated method stub, to be implemented by parser
287 }
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530288
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 S2ff139c2016-02-16 01:37:16 +0530315}