blob: f8d4606a9d8c69dffd0c3a002e1e15cab94336fc [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;
Vinod Kumar S38046502016-03-23 15:30:27 +053020import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21import org.onosproject.yangutils.parser.Parsable;
22import org.onosproject.yangutils.utils.YangConstructType;
23
24import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053025import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
Vinod Kumar S38046502016-03-23 15:30:27 +053026
Vinod Kumar S67e7be62016-02-11 20:13:28 +053027/*
28 * Reference RFC 6020.
29 *
30 * While the primary unit in YANG is a module, a YANG module can itself
31 * be constructed out of several submodules. Submodules allow a module
32 * designer to split a complex model into several pieces where all the
33 * submodules contribute to a single namespace, which is defined by the
34 * module that includes the submodules.
35 *
36 * The "submodule" statement defines the submodule's name, and groups
37 * all statements that belong to the submodule together. The
38 * "submodule" statement's argument is the name of the submodule,
39 * followed by a block of sub-statements that hold detailed submodule
40 * information.
41 *
42 * The submodule's sub-statements
43 *
44 * +--------------+---------+-------------+------------------+
45 * | substatement | section | cardinality |data model mapping|
46 * +--------------+---------+-------------+------------------+
47 * | anyxml | 7.10 | 0..n | - not supported |
48 * | augment | 7.15 | 0..n | - child nodes |
49 * | belongs-to | 7.2.2 | 1 | - YangBelongsTo |
50 * | choice | 7.9 | 0..n | - child nodes |
51 * | contact | 7.1.8 | 0..1 | - string |
52 * | container | 7.5 | 0..n | - child nodes |
53 * | description | 7.19.3 | 0..1 | - string |
54 * | deviation | 7.18.3 | 0..n | - TODO |
55 * | extension | 7.17 | 0..n | - TODO |
56 * | feature | 7.18.1 | 0..n | - TODO |
57 * | grouping | 7.11 | 0..n | - child nodes |
58 * | identity | 7.16 | 0..n | - TODO |
59 * | import | 7.1.5 | 0..n | - YangImport |
60 * | include | 7.1.6 | 0..n | - YangInclude |
61 * | leaf | 7.6 | 0..n | - YangLeaf |
62 * | leaf-list | 7.7 | 0..n | - YangLeafList |
63 * | list | 7.8 | 0..n | - child nodes |
64 * | notification | 7.14 | 0..n | - TODO |
65 * | organization | 7.1.7 | 0..1 | - string |
66 * | reference | 7.19.4 | 0..1 | - string |
67 * | revision | 7.1.9 | 0..n | - string |
68 * | rpc | 7.13 | 0..n | - TODO |
69 * | typedef | 7.3 | 0..n | - child nodes |
70 * | uses | 7.12 | 0..n | - child nodes |
71 * | YANG-version | 7.1.2 | 0..1 | - int |
72 * +--------------+---------+-------------+------------------+
73 */
74/**
75 * Data model node to maintain information defined in YANG sub-module.
76 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053077public class YangSubModule extends YangNode
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053078 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053079
80 /**
81 * Name of sub module.
82 */
83 private String name;
84
85 /**
86 * Module to which it belongs to.
87 */
88 private YangBelongsTo belongsTo;
89
90 /**
91 * Reference RFC 6020.
92 *
93 * The "contact" statement provides contact information for the module. The
94 * argument is a string that is used to specify contact information for the
95 * person or persons to whom technical queries concerning this module should
96 * be sent, such as their name, postal address, telephone number, and
97 * electronic mail address.
98 */
99 private String contact;
100
101 /**
102 * Description.
103 */
104 private String description;
105
106 /**
107 * List of YANG modules imported.
108 */
109 private List<YangImport> importList;
110
111 /**
112 * List of YANG sub-modules included.
113 */
114 private List<YangInclude> includeList;
115
116 /**
117 * List of leaves at root level in the sub-module.
118 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530119 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530120
121 /**
122 * List of leaf-lists at root level in the sub-module.
123 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530124 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530125
126 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530127 * Organization owner of the sub-module.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530128 */
129 private String organization;
130
131 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530132 * Reference of the sub-module.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530133 */
134 private String reference;
135
136 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530137 * Revision info of the sub-module.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530138 */
139 private YangRevision revision;
140
141 /**
142 * YANG version.
143 */
144 private byte version;
145
146 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530147 * Prefix of parent module.
148 */
149 private String prefix;
150 /*-
151 * Reference RFC 6020.
152 *
153 * Nested typedefs and groupings.
154 * Typedefs and groupings may appear nested under many YANG statements,
155 * allowing these to be lexically scoped by the hierarchy under which
156 * they appear. This allows types and groupings to be defined near
157 * where they are used, rather than placing them at the top level of the
158 * hierarchy. The close proximity increases readability.
159 *
160 * Scoping also allows types to be defined without concern for naming
161 * conflicts between types in different submodules. Type names can be
162 * specified without adding leading strings designed to prevent name
163 * collisions within large modules.
164 *
165 * Finally, scoping allows the module author to keep types and groupings
166 * private to their module or submodule, preventing their reuse. Since
167 * only top-level types and groupings (i.e., those appearing as
168 * sub-statements to a module or submodule statement) can be used outside
169 * the module or submodule, the developer has more control over what
170 * pieces of their module are presented to the outside world, supporting
171 * the need to hide internal information and maintaining a boundary
172 * between what is shared with the outside world and what is kept
173 * private.
174 *
175 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
176 * type or grouping cannot be defined if a higher level in the schema
177 * hierarchy has a definition with a matching identifier.
178 *
179 * A reference to an unprefixed type or grouping, or one which uses the
180 * prefix of the current module, is resolved by locating the closest
181 * matching "typedef" or "grouping" statement among the immediate
182 * sub-statements of each ancestor statement.
183 */
184 private List<YangResolutionInfo> unresolvedResolutionList;
185 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530186 * Create a sub module node.
187 */
188 public YangSubModule() {
189 super(YangNodeType.SUB_MODULE_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530190 unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
191 importList = new LinkedList<YangImport>();
192 includeList = new LinkedList<YangInclude>();
193 listOfLeaf = new LinkedList<YangLeaf>();
194 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530195 }
196
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530197 /**
198 * Get the YANG name of the sub module.
199 *
200 * @return YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530201 */
202 @Override
203 public String getName() {
204 return name;
205 }
206
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530207 /**
208 * Set YANG name of the sub module.
209 *
210 * @param subModuleName YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530211 */
212 @Override
213 public void setName(String subModuleName) {
214 name = subModuleName;
215 }
216
217 /**
218 * Get the module info.
219 *
220 * @return the belongs to info
221 */
222 public YangBelongsTo getBelongsTo() {
223 return belongsTo;
224 }
225
226 /**
227 * Set the module info.
228 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530229 * @param belongsTo module info to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530230 */
231 public void setBelongsTo(YangBelongsTo belongsTo) {
232 this.belongsTo = belongsTo;
233 }
234
235 /**
236 * Get the contact.
237 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530238 * @return the contact
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530239 */
240 public String getContact() {
241 return contact;
242 }
243
244 /**
245 * Set the contact.
246 *
247 * @param contact the contact to set
248 */
249 public void setContact(String contact) {
250 this.contact = contact;
251 }
252
253 /**
254 * Get the description.
255 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530256 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530257 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530258 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530259 public String getDescription() {
260 return description;
261 }
262
263 /**
264 * Set the description.
265 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530266 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530267 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530268 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530269 public void setDescription(String description) {
270 this.description = description;
271 }
272
273 /**
274 * Get the list of imported modules.
275 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530276 * @return the list of imported modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530277 */
278 public List<YangImport> getImportList() {
279 return importList;
280 }
281
282 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530283 * Add the imported module information to the import list.
284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @param importedModule module being imported
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530286 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530287 public void addToImportList(YangImport importedModule) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530288 getImportList().add(importedModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530289 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530290
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530291 @Override
292 public void setImportList(List<YangImport> importList) {
293 this.importList = importList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530294 }
295
296 /**
297 * Get the list of included sub modules.
298 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530299 * @return the included list of sub modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530300 */
301 public List<YangInclude> getIncludeList() {
302 return includeList;
303 }
304
305 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530306 * Add the included sub module information to the include list.
307 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530308 * @param includeModule submodule being included
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530309 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530310 public void addToIncludeList(YangInclude includeModule) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530311 getIncludeList().add(includeModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530312 }
313
314 @Override
315 public void setIncludeList(List<YangInclude> includeList) {
316 this.includeList = includeList;
317 }
318
319 @Override
320 public String getPrefix() {
321 return prefix;
322 }
323
324 @Override
325 public void setPrefix(String prefix) {
326 this.prefix = prefix;
327 }
328
329 @Override
330 public void resolveSelfFileLinking() throws DataModelException {
331 // Get the list to be resolved.
332 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
333 // Resolve linking for a resolution list.
334 resolveLinkingForResolutionList(resolutionList, this);
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530335 }
336
337 /**
338 * Get the list of leaves.
339 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530340 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530341 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530342 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530343 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530344 return listOfLeaf;
345 }
346
347 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530348 * Add a leaf.
349 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530350 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530351 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530352 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530353 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530354 getListOfLeaf().add(leaf);
355 }
356
357 /**
358 * Get the list of leaf-list.
359 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530360 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530361 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530362 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530363 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530364 return listOfLeafList;
365 }
366
367 /**
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530368 * Add a leaf-list.
369 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530370 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530371 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530372 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530373 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530374 getListOfLeafList().add(leafList);
375 }
376
377 /**
378 * Get the sub-modules organization.
379 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530380 * @return the organization
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530381 */
382 public String getOrganization() {
383 return organization;
384 }
385
386 /**
387 * Set the sub-modules organization.
388 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530389 * @param org the organization to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530390 */
391 public void setOrganization(String org) {
392 organization = org;
393 }
394
395 /**
396 * Get the textual reference.
397 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530398 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530399 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530400 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530401 public String getReference() {
402 return reference;
403 }
404
405 /**
406 * Set the textual reference.
407 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530408 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530409 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530410 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530411 public void setReference(String reference) {
412 this.reference = reference;
413 }
414
415 /**
416 * Get the revision.
417 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530418 * @return the revision
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530419 */
420 public YangRevision getRevision() {
421 return revision;
422 }
423
424 /**
425 * Set the revision.
426 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530427 * @param revision the revision to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530428 */
429 public void setRevision(YangRevision revision) {
430 this.revision = revision;
431 }
432
433 /**
434 * Get the version.
435 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530436 * @return the version
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530437 */
438 public byte getVersion() {
439 return version;
440 }
441
442 /**
443 * Set the version.
444 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530445 * @param version the version to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530446 */
447 public void setVersion(byte version) {
448 this.version = version;
449 }
450
451 /**
452 * Returns the type of the parsed data.
453 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530454 * @return returns SUB_MODULE_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530455 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530456 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530457 public YangConstructType getYangConstructType() {
458 return YangConstructType.SUB_MODULE_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530459 }
460
461 /**
462 * Validate the data on entering the corresponding parse tree node.
463 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530464 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530465 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530466 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530467 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 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530474 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530475 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530476 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530477 public void validateDataOnExit() throws DataModelException {
478 // TODO auto-generated method stub, to be implemented by parser
479 }
480
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530481 @Override
482 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
483 // Asks helper to detect colliding child.
484 detectCollidingChildUtil(identifierName, dataType, this);
485 }
486
487 @Override
488 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
489 // Not required as module doesn't have any parent.
490 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530491
492 @Override
493 public List<YangResolutionInfo> getUnresolvedResolutionList() {
494 return unresolvedResolutionList;
495 }
496
497 @Override
498 public void addToResolutionList(YangResolutionInfo resolutionInfo) {
499 this.unresolvedResolutionList.add(resolutionInfo);
500 }
501
502 @Override
503 public void setResolutionList(List<YangResolutionInfo> resolutionList) {
504 this.unresolvedResolutionList = resolutionList;
505 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530506}