blob: 81bbd41ccd26560da50eb461d70ccd92c8c9d79c [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 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530204 * Uses resolution list.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530205 */
206 private List<YangResolutionInfo> usesResolutionList;
Vinod Kumar S71cba682016-02-25 15:52:16 +0530207
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530208 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530209 * If-feature resolution list.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530210 */
211 private List<YangResolutionInfo> ifFeatureResolutionList;
212
213 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530214 * Leafref resolution list.
janani be18b5342016-07-13 21:06:41 +0530215 */
216 private List<YangResolutionInfo> leafrefResolutionList;
217
218 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530219 * Base resolution list.
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530220 */
221 private List<YangResolutionInfo> baseResolutionList;
222
223 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530224 * Identityref resolution list.
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530225 */
226 private List<YangResolutionInfo> identityrefResolutionList;
227
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530228 /**
229 * Augment resolution list.
230 */
231 private List<YangResolutionInfo> augmentResolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530232
233 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530234 * Creates a YANG node of module type.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530235 */
236 public YangModule() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530237
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530238 super(YangNodeType.MODULE_NODE);
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530239 derivedTypeResolutionList = new LinkedList<>();
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530240 augmentResolutionList = new LinkedList<>();
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530241 usesResolutionList = new LinkedList<>();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530242 ifFeatureResolutionList = new LinkedList<>();
janani be18b5342016-07-13 21:06:41 +0530243 leafrefResolutionList = new LinkedList<>();
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530244 baseResolutionList = new LinkedList<>();
245 identityrefResolutionList = new LinkedList<>();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530246 importList = new LinkedList<YangImport>();
247 includeList = new LinkedList<YangInclude>();
248 listOfLeaf = new LinkedList<YangLeaf>();
249 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530250 }
251
Vinod Kumar S71cba682016-02-25 15:52:16 +0530252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Returns name of the module.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530254 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530255 * @return module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530256 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530257 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530258 public String getName() {
259 return name;
260 }
261
Vinod Kumar S71cba682016-02-25 15:52:16 +0530262 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530263 * Sets module name.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530264 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530265 * @param moduleName module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530266 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530267 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530268 public void setName(String moduleName) {
269 name = moduleName;
270 }
271
272 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530273 * Returns the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530274 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530275 * @return the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530276 */
277 public String getContact() {
278 return contact;
279 }
280
281 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530282 * Sets the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530283 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530284 * @param contact the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530285 */
286 public void setContact(String contact) {
287 this.contact = contact;
288 }
289
290 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530291 * Returns the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530292 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530293 * @return the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530294 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530295 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530296 public String getDescription() {
297 return description;
298 }
299
300 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530301 * Sets the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530302 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530303 * @param description set the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530304 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530305 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530306 public void setDescription(String description) {
307 this.description = description;
308 }
309
310 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530311 * Returns the list of imported modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530312 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530313 * @return the list of imported modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530314 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530315 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530316 public List<YangImport> getImportList() {
317 return importList;
318 }
319
320 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530321 * Adds the imported module information to the import list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530322 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530323 * @param importedModule module being imported
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530324 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530325 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530326 public void addToImportList(YangImport importedModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530327 getImportList().add(importedModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530328 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530329
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530330 @Override
331 public void setImportList(List<YangImport> importList) {
332 this.importList = importList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530333 }
334
335 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530336 * Returns the list of included sub modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530337 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530338 * @return the included list of sub modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530339 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530340 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530341 public List<YangInclude> getIncludeList() {
342 return includeList;
343 }
344
345 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530346 * Adds the included sub module information to the include list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530347 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530348 * @param includeModule submodule being included
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530349 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530350 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530351 public void addToIncludeList(YangInclude includeModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530352 getIncludeList().add(includeModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530353 }
354
355 @Override
356 public void setIncludeList(List<YangInclude> includeList) {
357 this.includeList = includeList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530358 }
359
360 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530361 * Returns the list of leaves in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530362 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530363 * @return the list of leaves
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530364 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530365 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530366 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530367 return listOfLeaf;
368 }
369
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530370 @Override
371 public void setListOfLeaf(List<YangLeaf> leafsList) {
372 listOfLeaf = leafsList;
373 }
374
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530375 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530376 * Adds a leaf in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530377 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530378 * @param leaf the leaf to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530379 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530380 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530381 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530382 getListOfLeaf().add(leaf);
383 }
384
385 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530386 * Returns the list of leaf-list from module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530387 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530388 * @return the list of leaf-list
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530389 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530390 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530391 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530392 return listOfLeafList;
393 }
394
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530395 @Override
396 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
397 this.listOfLeafList = listOfLeafList;
398 }
399
400
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530401 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530402 * Adds a leaf-list in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530403 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530404 * @param leafList the leaf-list to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530405 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530406 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530407 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530408 getListOfLeafList().add(leafList);
409 }
410
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530411 @Override
412 public List<YangFeature> getFeatureList() {
413 return listOfFeature;
414 }
415
416 @Override
417 public void addFeatureList(YangFeature feature) {
418 if (getFeatureList() == null) {
419 setListOfFeature(new LinkedList<>());
420 }
421 getFeatureList().add(feature);
422 }
423
424 @Override
425 public void setListOfFeature(List<YangFeature> listOfFeature) {
426 this.listOfFeature = listOfFeature;
427 }
428
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530429 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530430 * Returns the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530431 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530432 * @return the nameSpace
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530433 */
434 public YangNameSpace getNameSpace() {
435 return nameSpace;
436 }
437
438 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530439 * Sets the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530440 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530441 * @param nameSpace the nameSpace to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530442 */
443 public void setNameSpace(YangNameSpace nameSpace) {
444 this.nameSpace = nameSpace;
445 }
446
447 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530448 * Returns the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530449 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530450 * @return the organization
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530451 */
452 public String getOrganization() {
453 return organization;
454 }
455
456 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530457 * Sets the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530458 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530459 * @param org the organization to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530460 */
461 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530462 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530463 }
464
465 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530466 * Returns the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530467 *
468 * @return the prefix
469 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530470 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530471 public String getPrefix() {
472 return prefix;
473 }
474
475 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530476 * Sets the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530477 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530478 * @param prefix the prefix to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530479 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530480 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530481 public void setPrefix(String prefix) {
482 this.prefix = prefix;
483 }
484
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530485 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530486 public void resolveSelfFileLinking(ResolvableType type)
487 throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530488 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530489 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530490 // Resolve linking for a resolution list.
491 resolveLinkingForResolutionList(resolutionList, this);
492 }
493
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530494 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530495 public void resolveInterFileLinking(ResolvableType type)
496 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530497 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530498 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530499 // Resolve linking for a resolution list.
500 linkInterFileReferences(resolutionList, this);
501 }
502
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530503 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530504 * Returns the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530505 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530506 * @return the reference
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530507 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530508 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530509 public String getReference() {
510 return reference;
511 }
512
513 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530514 * Sets the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530515 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530516 * @param reference the reference to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530517 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530518 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530519 public void setReference(String reference) {
520 this.reference = reference;
521 }
522
523 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530524 * Returns the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530525 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530526 * @return the revision
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530527 */
528 public YangRevision getRevision() {
529 return revision;
530 }
531
532 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530533 * Sets the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530534 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530535 * @param revision the revision to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530536 */
537 public void setRevision(YangRevision revision) {
538 this.revision = revision;
539 }
540
541 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530542 * Returns the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530543 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530544 * @return the version
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530545 */
546 public byte getVersion() {
547 return version;
548 }
549
550 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530551 * Sets the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530552 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530553 * @param version the version to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530554 */
555 public void setVersion(byte version) {
556 this.version = version;
557 }
558
559 /**
560 * Returns the type of the parsed data.
561 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530562 * @return returns MODULE_DATA
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530563 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530564 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530565 public YangConstructType getYangConstructType() {
566 return YangConstructType.MODULE_DATA;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530567 }
568
569 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530570 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530571 *
572 * @throws DataModelException a violation of data model rules
573 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530574 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530575 public void validateDataOnEntry()
576 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530577 /*
578 * Module is root in the data model tree, hence there is no entry
579 * validation
580 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530581 }
582
583 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530584 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530585 *
586 * @throws DataModelException a violation of data model rules
587 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530588 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530589 public void validateDataOnExit()
590 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530591 /*
592 * TODO: perform symbol linking for the imported or included YANG info.
593 * TODO: perform symbol resolution for referred YANG entities.
594 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530595 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530596
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530597 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530598 public void detectCollidingChild(String identifierName, YangConstructType dataType)
599 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530600 // Asks helper to detect colliding child.
601 detectCollidingChildUtil(identifierName, dataType, this);
602 }
603
604 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530605 public void detectSelfCollision(String identifierName, YangConstructType dataType)
606 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530607 // Not required as module doesn't have any parent.
608 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530609
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530610 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530611 public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
612 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
613 return derivedTypeResolutionList;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530614 } else if (type == ResolvableType.YANG_USES) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530615 return usesResolutionList;
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530616 } else if (type == ResolvableType.YANG_AUGMENT) {
617 return augmentResolutionList;
janani be18b5342016-07-13 21:06:41 +0530618 } else if (type == ResolvableType.YANG_IF_FEATURE) {
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530619 return ifFeatureResolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530620 } else if (type == ResolvableType.YANG_LEAFREF) {
janani be18b5342016-07-13 21:06:41 +0530621 return leafrefResolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530622 } else if (type == ResolvableType.YANG_BASE) {
623 return baseResolutionList;
624 } else {
625 return identityrefResolutionList;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530626 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530627 }
628
629 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530630 public void addToResolutionList(YangResolutionInfo resolutionInfo,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530631 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530632 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
633 derivedTypeResolutionList.add(resolutionInfo);
634 } else if (type == ResolvableType.YANG_USES) {
635 usesResolutionList.add(resolutionInfo);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530636 } else if (type == ResolvableType.YANG_IF_FEATURE) {
637 ifFeatureResolutionList.add(resolutionInfo);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530638 } else if (type == ResolvableType.YANG_LEAFREF) {
janani be18b5342016-07-13 21:06:41 +0530639 leafrefResolutionList.add(resolutionInfo);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530640 } else if (type == ResolvableType.YANG_BASE) {
641 baseResolutionList.add(resolutionInfo);
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530642 } else if (type == ResolvableType.YANG_AUGMENT) {
643 augmentResolutionList.add(resolutionInfo);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530644 } else if (type == ResolvableType.YANG_IDENTITYREF) {
645 identityrefResolutionList.add(resolutionInfo);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530646 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530647 }
648
649 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530650 public void setResolutionList(List<YangResolutionInfo> resolutionList,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530651 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530652 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
653 derivedTypeResolutionList = resolutionList;
654 } else if (type == ResolvableType.YANG_USES) {
655 usesResolutionList = resolutionList;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530656 } else if (type == ResolvableType.YANG_IF_FEATURE) {
657 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
janani be18b5342016-07-13 21:06:41 +0530658 } else if (type == ResolvableType.YANG_LEAFREF) {
659 leafrefResolutionList = resolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530660 } else if (type == ResolvableType.YANG_BASE) {
661 baseResolutionList = resolutionList;
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530662 } else if (type == ResolvableType.YANG_AUGMENT) {
663 augmentResolutionList = resolutionList;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530664 } else if (type == ResolvableType.YANG_IDENTITYREF) {
665 identityrefResolutionList = resolutionList;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530666 }
667
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530668 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530669
670 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530671 public void addReferencesToImportList(Set<YangNode> yangNodeSet)
672 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530673 Iterator<YangImport> importInfoIterator = getImportList().iterator();
674 // Run through the imported list to add references.
675 while (importInfoIterator.hasNext()) {
676 YangImport yangImport = importInfoIterator.next();
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530677 yangImport.addReferenceToImport(yangNodeSet);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530678 }
679 }
680
681 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530682 public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
683 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530684 Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
685 // Run through the included list to add references.
686 while (includeInfoIterator.hasNext()) {
687 YangInclude yangInclude = includeInfoIterator.next();
688 YangSubModule subModule = null;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530689 subModule = yangInclude.addReferenceToInclude(yangNodeSet);
690
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530691 // Check if the referred sub-modules parent is self
692 if (!(subModule.getBelongsTo().getModuleNode() == this)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530693 yangInclude.reportIncludeError();
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530694 }
695 }
696 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530697}