blob: 467217e504b2199a3cbfd4b504ba5ce609517d8d [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
18import java.util.LinkedList;
19import java.util.List;
20
21import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
23import org.onosproject.yangutils.parser.ParsableDataType;
Bharat saraswal594bc6d2016-02-22 22:15:21 +053024import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053025
26/*
27 * Reference RFC 6020.
28 *
29 * While the primary unit in YANG is a module, a YANG module can itself
30 * be constructed out of several submodules. Submodules allow a module
31 * designer to split a complex model into several pieces where all the
32 * submodules contribute to a single namespace, which is defined by the
33 * module that includes the submodules.
34 *
35 * The "submodule" statement defines the submodule's name, and groups
36 * all statements that belong to the submodule together. The
37 * "submodule" statement's argument is the name of the submodule,
38 * followed by a block of sub-statements that hold detailed submodule
39 * information.
40 *
41 * The submodule's sub-statements
42 *
43 * +--------------+---------+-------------+------------------+
44 * | substatement | section | cardinality |data model mapping|
45 * +--------------+---------+-------------+------------------+
46 * | anyxml | 7.10 | 0..n | - not supported |
47 * | augment | 7.15 | 0..n | - child nodes |
48 * | belongs-to | 7.2.2 | 1 | - YangBelongsTo |
49 * | choice | 7.9 | 0..n | - child nodes |
50 * | contact | 7.1.8 | 0..1 | - string |
51 * | container | 7.5 | 0..n | - child nodes |
52 * | description | 7.19.3 | 0..1 | - string |
53 * | deviation | 7.18.3 | 0..n | - TODO |
54 * | extension | 7.17 | 0..n | - TODO |
55 * | feature | 7.18.1 | 0..n | - TODO |
56 * | grouping | 7.11 | 0..n | - child nodes |
57 * | identity | 7.16 | 0..n | - TODO |
58 * | import | 7.1.5 | 0..n | - YangImport |
59 * | include | 7.1.6 | 0..n | - YangInclude |
60 * | leaf | 7.6 | 0..n | - YangLeaf |
61 * | leaf-list | 7.7 | 0..n | - YangLeafList |
62 * | list | 7.8 | 0..n | - child nodes |
63 * | notification | 7.14 | 0..n | - TODO |
64 * | organization | 7.1.7 | 0..1 | - string |
65 * | reference | 7.19.4 | 0..1 | - string |
66 * | revision | 7.1.9 | 0..n | - string |
67 * | rpc | 7.13 | 0..n | - TODO |
68 * | typedef | 7.3 | 0..n | - child nodes |
69 * | uses | 7.12 | 0..n | - child nodes |
70 * | YANG-version | 7.1.2 | 0..1 | - int |
71 * +--------------+---------+-------------+------------------+
72 */
73/**
74 * Data model node to maintain information defined in YANG sub-module.
75 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076public class YangSubModule extends YangNode
77 implements YangLeavesHolder, YangDesc, YangReference, Parsable {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053078
79 /**
80 * Name of sub module.
81 */
82 private String name;
83
84 /**
85 * Module to which it belongs to.
86 */
87 private YangBelongsTo belongsTo;
88
89 /**
90 * Reference RFC 6020.
91 *
92 * The "contact" statement provides contact information for the module. The
93 * argument is a string that is used to specify contact information for the
94 * person or persons to whom technical queries concerning this module should
95 * be sent, such as their name, postal address, telephone number, and
96 * electronic mail address.
97 */
98 private String contact;
99
100 /**
101 * Description.
102 */
103 private String description;
104
105 /**
106 * List of YANG modules imported.
107 */
108 private List<YangImport> importList;
109
110 /**
111 * List of YANG sub-modules included.
112 */
113 private List<YangInclude> includeList;
114
115 /**
116 * List of leaves at root level in the sub-module.
117 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530119
120 /**
121 * List of leaf-lists at root level in the sub-module.
122 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530124
125 /**
126 * organization owner of the sub-module.
127 */
128 private String organization;
129
130 /**
131 * reference of the sub-module.
132 */
133 private String reference;
134
135 /**
136 * revision info of the sub-module.
137 */
138 private YangRevision revision;
139
140 /**
141 * YANG version.
142 */
143 private byte version;
144
145 /**
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530146 * package of the generated java code.
147 */
148 private String pkg;
149
150 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530151 * Create a sub module node.
152 */
153 public YangSubModule() {
154 super(YangNodeType.SUB_MODULE_NODE);
155 }
156
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530157 /**
158 * Get the YANG name of the sub module.
159 *
160 * @return YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530161 */
162 @Override
163 public String getName() {
164 return name;
165 }
166
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530167 /**
168 * Set YANG name of the sub module.
169 *
170 * @param subModuleName YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530171 */
172 @Override
173 public void setName(String subModuleName) {
174 name = subModuleName;
175 }
176
177 /**
178 * Get the module info.
179 *
180 * @return the belongs to info
181 */
182 public YangBelongsTo getBelongsTo() {
183 return belongsTo;
184 }
185
186 /**
187 * Set the module info.
188 *
189 * @param belongsTo module info to set.
190 */
191 public void setBelongsTo(YangBelongsTo belongsTo) {
192 this.belongsTo = belongsTo;
193 }
194
195 /**
196 * Get the contact.
197 *
198 * @return the contact.
199 */
200 public String getContact() {
201 return contact;
202 }
203
204 /**
205 * Set the contact.
206 *
207 * @param contact the contact to set
208 */
209 public void setContact(String contact) {
210 this.contact = contact;
211 }
212
213 /**
214 * Get the description.
215 *
216 * @return the description.
217 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530218 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530219 public String getDescription() {
220 return description;
221 }
222
223 /**
224 * Set the description.
225 *
226 * @param description set the description.
227 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530228 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530229 public void setDescription(String description) {
230 this.description = description;
231 }
232
233 /**
234 * Get the list of imported modules.
235 *
236 * @return the list of imported modules.
237 */
238 public List<YangImport> getImportList() {
239 return importList;
240 }
241
242 /**
243 * prevent setting the import list from outside.
244 *
245 * @param importList the import list to set.
246 */
247 private void setImportList(List<YangImport> importList) {
248 this.importList = importList;
249 }
250
251 /**
252 * Add the imported module information to the import list.
253 *
254 * @param importedModule module being imported.
255 */
256 public void addImportedInfo(YangImport importedModule) {
257
258 if (getImportList() == null) {
259 setImportList(new LinkedList<YangImport>());
260 }
261
262 getImportList().add(importedModule);
263
264 return;
265 }
266
267 /**
268 * Get the list of included sub modules.
269 *
270 * @return the included list of sub modules.
271 */
272 public List<YangInclude> getIncludeList() {
273 return includeList;
274 }
275
276 /**
277 * Set the list of included sub modules.
278 *
279 * @param includeList the included list to set.
280 */
281 private void setIncludeList(List<YangInclude> includeList) {
282 this.includeList = includeList;
283 }
284
285 /**
286 * Add the included sub module information to the include list.
287 *
288 * @param includeModule submodule being included.
289 */
290 public void addIncludedInfo(YangInclude includeModule) {
291
292 if (getIncludeList() == null) {
293 setIncludeList(new LinkedList<YangInclude>());
294 }
295
296 getIncludeList().add(includeModule);
297 return;
298 }
299
300 /**
301 * Get the list of leaves.
302 *
303 * @return the list of leaves.
304 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530305 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530306 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530307 return listOfLeaf;
308 }
309
310 /**
311 * Set the list of leaves.
312 *
313 * @param leafsList the list of leaf to set.
314 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530315 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530316 listOfLeaf = leafsList;
317 }
318
319 /**
320 * Add a leaf.
321 *
322 * @param leaf the leaf to be added.
323 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530324 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530325 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530326 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530327 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530328 }
329
330 getListOfLeaf().add(leaf);
331 }
332
333 /**
334 * Get the list of leaf-list.
335 *
336 * @return the list of leaf-list.
337 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530338 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530339 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530340 return listOfLeafList;
341 }
342
343 /**
344 * Set the list of leaf-list.
345 *
346 * @param listOfLeafList the list of leaf-list to set.
347 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530348 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530349 this.listOfLeafList = listOfLeafList;
350 }
351
352 /**
353 * Add a leaf-list.
354 *
355 * @param leafList the leaf-list to be added.
356 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530357 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530358 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530359 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530360 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530361 }
362
363 getListOfLeafList().add(leafList);
364 }
365
366 /**
367 * Get the sub-modules organization.
368 *
369 * @return the organization.
370 */
371 public String getOrganization() {
372 return organization;
373 }
374
375 /**
376 * Set the sub-modules organization.
377 *
378 * @param org the organization to set.
379 */
380 public void setOrganization(String org) {
381 organization = org;
382 }
383
384 /**
385 * Get the textual reference.
386 *
387 * @return the reference.
388 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530389 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530390 public String getReference() {
391 return reference;
392 }
393
394 /**
395 * Set the textual reference.
396 *
397 * @param reference the reference to set.
398 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530399 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530400 public void setReference(String reference) {
401 this.reference = reference;
402 }
403
404 /**
405 * Get the revision.
406 *
407 * @return the revision.
408 */
409 public YangRevision getRevision() {
410 return revision;
411 }
412
413 /**
414 * Set the revision.
415 *
416 * @param revision the revision to set.
417 */
418 public void setRevision(YangRevision revision) {
419 this.revision = revision;
420 }
421
422 /**
423 * Get the version.
424 *
425 * @return the version.
426 */
427 public byte getVersion() {
428 return version;
429 }
430
431 /**
432 * Set the version.
433 *
434 * @param version the version to set.
435 */
436 public void setVersion(byte version) {
437 this.version = version;
438 }
439
440 /**
441 * Returns the type of the parsed data.
442 *
443 * @return returns SUB_MODULE_DATA.
444 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530445 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530446 public ParsableDataType getParsableDataType() {
447 return ParsableDataType.SUB_MODULE_DATA;
448 }
449
450 /**
451 * Validate the data on entering the corresponding parse tree node.
452 *
453 * @throws DataModelException a violation of data model rules.
454 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530455 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530456 public void validateDataOnEntry() throws DataModelException {
457 // TODO auto-generated method stub, to be implemented by parser
458 }
459
460 /**
461 * Validate the data on exiting the corresponding parse tree node.
462 *
463 * @throws DataModelException a violation of data model rules.
464 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530465 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530466 public void validateDataOnExit() throws DataModelException {
467 // TODO auto-generated method stub, to be implemented by parser
468 }
469
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530470 /**
471 * Generates java code for sub-module.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530472 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530473 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530474 public void generateJavaCodeEntry() {
475 // TODO Auto-generated method stub
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530476 }
477
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530478 /**
479 * Free resources used to generate code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530480 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530481 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530482 public void generateJavaCodeExit() {
483 // TODO Auto-generated method stub
484
485 }
486
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530487 /**
488 * Get the mapped java package.
489 *
490 * @return the java package
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530491 */
492 @Override
493 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530494 return pkg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530495 }
496
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530497 /**
498 * Set the mapped java package.
499 *
500 * @param pakg the package to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530501 */
502 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530503 public void setPackage(String pakg) {
504 pkg = pakg;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530505 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530506
507 @Override
508 public CachedFileHandle getFileHandle() {
509 // TODO Auto-generated method stub
510 return null;
511 }
512
513 @Override
514 public void setFileHandle(CachedFileHandle fileHandle) {
515 // TODO Auto-generated method stub
516
517 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530518}