blob: 5644d82695b884a7047ec975f67a5b43016641bb [file] [log] [blame]
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +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
Bharat saraswal870c56f2016-02-20 21:57:16 +053018import java.io.IOException;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053019import java.util.LinkedList;
20import java.util.List;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053021
22import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23import org.onosproject.yangutils.parser.Parsable;
24import org.onosproject.yangutils.parser.ParsableDataType;
Bharat saraswal870c56f2016-02-20 21:57:16 +053025import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053026import org.onosproject.yangutils.translator.CodeGenerator;
Bharat saraswal870c56f2016-02-20 21:57:16 +053027import org.onosproject.yangutils.translator.GeneratedFileType;
28import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
Bharat saraswal4bf8b152016-02-25 02:26:43 +053029import org.onosproject.yangutils.utils.UtilConstants;
Bharat saraswal870c56f2016-02-20 21:57:16 +053030import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053031
32/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053033 * Reference:RFC 6020.
34 * The "module" statement defines the module's name,
35 * and groups all statements that belong to the module together. The "module"
36 * statement's argument is the name of the module, followed by a block of
37 * sub statements that hold detailed module information.
38 * The module's sub statements
39 *
40 * +--------------+---------+-------------+-----------------------+
41 * |sub statement | section | cardinality | data model mapping |
42 * +--------------+---------+-------------+-----------------------+
43 * | anyxml | 7.10 | 0..n | not supported |
44 * | augment | 7.15 | 0..n | child nodes |
45 * | choice | 7.9 | 0..n | child nodes |
46 * | contact | 7.1.8 | 0..1 | string |
47 * | container | 7.5 | 0..n | child nodes |
48 * | description | 7.19.3 | 0..1 | string |
49 * | deviation | 7.18.3 | 0..n | TODO |
50 * | extension | 7.17 | 0..n | TODO |
51 * | feature | 7.18.1 | 0..n | TODO |
52 * | grouping | 7.11 | 0..n | child nodes |
53 * | identity | 7.16 | 0..n | TODO |
54 * | import | 7.1.5 | 0..n | list of import info |
55 * | include | 7.1.6 | 0..n | list of include info |
56 * | leaf | 7.6 | 0..n | list of leaf info |
57 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
58 * | list | 7.8 | 0..n | child nodes |
59 * | namespace | 7.1.3 | 1 | string/uri |
60 * | notification | 7.14 | 0..n | TODO |
61 * | organization | 7.1.7 | 0..1 | string |
62 * | prefix | 7.1.4 | 1 | string |
63 * | reference | 7.19.4 | 0..1 | string |
64 * | revision | 7.1.9 | 0..n | revision |
65 * | rpc | 7.13 | 0..n | TODO |
66 * | typedef | 7.3 | 0..n | child nodes |
67 * | uses | 7.12 | 0..n | child nodes |
68 * | YANG-version | 7.1.2 | 0..1 | int |
69 * +--------------+---------+-------------+-----------------------+
70 */
71
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053072/**
73 * Data model node to maintain information defined in YANG module.
74 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053075public class YangModule extends YangNode
76 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053077
78 /**
79 * Name of the module.
80 */
81 private String name;
82
83 /**
84 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053085 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053086 * The "contact" statement provides contact information for the module. The
87 * argument is a string that is used to specify contact information for the
88 * person or persons to whom technical queries concerning this module should
89 * be sent, such as their name, postal address, telephone number, and
90 * electronic mail address.
91 */
92 private String contact;
93
94 /**
95 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053096 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053097 * The "description" statement takes as an argument a string that contains a
98 * human-readable textual description of this definition. The text is
99 * provided in a language (or languages) chosen by the module developer; for
100 * the sake of interoperability.
101 */
102 private String description;
103
104 /**
105 * List of YANG modules imported.
106 */
107 private List<YangImport> importList;
108
109 /**
110 * List of YANG sub-modules included.
111 */
112 private List<YangInclude> includeList;
113
114 /**
115 * List of leaves at root level in the module.
116 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530117 private List<YangLeaf> listOfLeaf;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530118
119 /**
120 * List of leaf-lists at root level in the module.
121 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 private List<YangLeafList> listOfLeafList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530123
124 /**
125 * Name space of the module.
126 */
127 private YangNameSpace nameSpace;
128
129 /**
130 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530131 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530132 * The "organization" statement defines the party responsible for this
133 * module. The argument is a string that is used to specify a textual
134 * description of the organization(s) under whose auspices this module was
135 * developed.
136 */
137 private String organization;
138
139 /**
140 * Prefix to refer to the objects in module.
141 */
142 private String prefix;
143
144 /**
145 * Reference of the module.
146 */
147 private String reference;
148
149 /**
150 * Revision info of the module.
151 */
152 private YangRevision revision;
153
154 /**
155 * YANG version.
156 */
157 private byte version;
158
159 /**
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530160 * Package of the generated java code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530161 */
162 private String pkg;
163
164 /**
165 * Cached Java File Handle.
166 */
167 private CachedFileHandle fileHandle;
168
Vinod Kumar S71cba682016-02-25 15:52:16 +0530169 /*-
170 * Nested typedefs and groupings.
171 * Typedefs and groupings may appear nested under many YANG statements,
172 * allowing these to be lexically scoped by the hierarchy under which
173 * they appear. This allows types and groupings to be defined near
174 * where they are used, rather than placing them at the top level of the
175 * hierarchy. The close proximity increases readability.
176 *
177 * Scoping also allows types to be defined without concern for naming
178 * conflicts between types in different submodules. Type names can be
179 * specified without adding leading strings designed to prevent name
180 * collisions within large modules.
181 *
182 * Finally, scoping allows the module author to keep types and groupings
183 * private to their module or submodule, preventing their reuse. Since
184 * only top-level types and groupings (i.e., those appearing as
185 * sub-statements to a module or submodule statement) can be used outside
186 * the module or submodule, the developer has more control over what
187 * pieces of their module are presented to the outside world, supporting
188 * the need to hide internal information and maintaining a boundary
189 * between what is shared with the outside world and what is kept
190 * private.
191 *
192 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
193 * type or grouping cannot be defined if a higher level in the schema
194 * hierarchy has a definition with a matching identifier.
195 *
196 * A reference to an unprefixed type or grouping, or one which uses the
197 * prefix of the current module, is resolved by locating the closest
198 * matching "typedef" or "grouping" statement among the immediate
199 * sub-statements of each ancestor statement.
200 */
201 /**
202 * List of nodes which require nested reference resolution.
203 */
204 private List<YangNode> nestedReferenceResoulutionList;
205
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530206 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530207 * Create a YANG node of module type.
208 */
209 public YangModule() {
210 super(YangNodeType.MODULE_NODE);
211 }
212
Vinod Kumar S71cba682016-02-25 15:52:16 +0530213 /**
214 * Get name of the module.
215 *
216 * @return module name.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530217 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530218 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530219 public String getName() {
220 return name;
221 }
222
Vinod Kumar S71cba682016-02-25 15:52:16 +0530223 /**
224 * Set module name.
225 *
226 * @param moduleName module name.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530227 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530228 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530229 public void setName(String moduleName) {
230 name = moduleName;
231 }
232
233 /**
234 * Get the contact details of the module owner.
235 *
236 * @return the contact details of YANG owner.
237 */
238 public String getContact() {
239 return contact;
240 }
241
242 /**
243 * Set the contact details of the module owner.
244 *
245 * @param contact the contact details of YANG owner.
246 */
247 public void setContact(String contact) {
248 this.contact = contact;
249 }
250
251 /**
252 * Get the description of module.
253 *
254 * @return the description of YANG module.
255 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530256 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530257 public String getDescription() {
258 return description;
259 }
260
261 /**
262 * Set the description of module.
263 *
264 * @param description set the description of YANG module.
265 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530266 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530267 public void setDescription(String description) {
268 this.description = description;
269 }
270
271 /**
272 * Get the list of imported modules.
273 *
274 * @return the list of imported modules.
275 */
276 public List<YangImport> getImportList() {
277 return importList;
278 }
279
280 /**
281 * prevent setting the import list from outside.
282 *
283 * @param importList the import list to set.
284 */
285 private void setImportList(List<YangImport> importList) {
286 this.importList = importList;
287 }
288
289 /**
290 * Add the imported module information to the import list.
291 *
292 * @param importedModule module being imported.
293 */
294 public void addImportedInfo(YangImport importedModule) {
295
296 if (getImportList() == null) {
297 setImportList(new LinkedList<YangImport>());
298 }
299
300 getImportList().add(importedModule);
301
302 return;
303 }
304
305 /**
306 * Get the list of included sub modules.
307 *
308 * @return the included list of sub modules.
309 */
310 public List<YangInclude> getIncludeList() {
311 return includeList;
312 }
313
314 /**
315 * Set the list of included sub modules.
316 *
317 * @param includeList the included list to set.
318 */
319 private void setIncludeList(List<YangInclude> includeList) {
320 this.includeList = includeList;
321 }
322
323 /**
324 * Add the included sub module information to the include list.
325 *
326 * @param includeModule submodule being included.
327 */
328 public void addIncludedInfo(YangInclude includeModule) {
329
330 if (getIncludeList() == null) {
331 setIncludeList(new LinkedList<YangInclude>());
332 }
333
334 getIncludeList().add(includeModule);
335 return;
336 }
337
338 /**
339 * Get the list of leaves in module.
340 *
341 * @return the list of leaves.
342 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530343 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530344 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530345 return listOfLeaf;
346 }
347
348 /**
349 * Set the list of leaf in module.
350 *
351 * @param leafsList the list of leaf to set.
352 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530353 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530354 listOfLeaf = leafsList;
355 }
356
357 /**
358 * Add a leaf in module.
359 *
360 * @param leaf the leaf to be added.
361 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530362 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530363 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530364 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530365 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530366 }
367
368 getListOfLeaf().add(leaf);
369 }
370
371 /**
372 * Get the list of leaf-list from module.
373 *
374 * @return the list of leaf-list.
375 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530376 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530377 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530378 return listOfLeafList;
379 }
380
381 /**
382 * Set the list of leaf-list in module.
383 *
384 * @param listOfLeafList the list of leaf-list to set.
385 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530386 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530387 this.listOfLeafList = listOfLeafList;
388 }
389
390 /**
391 * Add a leaf-list in module.
392 *
393 * @param leafList the leaf-list to be added.
394 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530395 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530396 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530397 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530398 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530399 }
400
401 getListOfLeafList().add(leafList);
402 }
403
404 /**
405 * Get the name space of module elements.
406 *
407 * @return the nameSpace.
408 */
409 public YangNameSpace getNameSpace() {
410 return nameSpace;
411 }
412
413 /**
414 * Set the name space of module elements.
415 *
416 * @param nameSpace the nameSpace to set.
417 */
418 public void setNameSpace(YangNameSpace nameSpace) {
419 this.nameSpace = nameSpace;
420 }
421
422 /**
423 * Get the modules organization.
424 *
425 * @return the organization.
426 */
427 public String getOrganization() {
428 return organization;
429 }
430
431 /**
432 * Set the modules organization.
433 *
434 * @param org the organization to set.
435 */
436 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530437 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530438 }
439
440 /**
441 * Get the prefix.
442 *
443 * @return the prefix
444 */
445 public String getPrefix() {
446 return prefix;
447 }
448
449 /**
450 * Set the prefix.
451 *
452 * @param prefix the prefix to set.
453 */
454 public void setPrefix(String prefix) {
455 this.prefix = prefix;
456 }
457
458 /**
459 * Get the textual reference.
460 *
461 * @return the reference.
462 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530463 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530464 public String getReference() {
465 return reference;
466 }
467
468 /**
469 * Set the textual reference.
470 *
471 * @param reference the reference to set.
472 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530473 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530474 public void setReference(String reference) {
475 this.reference = reference;
476 }
477
478 /**
479 * Get the revision.
480 *
481 * @return the revision.
482 */
483 public YangRevision getRevision() {
484 return revision;
485 }
486
487 /**
488 * Set the revision.
489 *
490 * @param revision the revision to set.
491 */
492 public void setRevision(YangRevision revision) {
493 this.revision = revision;
494 }
495
496 /**
497 * Get the version.
498 *
499 * @return the version.
500 */
501 public byte getVersion() {
502 return version;
503 }
504
505 /**
506 * Set the version.
507 *
508 * @param version the version to set.
509 */
510 public void setVersion(byte version) {
511 this.version = version;
512 }
513
514 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530515 * Get the mapped java package.
516 *
517 * @return the java package
518 */
519 @Override
520 public String getPackage() {
521 return pkg;
522 }
523
524 /**
525 * Set the mapped java package.
526 *
527 * @param pcg the package to set
528 */
529 @Override
530 public void setPackage(String pcg) {
531 pkg = pcg;
532 }
533
534 /**
535 * Get the cached file handle.
536 *
537 * @return the fileHandle
538 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530539 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530540 public CachedFileHandle getFileHandle() {
541 return fileHandle;
542 }
543
544 /**
545 * Set the cached file handle.
546 *
547 * @param handle the fileHandle to set
548 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530549 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530550 public void setFileHandle(CachedFileHandle handle) {
551 fileHandle = handle;
552 }
553
554 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530555 * Get the list of nested reference's which required resolution.
556 *
557 * @return list of nested reference's which required resolution.
558 */
559 public List<YangNode> getNestedReferenceResoulutionList() {
560 return nestedReferenceResoulutionList;
561 }
562
563 /**
564 * Set list of nested reference's which requires resolution.
565 *
566 * @param nestedReferenceResoulutionList list of nested reference's which
567 * requires resolution.
568 */
569 private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) {
570 this.nestedReferenceResoulutionList = nestedReferenceResoulutionList;
571 }
572
573 /**
574 * Set list of nested reference's which requires resolution.
575 *
576 * @param nestedReference nested reference which requires resolution.
577 */
578 public void addToNestedReferenceResoulutionList(YangNode nestedReference) {
579 if (getNestedReferenceResoulutionList() == null) {
580 setNestedReferenceResoulutionList(new LinkedList<YangNode>());
581 }
582 getNestedReferenceResoulutionList().add(nestedReference);
583 }
584
585 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530586 * Returns the type of the parsed data.
587 *
588 * @return returns MODULE_DATA.
589 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530590 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530591 public ParsableDataType getParsableDataType() {
592 return ParsableDataType.MODULE_DATA;
593 }
594
595 /**
596 * Validate the data on entering the corresponding parse tree node.
597 *
598 * @throws DataModelException a violation of data model rules
599 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530600 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530601 public void validateDataOnEntry() throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530602 /*
603 * Module is root in the data model tree, hence there is no entry
604 * validation
605 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530606 }
607
608 /**
609 * Validate the data on exiting the corresponding parse tree node.
610 *
611 * @throws DataModelException a violation of data model rules
612 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530613 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530614 public void validateDataOnExit() throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530615 /*
616 * TODO: perform symbol linking for the imported or included YANG info.
617 * TODO: perform symbol resolution for referred YANG entities.
618 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530619 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530620
621 /**
622 * Generates java code for module.
Bharat saraswal870c56f2016-02-20 21:57:16 +0530623 *
624 * @throws IOException when fails to generate the source files.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530625 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530626 @Override
627 public void generateJavaCodeEntry() throws IOException {
628 String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
629 getRevision().getRevDate());
630 setPackage(modPkg);
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530631
Bharat saraswal870c56f2016-02-20 21:57:16 +0530632 CachedFileHandle handle = null;
633 try {
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530634 FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName());
Bharat saraswal870c56f2016-02-20 21:57:16 +0530635 handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530636 handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/"));
Bharat saraswal870c56f2016-02-20 21:57:16 +0530637 } catch (IOException e) {
638 throw new IOException("Failed to create the source files.");
639 }
640 setFileHandle(handle);
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530641 addLeavesAttributes();
642 addLeafListAttributes();
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530643 }
644
645 @Override
646 public void generateJavaCodeExit() throws IOException {
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530647 getFileHandle().close();
648 return;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530649 }
650
651 /**
652 * Adds leaf attributes in generated files.
653 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530654 private void addLeavesAttributes() {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530655
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530656 List<YangLeaf> leaves = getListOfLeaf();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530657 if (leaves != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530658 for (YangLeaf leaf : leaves) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530659 getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
660 }
661 }
662 }
663
664 /**
665 * Adds leaf list's attributes in generated files.
666 */
667 private void addLeafListAttributes() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530668 List<YangLeafList> leavesList = getListOfLeafList();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530669 if (leavesList != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530670 for (YangLeafList leafList : leavesList) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530671 getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
672 }
673 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530674 }
675
Vinod Kumar S71cba682016-02-25 15:52:16 +0530676 /**
677 * Add a type to resolve the nested references.
678 *
679 * @param node grouping or typedef node which needs to be resolved.
680 * @throws DataModelException data model exception.
681 */
682 public static void addToResolveList(YangNode node) throws DataModelException {
683 /* get the module node to add maintain the list of nested reference */
684 YangModule module;
685 YangNode curNode = node;
686 while (curNode.getNodeType() != YangNodeType.MODULE_NODE) {
687 curNode = curNode.getParent();
688 if (curNode == null) {
689 break;
690 }
691 }
692 if (curNode == null) {
693 throw new DataModelException("Datamodel tree is not correct");
694 }
695
696 module = (YangModule) curNode;
697 module.addToNestedReferenceResoulutionList(node);
698 return;
699 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530700}