blob: 47abdca113a670e393a96f5911eb5ba10087ed8b [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;
22import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053023import org.onosproject.yangutils.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 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053080public class YangGrouping extends YangNode
Gaurav Agrawalbd804472016-03-25 11:25:36 +053081 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053082
83 /**
84 * Name of the grouping.
85 */
86 private String name;
87
88 /**
89 * Description.
90 */
91 private String description;
92
93 /**
94 * List of leaves.
95 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053096 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053097
98 /**
99 * List of leaf lists.
100 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530101 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530102
103 /**
104 * Reference of the module.
105 */
106 private String reference;
107
108 /**
109 * Status of the node.
110 */
111 private YangStatusType status;
112
113 /**
114 * Creates the grouping node.
115 */
116 public YangGrouping() {
117 super(YangNodeType.GROUPING_NODE);
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530118 listOfLeaf = new LinkedList<YangLeaf>();
119 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 }
121
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530123 * Returns YANG grouping name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530125 * @return YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 */
127 @Override
128 public String getName() {
129 return name;
130 }
131
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530132 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530133 * Sets YANG grouping name.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530134 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530135 * @param name YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530136 */
137 @Override
138 public void setName(String name) {
139 this.name = name;
140 }
141
142 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530143 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530144 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530145 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530146 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530147 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530148 public String getDescription() {
149 return description;
150 }
151
152 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530153 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530155 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530156 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530157 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 public void setDescription(String description) {
159 this.description = description;
160 }
161
162 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530163 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530164 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530165 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530166 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530167 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530168 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 return listOfLeaf;
170 }
171
172 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530173 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530174 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530175 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530176 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530177 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530178 listOfLeaf = leafsList;
179 }
180
181 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530182 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530183 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530184 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530185 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530186 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530187 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530188 getListOfLeaf().add(leaf);
189 }
190
191 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530192 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530193 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530194 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530195 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530196 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530197 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 return listOfLeafList;
199 }
200
201 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530202 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530203 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530204 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530205 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530206 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530207 this.listOfLeafList = listOfLeafList;
208 }
209
210 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530211 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530212 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530213 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530215 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530216 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530217 getListOfLeafList().add(leafList);
218 }
219
220 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530221 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530222 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530223 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530224 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530225 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 public String getReference() {
227 return reference;
228 }
229
230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530232 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530233 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530234 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530235 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530236 public void setReference(String reference) {
237 this.reference = reference;
238 }
239
240 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530241 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530242 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530243 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530244 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530245 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530246 public YangStatusType getStatus() {
247 return status;
248 }
249
250 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530251 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530252 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530253 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530254 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530255 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530256 public void setStatus(YangStatusType status) {
257 this.status = status;
258 }
259
260 /**
261 * Returns the type of the data.
262 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530263 * @return returns GROUPING_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530264 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530265 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530266 public YangConstructType getYangConstructType() {
267 return YangConstructType.GROUPING_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530268 }
269
270 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530271 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530272 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530273 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530275 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530276 public void validateDataOnEntry() throws DataModelException {
277 // TODO auto-generated method stub, to be implemented by parser
278 }
279
280 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530281 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530282 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530283 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530284 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530285 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530286 public void validateDataOnExit() throws DataModelException {
287 // TODO auto-generated method stub, to be implemented by parser
288 }
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530289
290 /*
291 * Reference RFC6020
292 *
293 * Once a grouping is defined, it can be referenced in a "uses"
294 * statement (see Section 7.12). A grouping MUST NOT reference itself,
295 * neither directly nor indirectly through a chain of other groupings.
296 *
297 * If the grouping is defined at the top level of a YANG module or
298 * submodule, the grouping's identifier MUST be unique within the
299 * module.
300 */
301 @Override
302 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530303 // 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}