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