blob: 69b0376510ab62e53b3bda5181eab427cef409b6 [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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053018import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053019
20import java.io.IOException;
21import java.util.LinkedList;
22import java.util.List;
23
24import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053025import org.onosproject.yangutils.parser.Parsable;
Bharat saraswal870c56f2016-02-20 21:57:16 +053026import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053027import org.onosproject.yangutils.translator.CodeGenerator;
Bharat saraswal870c56f2016-02-20 21:57:16 +053028import org.onosproject.yangutils.translator.GeneratedFileType;
29import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053030import org.onosproject.yangutils.utils.YangConstructType;
Bharat saraswal870c56f2016-02-20 21:57:16 +053031import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053032
33/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053034 * Reference:RFC 6020.
35 * The "module" statement defines the module's name,
36 * and groups all statements that belong to the module together. The "module"
37 * statement's argument is the name of the module, followed by a block of
38 * sub statements that hold detailed module information.
39 * The module's sub statements
40 *
41 * +--------------+---------+-------------+-----------------------+
42 * |sub statement | section | cardinality | data model mapping |
43 * +--------------+---------+-------------+-----------------------+
44 * | anyxml | 7.10 | 0..n | not supported |
45 * | augment | 7.15 | 0..n | child nodes |
46 * | choice | 7.9 | 0..n | child nodes |
47 * | contact | 7.1.8 | 0..1 | string |
48 * | container | 7.5 | 0..n | child nodes |
49 * | description | 7.19.3 | 0..1 | string |
50 * | deviation | 7.18.3 | 0..n | TODO |
51 * | extension | 7.17 | 0..n | TODO |
52 * | feature | 7.18.1 | 0..n | TODO |
53 * | grouping | 7.11 | 0..n | child nodes |
54 * | identity | 7.16 | 0..n | TODO |
55 * | import | 7.1.5 | 0..n | list of import info |
56 * | include | 7.1.6 | 0..n | list of include info |
57 * | leaf | 7.6 | 0..n | list of leaf info |
58 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
59 * | list | 7.8 | 0..n | child nodes |
60 * | namespace | 7.1.3 | 1 | string/uri |
61 * | notification | 7.14 | 0..n | TODO |
62 * | organization | 7.1.7 | 0..1 | string |
63 * | prefix | 7.1.4 | 1 | string |
64 * | reference | 7.19.4 | 0..1 | string |
65 * | revision | 7.1.9 | 0..n | revision |
66 * | rpc | 7.13 | 0..n | TODO |
67 * | typedef | 7.3 | 0..n | child nodes |
68 * | uses | 7.12 | 0..n | child nodes |
69 * | YANG-version | 7.1.2 | 0..1 | int |
70 * +--------------+---------+-------------+-----------------------+
71 */
72
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053073/**
74 * Data model node to maintain information defined in YANG module.
75 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053076public class YangModule extends YangNode
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053077 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator, CollisionDetector {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053078
79 /**
80 * Name of the module.
81 */
82 private String name;
83
84 /**
85 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053086 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053087 * The "contact" statement provides contact information for the module. The
88 * argument is a string that is used to specify contact information for the
89 * person or persons to whom technical queries concerning this module should
90 * be sent, such as their name, postal address, telephone number, and
91 * electronic mail address.
92 */
93 private String contact;
94
95 /**
96 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053097 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053098 * The "description" statement takes as an argument a string that contains a
99 * human-readable textual description of this definition. The text is
100 * provided in a language (or languages) chosen by the module developer; for
101 * the sake of interoperability.
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 module.
117 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530118 private List<YangLeaf> listOfLeaf;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530119
120 /**
121 * List of leaf-lists at root level in the module.
122 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 private List<YangLeafList> listOfLeafList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530124
125 /**
126 * Name space of the module.
127 */
128 private YangNameSpace nameSpace;
129
130 /**
131 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530132 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530133 * The "organization" statement defines the party responsible for this
134 * module. The argument is a string that is used to specify a textual
135 * description of the organization(s) under whose auspices this module was
136 * developed.
137 */
138 private String organization;
139
140 /**
141 * Prefix to refer to the objects in module.
142 */
143 private String prefix;
144
145 /**
146 * Reference of the module.
147 */
148 private String reference;
149
150 /**
151 * Revision info of the module.
152 */
153 private YangRevision revision;
154
155 /**
156 * YANG version.
157 */
158 private byte version;
159
160 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530161 * Cached Java File Handle.
162 */
163 private CachedFileHandle fileHandle;
164
Vinod Kumar S71cba682016-02-25 15:52:16 +0530165 /*-
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530166 * Reference RFC 6020.
167 *
Vinod Kumar S71cba682016-02-25 15:52:16 +0530168 * Nested typedefs and groupings.
169 * Typedefs and groupings may appear nested under many YANG statements,
170 * allowing these to be lexically scoped by the hierarchy under which
171 * they appear. This allows types and groupings to be defined near
172 * where they are used, rather than placing them at the top level of the
173 * hierarchy. The close proximity increases readability.
174 *
175 * Scoping also allows types to be defined without concern for naming
176 * conflicts between types in different submodules. Type names can be
177 * specified without adding leading strings designed to prevent name
178 * collisions within large modules.
179 *
180 * Finally, scoping allows the module author to keep types and groupings
181 * private to their module or submodule, preventing their reuse. Since
182 * only top-level types and groupings (i.e., those appearing as
183 * sub-statements to a module or submodule statement) can be used outside
184 * the module or submodule, the developer has more control over what
185 * pieces of their module are presented to the outside world, supporting
186 * the need to hide internal information and maintaining a boundary
187 * between what is shared with the outside world and what is kept
188 * private.
189 *
190 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
191 * type or grouping cannot be defined if a higher level in the schema
192 * hierarchy has a definition with a matching identifier.
193 *
194 * A reference to an unprefixed type or grouping, or one which uses the
195 * prefix of the current module, is resolved by locating the closest
196 * matching "typedef" or "grouping" statement among the immediate
197 * sub-statements of each ancestor statement.
198 */
199 /**
200 * List of nodes which require nested reference resolution.
201 */
202 private List<YangNode> nestedReferenceResoulutionList;
203
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530204 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530205 * Create a YANG node of module type.
206 */
207 public YangModule() {
208 super(YangNodeType.MODULE_NODE);
209 }
210
Vinod Kumar S71cba682016-02-25 15:52:16 +0530211 /**
212 * Get name of the module.
213 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530214 * @return module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530215 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530216 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530217 public String getName() {
218 return name;
219 }
220
Vinod Kumar S71cba682016-02-25 15:52:16 +0530221 /**
222 * Set module name.
223 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530224 * @param moduleName module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530225 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530226 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530227 public void setName(String moduleName) {
228 name = moduleName;
229 }
230
231 /**
232 * Get the contact details of the module owner.
233 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530234 * @return the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530235 */
236 public String getContact() {
237 return contact;
238 }
239
240 /**
241 * Set the contact details of the module owner.
242 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530243 * @param contact the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530244 */
245 public void setContact(String contact) {
246 this.contact = contact;
247 }
248
249 /**
250 * Get the description of module.
251 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530252 * @return the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530253 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530254 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530255 public String getDescription() {
256 return description;
257 }
258
259 /**
260 * Set the description of module.
261 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530262 * @param description set the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530263 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530264 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530265 public void setDescription(String description) {
266 this.description = description;
267 }
268
269 /**
270 * Get the list of imported modules.
271 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530272 * @return the list of imported modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530273 */
274 public List<YangImport> getImportList() {
275 return importList;
276 }
277
278 /**
279 * prevent setting the import list from outside.
280 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530281 * @param importList the import list to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530282 */
283 private void setImportList(List<YangImport> importList) {
284 this.importList = importList;
285 }
286
287 /**
288 * Add the imported module information to the import list.
289 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530290 * @param importedModule module being imported
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530291 */
292 public void addImportedInfo(YangImport importedModule) {
293
294 if (getImportList() == null) {
295 setImportList(new LinkedList<YangImport>());
296 }
297
298 getImportList().add(importedModule);
299
300 return;
301 }
302
303 /**
304 * Get the list of included sub modules.
305 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530306 * @return the included list of sub modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530307 */
308 public List<YangInclude> getIncludeList() {
309 return includeList;
310 }
311
312 /**
313 * Set the list of included sub modules.
314 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530315 * @param includeList the included list to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530316 */
317 private void setIncludeList(List<YangInclude> includeList) {
318 this.includeList = includeList;
319 }
320
321 /**
322 * Add the included sub module information to the include list.
323 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530324 * @param includeModule submodule being included
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530325 */
326 public void addIncludedInfo(YangInclude includeModule) {
327
328 if (getIncludeList() == null) {
329 setIncludeList(new LinkedList<YangInclude>());
330 }
331
332 getIncludeList().add(includeModule);
333 return;
334 }
335
336 /**
337 * Get the list of leaves in module.
338 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530339 * @return the list of leaves
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530340 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530341 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530342 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530343 return listOfLeaf;
344 }
345
346 /**
347 * Set the list of leaf in module.
348 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530349 * @param leafsList the list of leaf to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530350 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530351 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530352 listOfLeaf = leafsList;
353 }
354
355 /**
356 * Add a leaf in module.
357 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530358 * @param leaf the leaf to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530359 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530360 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530361 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530362 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530363 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530364 }
365
366 getListOfLeaf().add(leaf);
367 }
368
369 /**
370 * Get the list of leaf-list from module.
371 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530372 * @return the list of leaf-list
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530373 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530374 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530375 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530376 return listOfLeafList;
377 }
378
379 /**
380 * Set the list of leaf-list in module.
381 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530382 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530383 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530384 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530385 this.listOfLeafList = listOfLeafList;
386 }
387
388 /**
389 * Add a leaf-list in module.
390 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530391 * @param leafList the leaf-list to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530392 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530393 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530394 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530395 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530396 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530397 }
398
399 getListOfLeafList().add(leafList);
400 }
401
402 /**
403 * Get the name space of module elements.
404 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530405 * @return the nameSpace
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530406 */
407 public YangNameSpace getNameSpace() {
408 return nameSpace;
409 }
410
411 /**
412 * Set the name space of module elements.
413 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530414 * @param nameSpace the nameSpace to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530415 */
416 public void setNameSpace(YangNameSpace nameSpace) {
417 this.nameSpace = nameSpace;
418 }
419
420 /**
421 * Get the modules organization.
422 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530423 * @return the organization
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530424 */
425 public String getOrganization() {
426 return organization;
427 }
428
429 /**
430 * Set the modules organization.
431 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530432 * @param org the organization to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530433 */
434 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530435 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530436 }
437
438 /**
439 * Get the prefix.
440 *
441 * @return the prefix
442 */
443 public String getPrefix() {
444 return prefix;
445 }
446
447 /**
448 * Set the prefix.
449 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530450 * @param prefix the prefix to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530451 */
452 public void setPrefix(String prefix) {
453 this.prefix = prefix;
454 }
455
456 /**
457 * Get the textual reference.
458 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530459 * @return the reference
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530460 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530461 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530462 public String getReference() {
463 return reference;
464 }
465
466 /**
467 * Set the textual reference.
468 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530469 * @param reference the reference to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530470 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530471 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530472 public void setReference(String reference) {
473 this.reference = reference;
474 }
475
476 /**
477 * Get the revision.
478 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530479 * @return the revision
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530480 */
481 public YangRevision getRevision() {
482 return revision;
483 }
484
485 /**
486 * Set the revision.
487 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530488 * @param revision the revision to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530489 */
490 public void setRevision(YangRevision revision) {
491 this.revision = revision;
492 }
493
494 /**
495 * Get the version.
496 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530497 * @return the version
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530498 */
499 public byte getVersion() {
500 return version;
501 }
502
503 /**
504 * Set the version.
505 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530506 * @param version the version to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530507 */
508 public void setVersion(byte version) {
509 this.version = version;
510 }
511
512 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530513 * Get the mapped java package.
514 *
515 * @return the java package
516 */
517 @Override
518 public String getPackage() {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530519 if (getFileHandle() != null) {
520 return getFileHandle().getRelativeFilePath().replace("/", ".");
521 }
522 return null;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530523 }
524
525 /**
526 * Set the mapped java package.
527 *
528 * @param pcg the package to set
529 */
530 @Override
531 public void setPackage(String pcg) {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530532 if (getFileHandle() != null) {
533 pcg.replace(".", "/");
534 getFileHandle().setRelativeFilePath(pcg);
535 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530536 }
537
538 /**
539 * Get the cached file handle.
540 *
541 * @return the fileHandle
542 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530543 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530544 public CachedFileHandle getFileHandle() {
545 return fileHandle;
546 }
547
548 /**
549 * Set the cached file handle.
550 *
551 * @param handle the fileHandle to set
552 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530553 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530554 public void setFileHandle(CachedFileHandle handle) {
555 fileHandle = handle;
556 }
557
558 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530559 * Get the list of nested reference's which required resolution.
560 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530561 * @return list of nested reference's which required resolution
Vinod Kumar S71cba682016-02-25 15:52:16 +0530562 */
563 public List<YangNode> getNestedReferenceResoulutionList() {
564 return nestedReferenceResoulutionList;
565 }
566
567 /**
568 * Set list of nested reference's which requires resolution.
569 *
570 * @param nestedReferenceResoulutionList list of nested reference's which
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530571 * requires resolution
Vinod Kumar S71cba682016-02-25 15:52:16 +0530572 */
573 private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) {
574 this.nestedReferenceResoulutionList = nestedReferenceResoulutionList;
575 }
576
577 /**
578 * Set list of nested reference's which requires resolution.
579 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530580 * @param nestedReference nested reference which requires resolution
Vinod Kumar S71cba682016-02-25 15:52:16 +0530581 */
582 public void addToNestedReferenceResoulutionList(YangNode nestedReference) {
583 if (getNestedReferenceResoulutionList() == null) {
584 setNestedReferenceResoulutionList(new LinkedList<YangNode>());
585 }
586 getNestedReferenceResoulutionList().add(nestedReference);
587 }
588
589 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530590 * Returns the type of the parsed data.
591 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530592 * @return returns MODULE_DATA
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530593 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530594 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530595 public YangConstructType getYangConstructType() {
596 return YangConstructType.MODULE_DATA;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530597 }
598
599 /**
600 * Validate the data on entering the corresponding parse tree node.
601 *
602 * @throws DataModelException a violation of data model rules
603 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530604 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530605 public void validateDataOnEntry() throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530606 /*
607 * Module is root in the data model tree, hence there is no entry
608 * validation
609 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530610 }
611
612 /**
613 * Validate the data on exiting the corresponding parse tree node.
614 *
615 * @throws DataModelException a violation of data model rules
616 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530617 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530618 public void validateDataOnExit() throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530619 /*
620 * TODO: perform symbol linking for the imported or included YANG info.
621 * TODO: perform symbol resolution for referred YANG entities.
622 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530623 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530624
625 /**
626 * Generates java code for module.
Bharat saraswal870c56f2016-02-20 21:57:16 +0530627 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530628 * @param codeGenDir code generation directory
629 * @throws IOException when fails to generate the source files
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530630 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530631 @Override
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530632 public void generateJavaCodeEntry(String codeGenDir) throws IOException {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530633 String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
634 getRevision().getRevDate());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530635
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530636 modPkg = JavaIdentifierSyntax.getCamelCase(modPkg);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530637 CachedFileHandle handle = null;
638 try {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530639 FileSystemUtil.createPackage(codeGenDir + modPkg, getName());
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530640 handle = FileSystemUtil.createSourceFiles(modPkg, getName(),
641 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530642 handle.setCodeGenFilePath(codeGenDir);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530643 } catch (IOException e) {
644 throw new IOException("Failed to create the source files.");
645 }
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530646
Bharat saraswal870c56f2016-02-20 21:57:16 +0530647 setFileHandle(handle);
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530648 addLeavesAttributes();
649 addLeafListAttributes();
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530650 }
651
652 @Override
653 public void generateJavaCodeExit() throws IOException {
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530654 getFileHandle().close();
655 return;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530656 }
657
658 /**
659 * Adds leaf attributes in generated files.
660 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530661 private void addLeavesAttributes() {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530662
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530663 List<YangLeaf> leaves = getListOfLeaf();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530664 if (leaves != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530665 for (YangLeaf leaf : leaves) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530666 getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
667 }
668 }
669 }
670
671 /**
672 * Adds leaf list's attributes in generated files.
673 */
674 private void addLeafListAttributes() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530675 List<YangLeafList> leavesList = getListOfLeafList();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530676 if (leavesList != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530677 for (YangLeafList leafList : leavesList) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530678 getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
679 }
680 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530681 }
682
Vinod Kumar S71cba682016-02-25 15:52:16 +0530683 /**
684 * Add a type to resolve the nested references.
685 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530686 * @param node grouping or typedef node which needs to be resolved
687 * @throws DataModelException data model exception
Vinod Kumar S71cba682016-02-25 15:52:16 +0530688 */
689 public static void addToResolveList(YangNode node) throws DataModelException {
690 /* get the module node to add maintain the list of nested reference */
691 YangModule module;
692 YangNode curNode = node;
693 while (curNode.getNodeType() != YangNodeType.MODULE_NODE) {
694 curNode = curNode.getParent();
695 if (curNode == null) {
696 break;
697 }
698 }
699 if (curNode == null) {
700 throw new DataModelException("Datamodel tree is not correct");
701 }
702
703 module = (YangModule) curNode;
704 module.addToNestedReferenceResoulutionList(node);
705 return;
706 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530707
708 @Override
709 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
710 // Asks helper to detect colliding child.
711 detectCollidingChildUtil(identifierName, dataType, this);
712 }
713
714 @Override
715 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
716 // Not required as module doesn't have any parent.
717 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530718}