blob: f2e9119e1e23205a9c9c21973ec7fe200be37a8d [file] [log] [blame]
Vinod Kumar S67e7be62016-02-11 20:13:28 +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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053018import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20import org.onosproject.yangutils.parser.Parsable;
21import org.onosproject.yangutils.translator.CachedFileHandle;
22import org.onosproject.yangutils.utils.YangConstructType;
23
Vinod Kumar S67e7be62016-02-11 20:13:28 +053024import java.util.LinkedList;
25import java.util.List;
26
Vinod Kumar S67e7be62016-02-11 20:13:28 +053027/*
28 * Reference RFC 6020.
29 *
30 * While the primary unit in YANG is a module, a YANG module can itself
31 * be constructed out of several submodules. Submodules allow a module
32 * designer to split a complex model into several pieces where all the
33 * submodules contribute to a single namespace, which is defined by the
34 * module that includes the submodules.
35 *
36 * The "submodule" statement defines the submodule's name, and groups
37 * all statements that belong to the submodule together. The
38 * "submodule" statement's argument is the name of the submodule,
39 * followed by a block of sub-statements that hold detailed submodule
40 * information.
41 *
42 * The submodule's sub-statements
43 *
44 * +--------------+---------+-------------+------------------+
45 * | substatement | section | cardinality |data model mapping|
46 * +--------------+---------+-------------+------------------+
47 * | anyxml | 7.10 | 0..n | - not supported |
48 * | augment | 7.15 | 0..n | - child nodes |
49 * | belongs-to | 7.2.2 | 1 | - YangBelongsTo |
50 * | choice | 7.9 | 0..n | - child nodes |
51 * | contact | 7.1.8 | 0..1 | - string |
52 * | container | 7.5 | 0..n | - child nodes |
53 * | description | 7.19.3 | 0..1 | - string |
54 * | deviation | 7.18.3 | 0..n | - TODO |
55 * | extension | 7.17 | 0..n | - TODO |
56 * | feature | 7.18.1 | 0..n | - TODO |
57 * | grouping | 7.11 | 0..n | - child nodes |
58 * | identity | 7.16 | 0..n | - TODO |
59 * | import | 7.1.5 | 0..n | - YangImport |
60 * | include | 7.1.6 | 0..n | - YangInclude |
61 * | leaf | 7.6 | 0..n | - YangLeaf |
62 * | leaf-list | 7.7 | 0..n | - YangLeafList |
63 * | list | 7.8 | 0..n | - child nodes |
64 * | notification | 7.14 | 0..n | - TODO |
65 * | organization | 7.1.7 | 0..1 | - string |
66 * | reference | 7.19.4 | 0..1 | - string |
67 * | revision | 7.1.9 | 0..n | - string |
68 * | rpc | 7.13 | 0..n | - TODO |
69 * | typedef | 7.3 | 0..n | - child nodes |
70 * | uses | 7.12 | 0..n | - child nodes |
71 * | YANG-version | 7.1.2 | 0..1 | - int |
72 * +--------------+---------+-------------+------------------+
73 */
74/**
75 * Data model node to maintain information defined in YANG sub-module.
76 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053077public class YangSubModule extends YangNode
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053078 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053079
80 /**
81 * Name of sub module.
82 */
83 private String name;
84
85 /**
86 * Module to which it belongs to.
87 */
88 private YangBelongsTo belongsTo;
89
90 /**
91 * Reference RFC 6020.
92 *
93 * The "contact" statement provides contact information for the module. The
94 * argument is a string that is used to specify contact information for the
95 * person or persons to whom technical queries concerning this module should
96 * be sent, such as their name, postal address, telephone number, and
97 * electronic mail address.
98 */
99 private String contact;
100
101 /**
102 * Description.
103 */
104 private String description;
105
106 /**
107 * List of YANG modules imported.
108 */
109 private List<YangImport> importList;
110
111 /**
112 * List of YANG sub-modules included.
113 */
114 private List<YangInclude> includeList;
115
116 /**
117 * List of leaves at root level in the sub-module.
118 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530119 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530120
121 /**
122 * List of leaf-lists at root level in the sub-module.
123 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530125
126 /**
127 * organization owner of the sub-module.
128 */
129 private String organization;
130
131 /**
132 * reference of the sub-module.
133 */
134 private String reference;
135
136 /**
137 * revision info of the sub-module.
138 */
139 private YangRevision revision;
140
141 /**
142 * YANG version.
143 */
144 private byte version;
145
146 /**
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530147 * package of the generated java code.
148 */
149 private String pkg;
150
151 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530152 * Create a sub module node.
153 */
154 public YangSubModule() {
155 super(YangNodeType.SUB_MODULE_NODE);
156 }
157
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530158 /**
159 * Get the YANG name of the sub module.
160 *
161 * @return YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530162 */
163 @Override
164 public String getName() {
165 return name;
166 }
167
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530168 /**
169 * Set YANG name of the sub module.
170 *
171 * @param subModuleName YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530172 */
173 @Override
174 public void setName(String subModuleName) {
175 name = subModuleName;
176 }
177
178 /**
179 * Get the module info.
180 *
181 * @return the belongs to info
182 */
183 public YangBelongsTo getBelongsTo() {
184 return belongsTo;
185 }
186
187 /**
188 * Set the module info.
189 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530190 * @param belongsTo module info to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530191 */
192 public void setBelongsTo(YangBelongsTo belongsTo) {
193 this.belongsTo = belongsTo;
194 }
195
196 /**
197 * Get the contact.
198 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530199 * @return the contact
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530200 */
201 public String getContact() {
202 return contact;
203 }
204
205 /**
206 * Set the contact.
207 *
208 * @param contact the contact to set
209 */
210 public void setContact(String contact) {
211 this.contact = contact;
212 }
213
214 /**
215 * Get the description.
216 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530217 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530218 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530219 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530220 public String getDescription() {
221 return description;
222 }
223
224 /**
225 * Set the description.
226 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530227 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530228 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530229 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530230 public void setDescription(String description) {
231 this.description = description;
232 }
233
234 /**
235 * Get the list of imported modules.
236 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530237 * @return the list of imported modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530238 */
239 public List<YangImport> getImportList() {
240 return importList;
241 }
242
243 /**
244 * prevent setting the import list from outside.
245 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530246 * @param importList the import list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530247 */
248 private void setImportList(List<YangImport> importList) {
249 this.importList = importList;
250 }
251
252 /**
253 * Add the imported module information to the import list.
254 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 * @param importedModule module being imported
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530256 */
257 public void addImportedInfo(YangImport importedModule) {
258
259 if (getImportList() == null) {
260 setImportList(new LinkedList<YangImport>());
261 }
262
263 getImportList().add(importedModule);
264
265 return;
266 }
267
268 /**
269 * Get the list of included sub modules.
270 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530271 * @return the included list of sub modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530272 */
273 public List<YangInclude> getIncludeList() {
274 return includeList;
275 }
276
277 /**
278 * Set the list of included sub modules.
279 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530280 * @param includeList the included list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530281 */
282 private void setIncludeList(List<YangInclude> includeList) {
283 this.includeList = includeList;
284 }
285
286 /**
287 * Add the included sub module information to the include list.
288 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530289 * @param includeModule submodule being included
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530290 */
291 public void addIncludedInfo(YangInclude includeModule) {
292
293 if (getIncludeList() == null) {
294 setIncludeList(new LinkedList<YangInclude>());
295 }
296
297 getIncludeList().add(includeModule);
298 return;
299 }
300
301 /**
302 * Get the list of leaves.
303 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530304 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530305 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530306 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530307 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530308 return listOfLeaf;
309 }
310
311 /**
312 * Set the list of leaves.
313 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530314 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530315 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530316 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530317 listOfLeaf = leafsList;
318 }
319
320 /**
321 * Add a leaf.
322 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530323 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530324 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530325 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530326 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530327 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530328 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530329 }
330
331 getListOfLeaf().add(leaf);
332 }
333
334 /**
335 * Get the list of leaf-list.
336 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530337 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530338 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530339 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530340 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530341 return listOfLeafList;
342 }
343
344 /**
345 * Set the list of leaf-list.
346 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530347 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530348 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530349 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530350 this.listOfLeafList = listOfLeafList;
351 }
352
353 /**
354 * Add a leaf-list.
355 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530356 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530357 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530358 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530359 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530360 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530361 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530362 }
363
364 getListOfLeafList().add(leafList);
365 }
366
367 /**
368 * Get the sub-modules organization.
369 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530370 * @return the organization
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530371 */
372 public String getOrganization() {
373 return organization;
374 }
375
376 /**
377 * Set the sub-modules organization.
378 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530379 * @param org the organization to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530380 */
381 public void setOrganization(String org) {
382 organization = org;
383 }
384
385 /**
386 * Get the textual reference.
387 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530388 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530389 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530390 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530391 public String getReference() {
392 return reference;
393 }
394
395 /**
396 * Set the textual reference.
397 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530398 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530399 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530400 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530401 public void setReference(String reference) {
402 this.reference = reference;
403 }
404
405 /**
406 * Get the revision.
407 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530408 * @return the revision
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530409 */
410 public YangRevision getRevision() {
411 return revision;
412 }
413
414 /**
415 * Set the revision.
416 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530417 * @param revision the revision to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530418 */
419 public void setRevision(YangRevision revision) {
420 this.revision = revision;
421 }
422
423 /**
424 * Get the version.
425 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530426 * @return the version
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530427 */
428 public byte getVersion() {
429 return version;
430 }
431
432 /**
433 * Set the version.
434 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530435 * @param version the version to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530436 */
437 public void setVersion(byte version) {
438 this.version = version;
439 }
440
441 /**
442 * Returns the type of the parsed data.
443 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530444 * @return returns SUB_MODULE_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530445 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530446 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530447 public YangConstructType getYangConstructType() {
448 return YangConstructType.SUB_MODULE_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530449 }
450
451 /**
452 * Validate the data on entering the corresponding parse tree node.
453 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530454 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530455 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530456 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530457 public void validateDataOnEntry() throws DataModelException {
458 // TODO auto-generated method stub, to be implemented by parser
459 }
460
461 /**
462 * Validate the data on exiting the corresponding parse tree node.
463 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530464 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530465 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530466 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530467 public void validateDataOnExit() throws DataModelException {
468 // TODO auto-generated method stub, to be implemented by parser
469 }
470
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530471 /**
472 * Generates java code for sub-module.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530473 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530474 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530475 public void generateJavaCodeEntry() {
476 // TODO Auto-generated method stub
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530477 }
478
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530479 /**
480 * Free resources used to generate code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530481 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530482 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530483 public void generateJavaCodeExit() {
484 // TODO Auto-generated method stub
485
486 }
487
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530488 /**
489 * Get the mapped java package.
490 *
491 * @return the java package
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530492 */
493 @Override
494 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530495 return pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530496 }
497
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530498 /**
499 * Set the mapped java package.
500 *
501 * @param pakg the package to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530502 */
503 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530504 public void setPackage(String pakg) {
505 pkg = pakg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530506 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530507
508 @Override
509 public CachedFileHandle getFileHandle() {
510 // TODO Auto-generated method stub
511 return null;
512 }
513
514 @Override
515 public void setFileHandle(CachedFileHandle fileHandle) {
516 // TODO Auto-generated method stub
517
518 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530519
520 @Override
521 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
522 // Asks helper to detect colliding child.
523 detectCollidingChildUtil(identifierName, dataType, this);
524 }
525
526 @Override
527 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
528 // Not required as module doesn't have any parent.
529 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530530}