blob: 11b089d27ce03c0e2b152837b512b74ae75a8145 [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;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053022
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053023import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053024import org.onosproject.yangutils.linker.exceptions.LinkerException;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053025import org.onosproject.yangutils.linker.ResolvableType;
26import org.onosproject.yangutils.linker.YangReferenceResolver;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053027import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053028import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053029import org.onosproject.yangutils.plugin.manager.YangFileInfo;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053030import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S38046502016-03-23 15:30:27 +053031
32import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053033import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053034import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053035
36/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053037 * Reference:RFC 6020.
38 * The "module" statement defines the module's name,
39 * and groups all statements that belong to the module together. The "module"
40 * statement's argument is the name of the module, followed by a block of
41 * sub statements that hold detailed module information.
42 * The module's sub statements
43 *
44 * +--------------+---------+-------------+-----------------------+
45 * |sub statement | section | cardinality | data model mapping |
46 * +--------------+---------+-------------+-----------------------+
47 * | anyxml | 7.10 | 0..n | not supported |
48 * | augment | 7.15 | 0..n | child nodes |
49 * | choice | 7.9 | 0..n | child nodes |
50 * | contact | 7.1.8 | 0..1 | string |
51 * | container | 7.5 | 0..n | child nodes |
52 * | description | 7.19.3 | 0..1 | string |
53 * | deviation | 7.18.3 | 0..n | TODO |
54 * | extension | 7.17 | 0..n | TODO |
55 * | feature | 7.18.1 | 0..n | TODO |
56 * | grouping | 7.11 | 0..n | child nodes |
57 * | identity | 7.16 | 0..n | TODO |
58 * | import | 7.1.5 | 0..n | list of import info |
59 * | include | 7.1.6 | 0..n | list of include info |
60 * | leaf | 7.6 | 0..n | list of leaf info |
61 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
62 * | list | 7.8 | 0..n | child nodes |
63 * | namespace | 7.1.3 | 1 | string/uri |
64 * | notification | 7.14 | 0..n | TODO |
65 * | organization | 7.1.7 | 0..1 | string |
66 * | prefix | 7.1.4 | 1 | string |
67 * | reference | 7.19.4 | 0..1 | string |
68 * | revision | 7.1.9 | 0..n | revision |
69 * | rpc | 7.13 | 0..n | TODO |
70 * | typedef | 7.3 | 0..n | child nodes |
71 * | uses | 7.12 | 0..n | child nodes |
72 * | YANG-version | 7.1.2 | 0..1 | int |
73 * +--------------+---------+-------------+-----------------------+
74 */
75
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053076/**
Bharat saraswald9822e92016-04-05 15:13:44 +053077 * Represents data model node to maintain information defined in YANG module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053078 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053079public class YangModule
80 extends YangNode
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053081 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
82 RpcNotificationContainer {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053083
84 /**
85 * Name of the module.
86 */
87 private String name;
88
89 /**
90 * Reference:RFC 6020.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053091 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053092 * The "contact" statement provides contact information for the module. The
93 * argument is a string that is used to specify contact information for the
94 * person or persons to whom technical queries concerning this module should
95 * be sent, such as their name, postal address, telephone number, and
96 * electronic mail address.
97 */
98 private String contact;
99
100 /**
101 * Reference:RFC 6020.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530102 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530103 * The "description" statement takes as an argument a string that contains a
104 * human-readable textual description of this definition. The text is
105 * provided in a language (or languages) chosen by the module developer; for
106 * the sake of interoperability.
107 */
108 private String description;
109
110 /**
111 * List of YANG modules imported.
112 */
113 private List<YangImport> importList;
114
115 /**
116 * List of YANG sub-modules included.
117 */
118 private List<YangInclude> includeList;
119
120 /**
121 * List of leaves at root level in the module.
122 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 private List<YangLeaf> listOfLeaf;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530124
125 /**
126 * List of leaf-lists at root level in the module.
127 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530128 private List<YangLeafList> listOfLeafList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530129
130 /**
131 * Name space of the module.
132 */
133 private YangNameSpace nameSpace;
134
135 /**
136 * Reference:RFC 6020.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530137 *
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530138 * The "organization" statement defines the party responsible for this
139 * module. The argument is a string that is used to specify a textual
140 * description of the organization(s) under whose auspices this module was
141 * developed.
142 */
143 private String organization;
144
145 /**
146 * Prefix to refer to the objects in module.
147 */
148 private String prefix;
149
150 /**
151 * Reference of the module.
152 */
153 private String reference;
154
155 /**
156 * Revision info of the module.
157 */
158 private YangRevision revision;
159
160 /**
161 * YANG version.
162 */
163 private byte version;
164
Vinod Kumar S71cba682016-02-25 15:52:16 +0530165 /*-
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530166 * Reference RFC 6020.
167 *
Vinod Kumar S71cba682016-02-25 15:52:16 +0530168 * Nested typedefs and groupings.
169 * Typedefs and groupings may appear nested under many YANG statements,
170 * allowing these to be lexically scoped by the hierarchy under which
171 * they appear. This allows types and groupings to be defined near
172 * where they are used, rather than placing them at the top level of the
173 * hierarchy. The close proximity increases readability.
174 *
175 * Scoping also allows types to be defined without concern for naming
176 * conflicts between types in different submodules. Type names can be
177 * specified without adding leading strings designed to prevent name
178 * collisions within large modules.
179 *
180 * Finally, scoping allows the module author to keep types and groupings
181 * private to their module or submodule, preventing their reuse. Since
182 * only top-level types and groupings (i.e., those appearing as
183 * sub-statements to a module or submodule statement) can be used outside
184 * the module or submodule, the developer has more control over what
185 * pieces of their module are presented to the outside world, supporting
186 * the need to hide internal information and maintaining a boundary
187 * between what is shared with the outside world and what is kept
188 * private.
189 *
190 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
191 * type or grouping cannot be defined if a higher level in the schema
192 * hierarchy has a definition with a matching identifier.
193 *
194 * A reference to an unprefixed type or grouping, or one which uses the
195 * prefix of the current module, is resolved by locating the closest
196 * matching "typedef" or "grouping" statement among the immediate
197 * sub-statements of each ancestor statement.
198 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530199 private List<YangResolutionInfo> derivedTypeResolutionList;
200
201 /**
202 * uses resolution list.
203 */
204 private List<YangResolutionInfo> usesResolutionList;
Vinod Kumar S71cba682016-02-25 15:52:16 +0530205
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530206 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530207 * Creates a YANG node of module type.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530208 */
209 public YangModule() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530210
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530211 super(YangNodeType.MODULE_NODE);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530212 derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
213 usesResolutionList = new LinkedList<YangResolutionInfo>();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530214 importList = new LinkedList<YangImport>();
215 includeList = new LinkedList<YangInclude>();
216 listOfLeaf = new LinkedList<YangLeaf>();
217 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530218 }
219
Vinod Kumar S71cba682016-02-25 15:52:16 +0530220 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530221 * Returns name of the module.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530222 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530223 * @return module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530224 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530225 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530226 public String getName() {
227 return name;
228 }
229
Vinod Kumar S71cba682016-02-25 15:52:16 +0530230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Sets module name.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530232 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530233 * @param moduleName module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530234 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530235 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530236 public void setName(String moduleName) {
237 name = moduleName;
238 }
239
240 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530241 * Returns the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530242 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530243 * @return the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530244 */
245 public String getContact() {
246 return contact;
247 }
248
249 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530250 * Sets the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530251 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530252 * @param contact the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530253 */
254 public void setContact(String contact) {
255 this.contact = contact;
256 }
257
258 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530259 * Returns the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530260 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530261 * @return the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530262 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530263 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530264 public String getDescription() {
265 return description;
266 }
267
268 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530269 * Sets the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530270 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530271 * @param description set the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530272 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530273 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530274 public void setDescription(String description) {
275 this.description = description;
276 }
277
278 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530279 * Returns the list of imported modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530280 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530281 * @return the list of imported modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530282 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530283 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530284 public List<YangImport> getImportList() {
285 return importList;
286 }
287
288 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530289 * Adds the imported module information to the import list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530290 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530291 * @param importedModule module being imported
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530292 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530293 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530294 public void addToImportList(YangImport importedModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530295 getImportList().add(importedModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530296 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530297
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530298 @Override
299 public void setImportList(List<YangImport> importList) {
300 this.importList = importList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530301 }
302
303 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530304 * Returns the list of included sub modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530305 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530306 * @return the included list of sub modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530307 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530308 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530309 public List<YangInclude> getIncludeList() {
310 return includeList;
311 }
312
313 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530314 * Adds the included sub module information to the include list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530315 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530316 * @param includeModule submodule being included
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530317 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530318 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530319 public void addToIncludeList(YangInclude includeModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530320 getIncludeList().add(includeModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530321 }
322
323 @Override
324 public void setIncludeList(List<YangInclude> includeList) {
325 this.includeList = includeList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530326 }
327
328 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530329 * Returns the list of leaves in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530330 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530331 * @return the list of leaves
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530332 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530333 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530334 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530335 return listOfLeaf;
336 }
337
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530338 @Override
339 public void setListOfLeaf(List<YangLeaf> leafsList) {
340 listOfLeaf = leafsList;
341 }
342
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530343 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530344 * Adds a leaf in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530345 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530346 * @param leaf the leaf to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530347 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530348 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530349 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530350 getListOfLeaf().add(leaf);
351 }
352
353 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530354 * Returns the list of leaf-list from module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530355 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530356 * @return the list of leaf-list
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530357 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530358 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530359 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530360 return listOfLeafList;
361 }
362
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530363 @Override
364 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
365 this.listOfLeafList = listOfLeafList;
366 }
367
368
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530369 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530370 * Adds a leaf-list in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530371 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530372 * @param leafList the leaf-list to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530373 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530374 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530375 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530376 getListOfLeafList().add(leafList);
377 }
378
379 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530380 * Returns the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530381 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530382 * @return the nameSpace
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530383 */
384 public YangNameSpace getNameSpace() {
385 return nameSpace;
386 }
387
388 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530389 * Sets the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530390 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530391 * @param nameSpace the nameSpace to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530392 */
393 public void setNameSpace(YangNameSpace nameSpace) {
394 this.nameSpace = nameSpace;
395 }
396
397 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530398 * Returns the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530399 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530400 * @return the organization
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530401 */
402 public String getOrganization() {
403 return organization;
404 }
405
406 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530407 * Sets the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530408 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530409 * @param org the organization to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530410 */
411 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530412 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530413 }
414
415 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530416 * Returns the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530417 *
418 * @return the prefix
419 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530420 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530421 public String getPrefix() {
422 return prefix;
423 }
424
425 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530426 * Sets the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530427 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530428 * @param prefix the prefix to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530429 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530430 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530431 public void setPrefix(String prefix) {
432 this.prefix = prefix;
433 }
434
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530435 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530436 public void resolveSelfFileLinking(ResolvableType type)
437 throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530438 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530439 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530440 // Resolve linking for a resolution list.
441 resolveLinkingForResolutionList(resolutionList, this);
442 }
443
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530444 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530445 public void resolveInterFileLinking(ResolvableType type)
446 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530447 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530448 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530449 // Resolve linking for a resolution list.
450 linkInterFileReferences(resolutionList, this);
451 }
452
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530453 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530454 * Returns the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530455 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530456 * @return the reference
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530457 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530458 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530459 public String getReference() {
460 return reference;
461 }
462
463 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530464 * Sets the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530465 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530466 * @param reference the reference to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530467 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530468 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530469 public void setReference(String reference) {
470 this.reference = reference;
471 }
472
473 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530474 * Returns the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530475 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530476 * @return the revision
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530477 */
478 public YangRevision getRevision() {
479 return revision;
480 }
481
482 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530483 * Sets the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530484 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530485 * @param revision the revision to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530486 */
487 public void setRevision(YangRevision revision) {
488 this.revision = revision;
489 }
490
491 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530492 * Returns the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530493 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530494 * @return the version
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530495 */
496 public byte getVersion() {
497 return version;
498 }
499
500 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530501 * Sets the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530502 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530503 * @param version the version to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530504 */
505 public void setVersion(byte version) {
506 this.version = version;
507 }
508
509 /**
510 * Returns the type of the parsed data.
511 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530512 * @return returns MODULE_DATA
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530513 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530514 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530515 public YangConstructType getYangConstructType() {
516 return YangConstructType.MODULE_DATA;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530517 }
518
519 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530520 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530521 *
522 * @throws DataModelException a violation of data model rules
523 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530524 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530525 public void validateDataOnEntry()
526 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530527 /*
528 * Module is root in the data model tree, hence there is no entry
529 * validation
530 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530531 }
532
533 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530534 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530535 *
536 * @throws DataModelException a violation of data model rules
537 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530538 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530539 public void validateDataOnExit()
540 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530541 /*
542 * TODO: perform symbol linking for the imported or included YANG info.
543 * TODO: perform symbol resolution for referred YANG entities.
544 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530545 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530546
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530547 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530548 public void detectCollidingChild(String identifierName, YangConstructType dataType)
549 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530550 // Asks helper to detect colliding child.
551 detectCollidingChildUtil(identifierName, dataType, this);
552 }
553
554 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530555 public void detectSelfCollision(String identifierName, YangConstructType dataType)
556 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530557 // Not required as module doesn't have any parent.
558 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530559
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530560 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530561 public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
562 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
563 return derivedTypeResolutionList;
564 } else {
565 return usesResolutionList;
566 }
567
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530568 }
569
570 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530571 public void addToResolutionList(YangResolutionInfo resolutionInfo,
572 ResolvableType type) {
573 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
574 derivedTypeResolutionList.add(resolutionInfo);
575 } else if (type == ResolvableType.YANG_USES) {
576 usesResolutionList.add(resolutionInfo);
577 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530578 }
579
580 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530581 public void setResolutionList(List<YangResolutionInfo> resolutionList,
582 ResolvableType type) {
583 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
584 derivedTypeResolutionList = resolutionList;
585 } else if (type == ResolvableType.YANG_USES) {
586 usesResolutionList = resolutionList;
587 }
588
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530589 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530590
591 @Override
592 public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
593 throws LinkerException {
594 Iterator<YangImport> importInfoIterator = getImportList().iterator();
595 // Run through the imported list to add references.
596 while (importInfoIterator.hasNext()) {
597 YangImport yangImport = importInfoIterator.next();
598 try {
599 yangImport.addReferenceToImport(yangFileInfoSet);
600 } catch (DataModelException e) {
601 throw new LinkerException(e.getMessage());
602 }
603 }
604 }
605
606 @Override
607 public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
608 throws LinkerException {
609 Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
610 // Run through the included list to add references.
611 while (includeInfoIterator.hasNext()) {
612 YangInclude yangInclude = includeInfoIterator.next();
613 YangSubModule subModule = null;
614 try {
615 subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
616 } catch (DataModelException e) {
617 throw new LinkerException(e.getMessage());
618 }
619 // Check if the referred sub-modules parent is self
620 if (!(subModule.getBelongsTo().getModuleNode() == this)) {
621 try {
622 yangInclude.reportIncludeError();
623 } catch (DataModelException e) {
624 throw new LinkerException(e.getMessage());
625 }
626 }
627 }
628 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530629}