blob: 09e1a4dae282102ff4658c30d1be02b8b3ee727d [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;
20
Vinod Kumar S38046502016-03-23 15:30:27 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
23import org.onosproject.yangutils.utils.YangConstructType;
24
25import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26
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 Agrawal8e8770a2016-02-27 03:57:50 +053078 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector {
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 /**
127 * organization owner of the sub-module.
128 */
129 private String organization;
130
131 /**
132 * reference of the sub-module.
133 */
134 private String reference;
135
136 /**
137 * revision info of the sub-module.
138 */
139 private YangRevision revision;
140
141 /**
142 * YANG version.
143 */
144 private byte version;
145
146 /**
147 * Create a sub module node.
148 */
149 public YangSubModule() {
150 super(YangNodeType.SUB_MODULE_NODE);
151 }
152
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530153 /**
154 * Get the YANG name of the sub module.
155 *
156 * @return YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530157 */
158 @Override
159 public String getName() {
160 return name;
161 }
162
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530163 /**
164 * Set YANG name of the sub module.
165 *
166 * @param subModuleName YANG name of the sub module
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530167 */
168 @Override
169 public void setName(String subModuleName) {
170 name = subModuleName;
171 }
172
173 /**
174 * Get the module info.
175 *
176 * @return the belongs to info
177 */
178 public YangBelongsTo getBelongsTo() {
179 return belongsTo;
180 }
181
182 /**
183 * Set the module info.
184 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530185 * @param belongsTo module info to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530186 */
187 public void setBelongsTo(YangBelongsTo belongsTo) {
188 this.belongsTo = belongsTo;
189 }
190
191 /**
192 * Get the contact.
193 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530194 * @return the contact
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530195 */
196 public String getContact() {
197 return contact;
198 }
199
200 /**
201 * Set the contact.
202 *
203 * @param contact the contact to set
204 */
205 public void setContact(String contact) {
206 this.contact = contact;
207 }
208
209 /**
210 * Get the description.
211 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530212 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530213 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530214 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530215 public String getDescription() {
216 return description;
217 }
218
219 /**
220 * Set the description.
221 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530222 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530223 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530224 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530225 public void setDescription(String description) {
226 this.description = description;
227 }
228
229 /**
230 * Get the list of imported modules.
231 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530232 * @return the list of imported modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530233 */
234 public List<YangImport> getImportList() {
235 return importList;
236 }
237
238 /**
239 * prevent setting the import list from outside.
240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @param importList the import list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530242 */
243 private void setImportList(List<YangImport> importList) {
244 this.importList = importList;
245 }
246
247 /**
248 * Add the imported module information to the import list.
249 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530250 * @param importedModule module being imported
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530251 */
252 public void addImportedInfo(YangImport importedModule) {
253
254 if (getImportList() == null) {
255 setImportList(new LinkedList<YangImport>());
256 }
257
258 getImportList().add(importedModule);
259
260 return;
261 }
262
263 /**
264 * Get the list of included sub modules.
265 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530266 * @return the included list of sub modules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530267 */
268 public List<YangInclude> getIncludeList() {
269 return includeList;
270 }
271
272 /**
273 * Set the list of included sub modules.
274 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530275 * @param includeList the included list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530276 */
277 private void setIncludeList(List<YangInclude> includeList) {
278 this.includeList = includeList;
279 }
280
281 /**
282 * Add the included sub module information to the include list.
283 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530284 * @param includeModule submodule being included
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530285 */
286 public void addIncludedInfo(YangInclude includeModule) {
287
288 if (getIncludeList() == null) {
289 setIncludeList(new LinkedList<YangInclude>());
290 }
291
292 getIncludeList().add(includeModule);
293 return;
294 }
295
296 /**
297 * Get the list of leaves.
298 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530299 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530300 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530301 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530302 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530303 return listOfLeaf;
304 }
305
306 /**
307 * Set the list of leaves.
308 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530309 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530310 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530311 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530312 listOfLeaf = leafsList;
313 }
314
315 /**
316 * Add a leaf.
317 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530318 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530319 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530320 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530321 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530322 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530323 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530324 }
325
326 getListOfLeaf().add(leaf);
327 }
328
329 /**
330 * Get the list of leaf-list.
331 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530332 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530333 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530334 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530335 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530336 return listOfLeafList;
337 }
338
339 /**
340 * Set the list of leaf-list.
341 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530342 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530343 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530344 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530345 this.listOfLeafList = listOfLeafList;
346 }
347
348 /**
349 * Add a leaf-list.
350 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530351 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530352 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530353 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530354 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530355 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530356 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530357 }
358
359 getListOfLeafList().add(leafList);
360 }
361
362 /**
363 * Get the sub-modules organization.
364 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530365 * @return the organization
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530366 */
367 public String getOrganization() {
368 return organization;
369 }
370
371 /**
372 * Set the sub-modules organization.
373 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530374 * @param org the organization to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530375 */
376 public void setOrganization(String org) {
377 organization = org;
378 }
379
380 /**
381 * Get the textual reference.
382 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530383 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530384 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530385 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530386 public String getReference() {
387 return reference;
388 }
389
390 /**
391 * Set the textual reference.
392 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530393 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530394 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530395 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530396 public void setReference(String reference) {
397 this.reference = reference;
398 }
399
400 /**
401 * Get the revision.
402 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530403 * @return the revision
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530404 */
405 public YangRevision getRevision() {
406 return revision;
407 }
408
409 /**
410 * Set the revision.
411 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530412 * @param revision the revision to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530413 */
414 public void setRevision(YangRevision revision) {
415 this.revision = revision;
416 }
417
418 /**
419 * Get the version.
420 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530421 * @return the version
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530422 */
423 public byte getVersion() {
424 return version;
425 }
426
427 /**
428 * Set the version.
429 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530430 * @param version the version to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530431 */
432 public void setVersion(byte version) {
433 this.version = version;
434 }
435
436 /**
437 * Returns the type of the parsed data.
438 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530439 * @return returns SUB_MODULE_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530440 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530441 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530442 public YangConstructType getYangConstructType() {
443 return YangConstructType.SUB_MODULE_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530444 }
445
446 /**
447 * Validate the data on entering the corresponding parse tree node.
448 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530449 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530450 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530451 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530452 public void validateDataOnEntry() throws DataModelException {
453 // TODO auto-generated method stub, to be implemented by parser
454 }
455
456 /**
457 * Validate the data on exiting the corresponding parse tree node.
458 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530459 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530460 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530461 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530462 public void validateDataOnExit() throws DataModelException {
463 // TODO auto-generated method stub, to be implemented by parser
464 }
465
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530466 @Override
467 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
468 // Asks helper to detect colliding child.
469 detectCollidingChildUtil(identifierName, dataType, this);
470 }
471
472 @Override
473 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
474 // Not required as module doesn't have any parent.
475 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530476}