blob: 757481760842a1a971f0631603a3aced1e3ee0da [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;
20
21import 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;
Bharat saraswal594bc6d2016-02-22 22:15:21 +053024import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
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 S0c330cd2016-02-23 22:36:57 +053079public class YangGrouping extends YangNode
80 implements YangLeavesHolder, YangCommonInfo, Parsable {
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 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530113 * Package of the generated java code.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530114 */
115 private String pkg;
116
117 /**
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530118 * Creates the grouping node.
119 */
120 public YangGrouping() {
121 super(YangNodeType.GROUPING_NODE);
122 }
123
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 /**
125 * Get YANG grouping name.
126 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530127 * @return YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 */
129 @Override
130 public String getName() {
131 return name;
132 }
133
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530134 /**
135 * Set YANG grouping name.
136 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530137 * @param name YANG grouping name
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 */
139 @Override
140 public void setName(String name) {
141 this.name = name;
142 }
143
144 /**
145 * Get the description.
146 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530147 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530148 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530149 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 public String getDescription() {
151 return description;
152 }
153
154 /**
155 * Set the description.
156 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530157 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530159 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 public void setDescription(String description) {
161 this.description = description;
162 }
163
164 /**
165 * Get the list of leaves.
166 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530167 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530168 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530169 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530170 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530171 return listOfLeaf;
172 }
173
174 /**
175 * Set the list of leaves.
176 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530177 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530178 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530179 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530180 listOfLeaf = leafsList;
181 }
182
183 /**
184 * Add a leaf.
185 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530186 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530187 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530188 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530189 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530190 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530191 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 }
193
194 getListOfLeaf().add(leaf);
195 }
196
197 /**
198 * Get the list of leaf-list.
199 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530200 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530202 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530203 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530204 return listOfLeafList;
205 }
206
207 /**
208 * Set the list of leaf-list.
209 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530210 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530211 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530212 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 this.listOfLeafList = listOfLeafList;
214 }
215
216 /**
217 * Add a leaf-list.
218 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530219 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530220 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530221 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530222 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530223 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530224 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 }
226
227 getListOfLeafList().add(leafList);
228 }
229
230 /**
231 * Get the textual reference.
232 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530233 * @return the reference
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 String getReference() {
237 return reference;
238 }
239
240 /**
241 * Set the textual reference.
242 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530243 * @param reference the reference to set
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 void setReference(String reference) {
247 this.reference = reference;
248 }
249
250 /**
251 * Get the status.
252 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530253 * @return the status
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 YangStatusType getStatus() {
257 return status;
258 }
259
260 /**
261 * Set the status.
262 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530263 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530264 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530265 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 public void setStatus(YangStatusType status) {
267 this.status = status;
268 }
269
270 /**
271 * Returns the type of the data.
272 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530273 * @return returns GROUPING_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530275 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 public YangConstructType getYangConstructType() {
277 return YangConstructType.GROUPING_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 }
279
280 /**
281 * Validate the data on entering the corresponding parse tree node.
282 *
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 validateDataOnEntry() throws DataModelException {
287 // TODO auto-generated method stub, to be implemented by parser
288 }
289
290 /**
291 * Validate the data on exiting the corresponding parse tree node.
292 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530293 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530294 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530295 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530296 public void validateDataOnExit() throws DataModelException {
297 // TODO auto-generated method stub, to be implemented by parser
298 }
299
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530300 /**
301 * Generate the code for YANG grouping.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530302 *
303 * @param codeGenDir code generated directory.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530304 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530305 @Override
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530306 public void generateJavaCodeEntry(String codeGenDir) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530307 // TODO Auto-generated method stub
308
309 }
310
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530311 /**
312 * Free the resources used to generate java files corresponding to YANG
313 * grouping info and generate valid java files.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530314 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530315 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530316 public void generateJavaCodeExit() {
317 // TODO Auto-generated method stub
318
319 }
320
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530321 /**
322 * Get the mapped java package.
323 *
324 * @return the java package
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530325 */
326 @Override
327 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530328 return pkg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530329 }
330
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530331 /**
332 * Set the mapped java package.
333 *
334 * @param pakg the package to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530335 */
336 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530337 public void setPackage(String pakg) {
338 pkg = pakg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530339
340 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530341
342 @Override
343 public CachedFileHandle getFileHandle() {
344 // TODO Auto-generated method stub
345 return null;
346 }
347
348 @Override
349 public void setFileHandle(CachedFileHandle fileHandle) {
350 // TODO Auto-generated method stub
351
352 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530353}