blob: 1434363670901ea4452b7d2f9645f593ac814ec0 [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
18import java.util.LinkedList;
19import java.util.List;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053020
21import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
23import org.onosproject.yangutils.parser.ParsableDataType;
24import org.onosproject.yangutils.translator.CodeGenerator;
25import org.onosproject.yangutils.utils.io.CachedFileHandle;
26
27/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053028 * Reference:RFC 6020.
29 * The "module" statement defines the module's name,
30 * and groups all statements that belong to the module together. The "module"
31 * statement's argument is the name of the module, followed by a block of
32 * sub statements that hold detailed module information.
33 * The module's sub statements
34 *
35 * +--------------+---------+-------------+-----------------------+
36 * |sub statement | section | cardinality | data model mapping |
37 * +--------------+---------+-------------+-----------------------+
38 * | anyxml | 7.10 | 0..n | not supported |
39 * | augment | 7.15 | 0..n | child nodes |
40 * | choice | 7.9 | 0..n | child nodes |
41 * | contact | 7.1.8 | 0..1 | string |
42 * | container | 7.5 | 0..n | child nodes |
43 * | description | 7.19.3 | 0..1 | string |
44 * | deviation | 7.18.3 | 0..n | TODO |
45 * | extension | 7.17 | 0..n | TODO |
46 * | feature | 7.18.1 | 0..n | TODO |
47 * | grouping | 7.11 | 0..n | child nodes |
48 * | identity | 7.16 | 0..n | TODO |
49 * | import | 7.1.5 | 0..n | list of import info |
50 * | include | 7.1.6 | 0..n | list of include info |
51 * | leaf | 7.6 | 0..n | list of leaf info |
52 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
53 * | list | 7.8 | 0..n | child nodes |
54 * | namespace | 7.1.3 | 1 | string/uri |
55 * | notification | 7.14 | 0..n | TODO |
56 * | organization | 7.1.7 | 0..1 | string |
57 * | prefix | 7.1.4 | 1 | string |
58 * | reference | 7.19.4 | 0..1 | string |
59 * | revision | 7.1.9 | 0..n | revision |
60 * | rpc | 7.13 | 0..n | TODO |
61 * | typedef | 7.3 | 0..n | child nodes |
62 * | uses | 7.12 | 0..n | child nodes |
63 * | YANG-version | 7.1.2 | 0..1 | int |
64 * +--------------+---------+-------------+-----------------------+
65 */
66
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053067/**
68 * Data model node to maintain information defined in YANG module.
69 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +053070public class YangModule extends YangNode
71 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053072
73 /**
74 * Name of the module.
75 */
76 private String name;
77
78 /**
79 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053080 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053081 * The "contact" statement provides contact information for the module. The
82 * argument is a string that is used to specify contact information for the
83 * person or persons to whom technical queries concerning this module should
84 * be sent, such as their name, postal address, telephone number, and
85 * electronic mail address.
86 */
87 private String contact;
88
89 /**
90 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053091 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053092 * The "description" statement takes as an argument a string that contains a
93 * human-readable textual description of this definition. The text is
94 * provided in a language (or languages) chosen by the module developer; for
95 * the sake of interoperability.
96 */
97 private String description;
98
99 /**
100 * List of YANG modules imported.
101 */
102 private List<YangImport> importList;
103
104 /**
105 * List of YANG sub-modules included.
106 */
107 private List<YangInclude> includeList;
108
109 /**
110 * List of leaves at root level in the module.
111 */
112 @SuppressWarnings("rawtypes")
113 private List<YangLeaf> listOfLeaf;
114
115 /**
116 * List of leaf-lists at root level in the module.
117 */
118 @SuppressWarnings("rawtypes")
119 private List<YangLeafList> listOfLeafList;
120
121 /**
122 * Name space of the module.
123 */
124 private YangNameSpace nameSpace;
125
126 /**
127 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530128 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530129 * The "organization" statement defines the party responsible for this
130 * module. The argument is a string that is used to specify a textual
131 * description of the organization(s) under whose auspices this module was
132 * developed.
133 */
134 private String organization;
135
136 /**
137 * Prefix to refer to the objects in module.
138 */
139 private String prefix;
140
141 /**
142 * Reference of the module.
143 */
144 private String reference;
145
146 /**
147 * Revision info of the module.
148 */
149 private YangRevision revision;
150
151 /**
152 * YANG version.
153 */
154 private byte version;
155
156 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530157 * package of the generated java code.
158 */
159 private String pkg;
160
161 /**
162 * Cached Java File Handle.
163 */
164 private CachedFileHandle fileHandle;
165
166 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530167 * Create a YANG node of module type.
168 */
169 public YangModule() {
170 super(YangNodeType.MODULE_NODE);
171 }
172
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530173 /* (non-Javadoc)
174 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530175 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530176 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530177 public String getName() {
178 return name;
179 }
180
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530181 /* (non-Javadoc)
182 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530183 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530184 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530185 public void setName(String moduleName) {
186 name = moduleName;
187 }
188
189 /**
190 * Get the contact details of the module owner.
191 *
192 * @return the contact details of YANG owner.
193 */
194 public String getContact() {
195 return contact;
196 }
197
198 /**
199 * Set the contact details of the module owner.
200 *
201 * @param contact the contact details of YANG owner.
202 */
203 public void setContact(String contact) {
204 this.contact = contact;
205 }
206
207 /**
208 * Get the description of module.
209 *
210 * @return the description of YANG module.
211 */
212 public String getDescription() {
213 return description;
214 }
215
216 /**
217 * Set the description of module.
218 *
219 * @param description set the description of YANG module.
220 */
221 public void setDescription(String description) {
222 this.description = description;
223 }
224
225 /**
226 * Get the list of imported modules.
227 *
228 * @return the list of imported modules.
229 */
230 public List<YangImport> getImportList() {
231 return importList;
232 }
233
234 /**
235 * prevent setting the import list from outside.
236 *
237 * @param importList the import list to set.
238 */
239 private void setImportList(List<YangImport> importList) {
240 this.importList = importList;
241 }
242
243 /**
244 * Add the imported module information to the import list.
245 *
246 * @param importedModule module being imported.
247 */
248 public void addImportedInfo(YangImport importedModule) {
249
250 if (getImportList() == null) {
251 setImportList(new LinkedList<YangImport>());
252 }
253
254 getImportList().add(importedModule);
255
256 return;
257 }
258
259 /**
260 * Get the list of included sub modules.
261 *
262 * @return the included list of sub modules.
263 */
264 public List<YangInclude> getIncludeList() {
265 return includeList;
266 }
267
268 /**
269 * Set the list of included sub modules.
270 *
271 * @param includeList the included list to set.
272 */
273 private void setIncludeList(List<YangInclude> includeList) {
274 this.includeList = includeList;
275 }
276
277 /**
278 * Add the included sub module information to the include list.
279 *
280 * @param includeModule submodule being included.
281 */
282 public void addIncludedInfo(YangInclude includeModule) {
283
284 if (getIncludeList() == null) {
285 setIncludeList(new LinkedList<YangInclude>());
286 }
287
288 getIncludeList().add(includeModule);
289 return;
290 }
291
292 /**
293 * Get the list of leaves in module.
294 *
295 * @return the list of leaves.
296 */
297 @SuppressWarnings("rawtypes")
298 public List<YangLeaf> getListOfLeaf() {
299 return listOfLeaf;
300 }
301
302 /**
303 * Set the list of leaf in module.
304 *
305 * @param leafsList the list of leaf to set.
306 */
307 @SuppressWarnings("rawtypes")
308 private void setListOfLeaf(List<YangLeaf> leafsList) {
309 listOfLeaf = leafsList;
310 }
311
312 /**
313 * Add a leaf in module.
314 *
315 * @param leaf the leaf to be added.
316 */
317 @SuppressWarnings("rawtypes")
318 public void addLeaf(YangLeaf<?> leaf) {
319 if (getListOfLeaf() == null) {
320 setListOfLeaf(new LinkedList<YangLeaf>());
321 }
322
323 getListOfLeaf().add(leaf);
324 }
325
326 /**
327 * Get the list of leaf-list from module.
328 *
329 * @return the list of leaf-list.
330 */
331 @SuppressWarnings("rawtypes")
332 public List<YangLeafList> getListOfLeafList() {
333 return listOfLeafList;
334 }
335
336 /**
337 * Set the list of leaf-list in module.
338 *
339 * @param listOfLeafList the list of leaf-list to set.
340 */
341 @SuppressWarnings("rawtypes")
342 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
343 this.listOfLeafList = listOfLeafList;
344 }
345
346 /**
347 * Add a leaf-list in module.
348 *
349 * @param leafList the leaf-list to be added.
350 */
351 @SuppressWarnings("rawtypes")
352 public void addLeafList(YangLeafList<?> leafList) {
353 if (getListOfLeafList() == null) {
354 setListOfLeafList(new LinkedList<YangLeafList>());
355 }
356
357 getListOfLeafList().add(leafList);
358 }
359
360 /**
361 * Get the name space of module elements.
362 *
363 * @return the nameSpace.
364 */
365 public YangNameSpace getNameSpace() {
366 return nameSpace;
367 }
368
369 /**
370 * Set the name space of module elements.
371 *
372 * @param nameSpace the nameSpace to set.
373 */
374 public void setNameSpace(YangNameSpace nameSpace) {
375 this.nameSpace = nameSpace;
376 }
377
378 /**
379 * Get the modules organization.
380 *
381 * @return the organization.
382 */
383 public String getOrganization() {
384 return organization;
385 }
386
387 /**
388 * Set the modules organization.
389 *
390 * @param org the organization to set.
391 */
392 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530393 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530394 }
395
396 /**
397 * Get the prefix.
398 *
399 * @return the prefix
400 */
401 public String getPrefix() {
402 return prefix;
403 }
404
405 /**
406 * Set the prefix.
407 *
408 * @param prefix the prefix to set.
409 */
410 public void setPrefix(String prefix) {
411 this.prefix = prefix;
412 }
413
414 /**
415 * Get the textual reference.
416 *
417 * @return the reference.
418 */
419 public String getReference() {
420 return reference;
421 }
422
423 /**
424 * Set the textual reference.
425 *
426 * @param reference the reference to set.
427 */
428 public void setReference(String reference) {
429 this.reference = reference;
430 }
431
432 /**
433 * Get the revision.
434 *
435 * @return the revision.
436 */
437 public YangRevision getRevision() {
438 return revision;
439 }
440
441 /**
442 * Set the revision.
443 *
444 * @param revision the revision to set.
445 */
446 public void setRevision(YangRevision revision) {
447 this.revision = revision;
448 }
449
450 /**
451 * Get the version.
452 *
453 * @return the version.
454 */
455 public byte getVersion() {
456 return version;
457 }
458
459 /**
460 * Set the version.
461 *
462 * @param version the version to set.
463 */
464 public void setVersion(byte version) {
465 this.version = version;
466 }
467
468 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530469 * Get the mapped java package.
470 *
471 * @return the java package
472 */
473 @Override
474 public String getPackage() {
475 return pkg;
476 }
477
478 /**
479 * Set the mapped java package.
480 *
481 * @param pcg the package to set
482 */
483 @Override
484 public void setPackage(String pcg) {
485 pkg = pcg;
486 }
487
488 /**
489 * Get the cached file handle.
490 *
491 * @return the fileHandle
492 */
493 public CachedFileHandle getFileHandle() {
494 return fileHandle;
495 }
496
497 /**
498 * Set the cached file handle.
499 *
500 * @param handle the fileHandle to set
501 */
502 public void setFileHandle(CachedFileHandle handle) {
503 fileHandle = handle;
504 }
505
506 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530507 * Returns the type of the parsed data.
508 *
509 * @return returns MODULE_DATA.
510 */
511 public ParsableDataType getParsableDataType() {
512 return ParsableDataType.MODULE_DATA;
513 }
514
515 /**
516 * Validate the data on entering the corresponding parse tree node.
517 *
518 * @throws DataModelException a violation of data model rules
519 */
520 public void validateDataOnEntry() throws DataModelException {
521 // TODO auto-generated method stub, to be implemented by parser
522 }
523
524 /**
525 * Validate the data on exiting the corresponding parse tree node.
526 *
527 * @throws DataModelException a violation of data model rules
528 */
529 public void validateDataOnExit() throws DataModelException {
530 // TODO auto-generated method stub, to be implemented by parser
531 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530532
533 /**
534 * Generates java code for module.
535 */
536 public void generateJavaCodeEntry() {
537 //TODO: autogenerated method stub, to be implemented
538
539 return;
540 }
541
542 /**
543 * Free resources used to generate code.
544 */
545 public void generateJavaCodeExit() {
546 //TODO: autogenerated method stub, to be implemented
547 return;
548 }
549
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530550}