blob: 6e515ad29b5b17102feb98559dd5c99587614062 [file] [log] [blame]
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +05303 *
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 Agrawal0d43bb52016-05-17 18:06:38 +053018import java.util.Iterator;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053019import java.util.LinkedList;
20import java.util.List;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053021import java.util.Set;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053023import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053024import org.onosproject.yangutils.datamodel.utils.Parsable;
25import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S38046502016-03-23 15:30:27 +053026
27import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053028import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053029import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053030
31/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053032 * Reference:RFC 6020.
33 * The "module" statement defines the module's name,
34 * and groups all statements that belong to the module together. The "module"
35 * statement's argument is the name of the module, followed by a block of
36 * sub statements that hold detailed module information.
37 * The module's sub statements
38 *
39 * +--------------+---------+-------------+-----------------------+
40 * |sub statement | section | cardinality | data model mapping |
41 * +--------------+---------+-------------+-----------------------+
42 * | anyxml | 7.10 | 0..n | not supported |
43 * | augment | 7.15 | 0..n | child nodes |
44 * | choice | 7.9 | 0..n | child nodes |
45 * | contact | 7.1.8 | 0..1 | string |
46 * | container | 7.5 | 0..n | child nodes |
47 * | description | 7.19.3 | 0..1 | string |
48 * | deviation | 7.18.3 | 0..n | TODO |
49 * | extension | 7.17 | 0..n | TODO |
50 * | feature | 7.18.1 | 0..n | TODO |
51 * | grouping | 7.11 | 0..n | child nodes |
52 * | identity | 7.16 | 0..n | TODO |
53 * | import | 7.1.5 | 0..n | list of import info |
54 * | include | 7.1.6 | 0..n | list of include info |
55 * | leaf | 7.6 | 0..n | list of leaf info |
56 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
57 * | list | 7.8 | 0..n | child nodes |
58 * | namespace | 7.1.3 | 1 | string/uri |
59 * | notification | 7.14 | 0..n | TODO |
60 * | organization | 7.1.7 | 0..1 | string |
61 * | prefix | 7.1.4 | 1 | string |
62 * | reference | 7.19.4 | 0..1 | string |
63 * | revision | 7.1.9 | 0..n | revision |
64 * | rpc | 7.13 | 0..n | TODO |
65 * | typedef | 7.3 | 0..n | child nodes |
66 * | uses | 7.12 | 0..n | child nodes |
67 * | YANG-version | 7.1.2 | 0..1 | int |
68 * +--------------+---------+-------------+-----------------------+
69 */
70
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053071/**
Bharat saraswald9822e92016-04-05 15:13:44 +053072 * Represents data model node to maintain information defined in YANG module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053073 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053074public class YangModule
75 extends YangNode
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053076 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053077 RpcNotificationContainer, YangFeatureHolder {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053078
Bharat saraswal96dfef02016-06-16 00:29:12 +053079 private static final long serialVersionUID = 806201610L;
80
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053081 /**
82 * Name of the module.
83 */
84 private String name;
85
86 /**
87 * Reference:RFC 6020.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053088 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053089 * The "contact" statement provides contact information for the module. The
90 * argument is a string that is used to specify contact information for the
91 * person or persons to whom technical queries concerning this module should
92 * be sent, such as their name, postal address, telephone number, and
93 * electronic mail address.
94 */
95 private String contact;
96
97 /**
98 * Reference:RFC 6020.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053099 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530100 * The "description" statement takes as an argument a string that contains a
101 * human-readable textual description of this definition. The text is
102 * provided in a language (or languages) chosen by the module developer; for
103 * the sake of interoperability.
104 */
105 private String description;
106
107 /**
108 * List of YANG modules imported.
109 */
110 private List<YangImport> importList;
111
112 /**
113 * List of YANG sub-modules included.
114 */
115 private List<YangInclude> includeList;
116
117 /**
118 * List of leaves at root level in the module.
119 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530120 private List<YangLeaf> listOfLeaf;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530121
122 /**
123 * List of leaf-lists at root level in the module.
124 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530125 private List<YangLeafList> listOfLeafList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530126
127 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530128 * List of feature at root level in the module.
129 */
130 private List<YangFeature> listOfFeature;
131
132 /**
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530133 * Name space of the module.
134 */
135 private YangNameSpace nameSpace;
136
137 /**
138 * Reference:RFC 6020.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530139 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530140 * The "organization" statement defines the party responsible for this
141 * module. The argument is a string that is used to specify a textual
142 * description of the organization(s) under whose auspices this module was
143 * developed.
144 */
145 private String organization;
146
147 /**
148 * Prefix to refer to the objects in module.
149 */
150 private String prefix;
151
152 /**
153 * Reference of the module.
154 */
155 private String reference;
156
157 /**
158 * Revision info of the module.
159 */
160 private YangRevision revision;
161
162 /**
163 * YANG version.
164 */
165 private byte version;
166
Vinod Kumar S71cba682016-02-25 15:52:16 +0530167 /*-
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530168 * Reference RFC 6020.
169 *
Vinod Kumar S71cba682016-02-25 15:52:16 +0530170 * Nested typedefs and groupings.
171 * Typedefs and groupings may appear nested under many YANG statements,
172 * allowing these to be lexically scoped by the hierarchy under which
173 * they appear. This allows types and groupings to be defined near
174 * where they are used, rather than placing them at the top level of the
175 * hierarchy. The close proximity increases readability.
176 *
177 * Scoping also allows types to be defined without concern for naming
178 * conflicts between types in different submodules. Type names can be
179 * specified without adding leading strings designed to prevent name
180 * collisions within large modules.
181 *
182 * Finally, scoping allows the module author to keep types and groupings
183 * private to their module or submodule, preventing their reuse. Since
184 * only top-level types and groupings (i.e., those appearing as
185 * sub-statements to a module or submodule statement) can be used outside
186 * the module or submodule, the developer has more control over what
187 * pieces of their module are presented to the outside world, supporting
188 * the need to hide internal information and maintaining a boundary
189 * between what is shared with the outside world and what is kept
190 * private.
191 *
192 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
193 * type or grouping cannot be defined if a higher level in the schema
194 * hierarchy has a definition with a matching identifier.
195 *
196 * A reference to an unprefixed type or grouping, or one which uses the
197 * prefix of the current module, is resolved by locating the closest
198 * matching "typedef" or "grouping" statement among the immediate
199 * sub-statements of each ancestor statement.
200 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530201 private List<YangResolutionInfo> derivedTypeResolutionList;
202
203 /**
204 * uses resolution list.
205 */
206 private List<YangResolutionInfo> usesResolutionList;
Vinod Kumar S71cba682016-02-25 15:52:16 +0530207
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530208 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530209 * if-feature resolution list.
210 */
211 private List<YangResolutionInfo> ifFeatureResolutionList;
212
213 /**
janani be18b5342016-07-13 21:06:41 +0530214 * leafref resolution list.
215 */
216 private List<YangResolutionInfo> leafrefResolutionList;
217
218 /**
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530219 * base resolution list.
220 */
221 private List<YangResolutionInfo> baseResolutionList;
222
223 /**
224 * identityref resolution list.
225 */
226 private List<YangResolutionInfo> identityrefResolutionList;
227
228
229 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530230 * Creates a YANG node of module type.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530231 */
232 public YangModule() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530233
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530234 super(YangNodeType.MODULE_NODE);
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530235 derivedTypeResolutionList = new LinkedList<>();
236 usesResolutionList = new LinkedList<>();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530237 ifFeatureResolutionList = new LinkedList<>();
janani be18b5342016-07-13 21:06:41 +0530238 leafrefResolutionList = new LinkedList<>();
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530239 baseResolutionList = new LinkedList<>();
240 identityrefResolutionList = new LinkedList<>();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530241 importList = new LinkedList<YangImport>();
242 includeList = new LinkedList<YangInclude>();
243 listOfLeaf = new LinkedList<YangLeaf>();
244 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530245 }
246
Vinod Kumar S71cba682016-02-25 15:52:16 +0530247 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530248 * Returns name of the module.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530249 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530250 * @return module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530251 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530252 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530253 public String getName() {
254 return name;
255 }
256
Vinod Kumar S71cba682016-02-25 15:52:16 +0530257 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530258 * Sets module name.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530259 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530260 * @param moduleName module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530261 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530263 public void setName(String moduleName) {
264 name = moduleName;
265 }
266
267 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530268 * Returns the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530269 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530270 * @return the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530271 */
272 public String getContact() {
273 return contact;
274 }
275
276 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530277 * Sets the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530278 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530279 * @param contact the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530280 */
281 public void setContact(String contact) {
282 this.contact = contact;
283 }
284
285 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530286 * Returns the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530287 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530288 * @return the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530289 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530290 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530291 public String getDescription() {
292 return description;
293 }
294
295 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530296 * Sets the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530297 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530298 * @param description set the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530299 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530300 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530301 public void setDescription(String description) {
302 this.description = description;
303 }
304
305 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530306 * Returns the list of imported modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530307 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530308 * @return the list of imported modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530309 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530310 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530311 public List<YangImport> getImportList() {
312 return importList;
313 }
314
315 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530316 * Adds the imported module information to the import list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530317 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530318 * @param importedModule module being imported
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530319 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530320 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530321 public void addToImportList(YangImport importedModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530322 getImportList().add(importedModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530323 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530324
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530325 @Override
326 public void setImportList(List<YangImport> importList) {
327 this.importList = importList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530328 }
329
330 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530331 * Returns the list of included sub modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530332 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530333 * @return the included list of sub modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530334 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530335 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530336 public List<YangInclude> getIncludeList() {
337 return includeList;
338 }
339
340 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530341 * Adds the included sub module information to the include list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530342 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530343 * @param includeModule submodule being included
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530344 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530345 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530346 public void addToIncludeList(YangInclude includeModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530347 getIncludeList().add(includeModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530348 }
349
350 @Override
351 public void setIncludeList(List<YangInclude> includeList) {
352 this.includeList = includeList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530353 }
354
355 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530356 * Returns the list of leaves in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530357 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530358 * @return the list of leaves
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 List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530362 return listOfLeaf;
363 }
364
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530365 @Override
366 public void setListOfLeaf(List<YangLeaf> leafsList) {
367 listOfLeaf = leafsList;
368 }
369
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530370 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530371 * Adds a leaf in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530372 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530373 * @param leaf the leaf to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530374 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530375 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530376 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530377 getListOfLeaf().add(leaf);
378 }
379
380 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530381 * Returns the list of leaf-list from module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530382 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530383 * @return the list of leaf-list
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530384 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530385 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530386 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530387 return listOfLeafList;
388 }
389
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530390 @Override
391 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
392 this.listOfLeafList = listOfLeafList;
393 }
394
395
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530396 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530397 * Adds a leaf-list in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530398 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530399 * @param leafList the leaf-list to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530400 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530401 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530402 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530403 getListOfLeafList().add(leafList);
404 }
405
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530406 @Override
407 public List<YangFeature> getFeatureList() {
408 return listOfFeature;
409 }
410
411 @Override
412 public void addFeatureList(YangFeature feature) {
413 if (getFeatureList() == null) {
414 setListOfFeature(new LinkedList<>());
415 }
416 getFeatureList().add(feature);
417 }
418
419 @Override
420 public void setListOfFeature(List<YangFeature> listOfFeature) {
421 this.listOfFeature = listOfFeature;
422 }
423
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530424 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530425 * Returns the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530426 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530427 * @return the nameSpace
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530428 */
429 public YangNameSpace getNameSpace() {
430 return nameSpace;
431 }
432
433 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530434 * Sets the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530435 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530436 * @param nameSpace the nameSpace to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530437 */
438 public void setNameSpace(YangNameSpace nameSpace) {
439 this.nameSpace = nameSpace;
440 }
441
442 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530443 * Returns the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530444 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530445 * @return the organization
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530446 */
447 public String getOrganization() {
448 return organization;
449 }
450
451 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530452 * Sets the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530453 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530454 * @param org the organization to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530455 */
456 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530457 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530458 }
459
460 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530461 * Returns the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530462 *
463 * @return the prefix
464 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530465 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530466 public String getPrefix() {
467 return prefix;
468 }
469
470 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530471 * Sets the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530472 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530473 * @param prefix the prefix to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530474 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530475 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530476 public void setPrefix(String prefix) {
477 this.prefix = prefix;
478 }
479
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530480 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530481 public void resolveSelfFileLinking(ResolvableType type)
482 throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530483 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530484 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530485 // Resolve linking for a resolution list.
486 resolveLinkingForResolutionList(resolutionList, this);
487 }
488
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530489 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530490 public void resolveInterFileLinking(ResolvableType type)
491 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530492 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530493 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530494 // Resolve linking for a resolution list.
495 linkInterFileReferences(resolutionList, this);
496 }
497
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530498 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530499 * Returns the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530500 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530501 * @return the reference
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530502 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530503 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530504 public String getReference() {
505 return reference;
506 }
507
508 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530509 * Sets the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530510 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530511 * @param reference the reference to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530512 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530513 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530514 public void setReference(String reference) {
515 this.reference = reference;
516 }
517
518 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530519 * Returns the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530520 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530521 * @return the revision
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530522 */
523 public YangRevision getRevision() {
524 return revision;
525 }
526
527 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530528 * Sets the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530529 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530530 * @param revision the revision to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530531 */
532 public void setRevision(YangRevision revision) {
533 this.revision = revision;
534 }
535
536 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530537 * Returns the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530538 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530539 * @return the version
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530540 */
541 public byte getVersion() {
542 return version;
543 }
544
545 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530546 * Sets the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530547 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530548 * @param version the version to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530549 */
550 public void setVersion(byte version) {
551 this.version = version;
552 }
553
554 /**
555 * Returns the type of the parsed data.
556 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530557 * @return returns MODULE_DATA
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530558 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530559 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530560 public YangConstructType getYangConstructType() {
561 return YangConstructType.MODULE_DATA;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530562 }
563
564 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530565 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530566 *
567 * @throws DataModelException a violation of data model rules
568 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530569 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530570 public void validateDataOnEntry()
571 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530572 /*
573 * Module is root in the data model tree, hence there is no entry
574 * validation
575 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530576 }
577
578 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530579 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530580 *
581 * @throws DataModelException a violation of data model rules
582 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530583 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530584 public void validateDataOnExit()
585 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530586 /*
587 * TODO: perform symbol linking for the imported or included YANG info.
588 * TODO: perform symbol resolution for referred YANG entities.
589 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530590 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530591
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530592 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530593 public void detectCollidingChild(String identifierName, YangConstructType dataType)
594 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530595 // Asks helper to detect colliding child.
596 detectCollidingChildUtil(identifierName, dataType, this);
597 }
598
599 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530600 public void detectSelfCollision(String identifierName, YangConstructType dataType)
601 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530602 // Not required as module doesn't have any parent.
603 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530604
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530605 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530606 public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
607 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
608 return derivedTypeResolutionList;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530609 } else if (type == ResolvableType.YANG_USES) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530610 return usesResolutionList;
janani be18b5342016-07-13 21:06:41 +0530611 } else if (type == ResolvableType.YANG_IF_FEATURE) {
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530612 return ifFeatureResolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530613 } else if (type == ResolvableType.YANG_LEAFREF) {
janani be18b5342016-07-13 21:06:41 +0530614 return leafrefResolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530615 } else if (type == ResolvableType.YANG_BASE) {
616 return baseResolutionList;
617 } else {
618 return identityrefResolutionList;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530619 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530620 }
621
622 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530623 public void addToResolutionList(YangResolutionInfo resolutionInfo,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530624 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530625 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
626 derivedTypeResolutionList.add(resolutionInfo);
627 } else if (type == ResolvableType.YANG_USES) {
628 usesResolutionList.add(resolutionInfo);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530629 } else if (type == ResolvableType.YANG_IF_FEATURE) {
630 ifFeatureResolutionList.add(resolutionInfo);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530631 } else if (type == ResolvableType.YANG_LEAFREF) {
janani be18b5342016-07-13 21:06:41 +0530632 leafrefResolutionList.add(resolutionInfo);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530633 } else if (type == ResolvableType.YANG_BASE) {
634 baseResolutionList.add(resolutionInfo);
635 } else if (type == ResolvableType.YANG_IDENTITYREF) {
636 identityrefResolutionList.add(resolutionInfo);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530637 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530638 }
639
640 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530641 public void setResolutionList(List<YangResolutionInfo> resolutionList,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530642 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530643 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
644 derivedTypeResolutionList = resolutionList;
645 } else if (type == ResolvableType.YANG_USES) {
646 usesResolutionList = resolutionList;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530647 } else if (type == ResolvableType.YANG_IF_FEATURE) {
648 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
janani be18b5342016-07-13 21:06:41 +0530649 } else if (type == ResolvableType.YANG_LEAFREF) {
650 leafrefResolutionList = resolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530651 } else if (type == ResolvableType.YANG_BASE) {
652 baseResolutionList = resolutionList;
653 } else if (type == ResolvableType.YANG_IDENTITYREF) {
654 identityrefResolutionList = resolutionList;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530655 }
656
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530657 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530658
659 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530660 public void addReferencesToImportList(Set<YangNode> yangNodeSet)
661 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530662 Iterator<YangImport> importInfoIterator = getImportList().iterator();
663 // Run through the imported list to add references.
664 while (importInfoIterator.hasNext()) {
665 YangImport yangImport = importInfoIterator.next();
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530666 yangImport.addReferenceToImport(yangNodeSet);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530667 }
668 }
669
670 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530671 public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
672 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530673 Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
674 // Run through the included list to add references.
675 while (includeInfoIterator.hasNext()) {
676 YangInclude yangInclude = includeInfoIterator.next();
677 YangSubModule subModule = null;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530678 subModule = yangInclude.addReferenceToInclude(yangNodeSet);
679
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530680 // Check if the referred sub-modules parent is self
681 if (!(subModule.getBelongsTo().getModuleNode() == this)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530682 yangInclude.reportIncludeError();
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530683 }
684 }
685 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530686}