blob: 4eab4c3180d9f2cbfbb6dea2bf34ff386c9ceaf7 [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 saraswal2f00b4b2016-03-04 20:08:09 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053023import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053024import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S38046502016-03-23 15:30:27 +053025
26import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053027import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053028import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053029
30/*-
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053031 * Reference:RFC 6020.
32 * The "module" statement defines the module's name,
33 * and groups all statements that belong to the module together. The "module"
34 * statement's argument is the name of the module, followed by a block of
35 * sub statements that hold detailed module information.
36 * The module's sub statements
37 *
38 * +--------------+---------+-------------+-----------------------+
39 * |sub statement | section | cardinality | data model mapping |
40 * +--------------+---------+-------------+-----------------------+
41 * | anyxml | 7.10 | 0..n | not supported |
42 * | augment | 7.15 | 0..n | child nodes |
43 * | choice | 7.9 | 0..n | child nodes |
44 * | contact | 7.1.8 | 0..1 | string |
45 * | container | 7.5 | 0..n | child nodes |
46 * | description | 7.19.3 | 0..1 | string |
47 * | deviation | 7.18.3 | 0..n | TODO |
48 * | extension | 7.17 | 0..n | TODO |
49 * | feature | 7.18.1 | 0..n | TODO |
50 * | grouping | 7.11 | 0..n | child nodes |
51 * | identity | 7.16 | 0..n | TODO |
52 * | import | 7.1.5 | 0..n | list of import info |
53 * | include | 7.1.6 | 0..n | list of include info |
54 * | leaf | 7.6 | 0..n | list of leaf info |
55 * | leaf-list | 7.7 | 0..n | list of leaf-list info|
56 * | list | 7.8 | 0..n | child nodes |
57 * | namespace | 7.1.3 | 1 | string/uri |
58 * | notification | 7.14 | 0..n | TODO |
59 * | organization | 7.1.7 | 0..1 | string |
60 * | prefix | 7.1.4 | 1 | string |
61 * | reference | 7.19.4 | 0..1 | string |
62 * | revision | 7.1.9 | 0..n | revision |
63 * | rpc | 7.13 | 0..n | TODO |
64 * | typedef | 7.3 | 0..n | child nodes |
65 * | uses | 7.12 | 0..n | child nodes |
66 * | YANG-version | 7.1.2 | 0..1 | int |
67 * +--------------+---------+-------------+-----------------------+
68 */
69
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053070/**
Bharat saraswald9822e92016-04-05 15:13:44 +053071 * Represents data model node to maintain information defined in YANG module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053072 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053073public class YangModule
74 extends YangNode
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053075 implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
76 RpcNotificationContainer {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053077
78 /**
79 * Name of the module.
80 */
81 private String name;
82
83 /**
84 * Reference:RFC 6020.
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053085 * <p>
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053086 * The "contact" statement provides contact information for the module. The
87 * argument is a string that is used to specify contact information for the
88 * person or persons to whom technical queries concerning this module should
89 * be sent, such as their name, postal address, telephone number, and
90 * electronic mail address.
91 */
92 private String contact;
93
94 /**
95 * Reference:RFC 6020.
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053096 * <p>
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +053097 * The "description" statement takes as an argument a string that contains a
98 * human-readable textual description of this definition. The text is
99 * provided in a language (or languages) chosen by the module developer; for
100 * the sake of interoperability.
101 */
102 private String description;
103
104 /**
105 * List of YANG modules imported.
106 */
107 private List<YangImport> importList;
108
109 /**
110 * List of YANG sub-modules included.
111 */
112 private List<YangInclude> includeList;
113
114 /**
115 * List of leaves at root level in the module.
116 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530117 private List<YangLeaf> listOfLeaf;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530118
119 /**
120 * List of leaf-lists at root level in the module.
121 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530122 private List<YangLeafList> listOfLeafList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530123
124 /**
125 * Name space of the module.
126 */
127 private YangNameSpace nameSpace;
128
129 /**
130 * Reference:RFC 6020.
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530131 * <p>
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530132 * The "organization" statement defines the party responsible for this
133 * module. The argument is a string that is used to specify a textual
134 * description of the organization(s) under whose auspices this module was
135 * developed.
136 */
137 private String organization;
138
139 /**
140 * Prefix to refer to the objects in module.
141 */
142 private String prefix;
143
144 /**
145 * Reference of the module.
146 */
147 private String reference;
148
149 /**
150 * Revision info of the module.
151 */
152 private YangRevision revision;
153
154 /**
155 * YANG version.
156 */
157 private byte version;
158
Vinod Kumar S71cba682016-02-25 15:52:16 +0530159 /*-
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530160 * Reference RFC 6020.
161 *
Vinod Kumar S71cba682016-02-25 15:52:16 +0530162 * Nested typedefs and groupings.
163 * Typedefs and groupings may appear nested under many YANG statements,
164 * allowing these to be lexically scoped by the hierarchy under which
165 * they appear. This allows types and groupings to be defined near
166 * where they are used, rather than placing them at the top level of the
167 * hierarchy. The close proximity increases readability.
168 *
169 * Scoping also allows types to be defined without concern for naming
170 * conflicts between types in different submodules. Type names can be
171 * specified without adding leading strings designed to prevent name
172 * collisions within large modules.
173 *
174 * Finally, scoping allows the module author to keep types and groupings
175 * private to their module or submodule, preventing their reuse. Since
176 * only top-level types and groupings (i.e., those appearing as
177 * sub-statements to a module or submodule statement) can be used outside
178 * the module or submodule, the developer has more control over what
179 * pieces of their module are presented to the outside world, supporting
180 * the need to hide internal information and maintaining a boundary
181 * between what is shared with the outside world and what is kept
182 * private.
183 *
184 * Scoped definitions MUST NOT shadow definitions at a higher scope. A
185 * type or grouping cannot be defined if a higher level in the schema
186 * hierarchy has a definition with a matching identifier.
187 *
188 * A reference to an unprefixed type or grouping, or one which uses the
189 * prefix of the current module, is resolved by locating the closest
190 * matching "typedef" or "grouping" statement among the immediate
191 * sub-statements of each ancestor statement.
192 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530193 private List<YangResolutionInfo> derivedTypeResolutionList;
194
195 /**
196 * uses resolution list.
197 */
198 private List<YangResolutionInfo> usesResolutionList;
Vinod Kumar S71cba682016-02-25 15:52:16 +0530199
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530200 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530201 * Creates a YANG node of module type.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530202 */
203 public YangModule() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530204
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530205 super(YangNodeType.MODULE_NODE);
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530206 derivedTypeResolutionList = new LinkedList<>();
207 usesResolutionList = new LinkedList<>();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530208 importList = new LinkedList<YangImport>();
209 includeList = new LinkedList<YangInclude>();
210 listOfLeaf = new LinkedList<YangLeaf>();
211 listOfLeafList = new LinkedList<YangLeafList>();
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530212 }
213
Vinod Kumar S71cba682016-02-25 15:52:16 +0530214 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530215 * Returns name of the module.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530216 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530217 * @return module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530218 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530219 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530220 public String getName() {
221 return name;
222 }
223
Vinod Kumar S71cba682016-02-25 15:52:16 +0530224 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530225 * Sets module name.
Vinod Kumar S71cba682016-02-25 15:52:16 +0530226 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530227 * @param moduleName module name
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530228 */
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530229 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530230 public void setName(String moduleName) {
231 name = moduleName;
232 }
233
234 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530235 * Returns the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530236 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530237 * @return the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530238 */
239 public String getContact() {
240 return contact;
241 }
242
243 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530244 * Sets the contact details of the module owner.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530245 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530246 * @param contact the contact details of YANG owner
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530247 */
248 public void setContact(String contact) {
249 this.contact = contact;
250 }
251
252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Returns the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530254 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530255 * @return the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530256 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530257 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530258 public String getDescription() {
259 return description;
260 }
261
262 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530263 * Sets the description of module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530264 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530265 * @param description set the description of YANG module
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530266 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530267 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530268 public void setDescription(String description) {
269 this.description = description;
270 }
271
272 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530273 * Returns the list of imported modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530274 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530275 * @return the list of imported modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530276 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530277 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530278 public List<YangImport> getImportList() {
279 return importList;
280 }
281
282 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530283 * Adds the imported module information to the import list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530284 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530285 * @param importedModule module being imported
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530286 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530287 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530288 public void addToImportList(YangImport importedModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530289 getImportList().add(importedModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530290 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530291
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530292 @Override
293 public void setImportList(List<YangImport> importList) {
294 this.importList = importList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530295 }
296
297 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530298 * Returns the list of included sub modules.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530299 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530300 * @return the included list of sub modules
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530301 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530302 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530303 public List<YangInclude> getIncludeList() {
304 return includeList;
305 }
306
307 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530308 * Adds the included sub module information to the include list.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530309 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530310 * @param includeModule submodule being included
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530311 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530312 @Override
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530313 public void addToIncludeList(YangInclude includeModule) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530314 getIncludeList().add(includeModule);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530315 }
316
317 @Override
318 public void setIncludeList(List<YangInclude> includeList) {
319 this.includeList = includeList;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530320 }
321
322 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530323 * Returns the list of leaves in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530324 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530325 * @return the list of leaves
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530326 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530327 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530328 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530329 return listOfLeaf;
330 }
331
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530332 @Override
333 public void setListOfLeaf(List<YangLeaf> leafsList) {
334 listOfLeaf = leafsList;
335 }
336
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530337 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530338 * Adds a leaf in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530339 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530340 * @param leaf the leaf to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530341 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530342 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530343 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530344 getListOfLeaf().add(leaf);
345 }
346
347 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530348 * Returns the list of leaf-list from module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530349 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530350 * @return the list of leaf-list
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530351 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530352 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530353 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530354 return listOfLeafList;
355 }
356
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530357 @Override
358 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
359 this.listOfLeafList = listOfLeafList;
360 }
361
362
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530363 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530364 * Adds a leaf-list in module.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530365 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530366 * @param leafList the leaf-list to be added
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530367 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530368 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530369 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530370 getListOfLeafList().add(leafList);
371 }
372
373 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530374 * Returns the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530375 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530376 * @return the nameSpace
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530377 */
378 public YangNameSpace getNameSpace() {
379 return nameSpace;
380 }
381
382 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530383 * Sets the name space of module elements.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530384 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530385 * @param nameSpace the nameSpace to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530386 */
387 public void setNameSpace(YangNameSpace nameSpace) {
388 this.nameSpace = nameSpace;
389 }
390
391 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530392 * Returns the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530393 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530394 * @return the organization
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530395 */
396 public String getOrganization() {
397 return organization;
398 }
399
400 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530401 * Sets the modules organization.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530402 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530403 * @param org the organization to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530404 */
405 public void setOrganization(String org) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530406 organization = org;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530407 }
408
409 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530410 * Returns the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530411 *
412 * @return the prefix
413 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530414 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530415 public String getPrefix() {
416 return prefix;
417 }
418
419 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530420 * Sets the prefix.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530421 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530422 * @param prefix the prefix to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530423 */
Bharat saraswalcad0e652016-05-26 23:48:38 +0530424 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530425 public void setPrefix(String prefix) {
426 this.prefix = prefix;
427 }
428
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530429 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530430 public void resolveSelfFileLinking(ResolvableType type)
431 throws DataModelException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530432 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530433 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530434 // Resolve linking for a resolution list.
435 resolveLinkingForResolutionList(resolutionList, this);
436 }
437
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530438 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530439 public void resolveInterFileLinking(ResolvableType type)
440 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530441 // Get the list to be resolved.
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530442 List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530443 // Resolve linking for a resolution list.
444 linkInterFileReferences(resolutionList, this);
445 }
446
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530447 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530448 * Returns the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530449 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530450 * @return the reference
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530451 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530452 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530453 public String getReference() {
454 return reference;
455 }
456
457 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530458 * Sets the textual reference.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530459 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530460 * @param reference the reference to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530461 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530462 @Override
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530463 public void setReference(String reference) {
464 this.reference = reference;
465 }
466
467 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530468 * Returns the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530469 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530470 * @return the revision
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530471 */
472 public YangRevision getRevision() {
473 return revision;
474 }
475
476 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530477 * Sets the revision.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530478 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530479 * @param revision the revision to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530480 */
481 public void setRevision(YangRevision revision) {
482 this.revision = revision;
483 }
484
485 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530486 * Returns the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530487 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530488 * @return the version
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530489 */
490 public byte getVersion() {
491 return version;
492 }
493
494 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530495 * Sets the version.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530496 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530497 * @param version the version to set
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530498 */
499 public void setVersion(byte version) {
500 this.version = version;
501 }
502
503 /**
504 * Returns the type of the parsed data.
505 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530506 * @return returns MODULE_DATA
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530507 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530508 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530509 public YangConstructType getYangConstructType() {
510 return YangConstructType.MODULE_DATA;
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530511 }
512
513 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530514 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530515 *
516 * @throws DataModelException a violation of data model rules
517 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530518 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530519 public void validateDataOnEntry()
520 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530521 /*
522 * Module is root in the data model tree, hence there is no entry
523 * validation
524 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530525 }
526
527 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530528 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530529 *
530 * @throws DataModelException a violation of data model rules
531 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530532 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530533 public void validateDataOnExit()
534 throws DataModelException {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530535 /*
536 * TODO: perform symbol linking for the imported or included YANG info.
537 * TODO: perform symbol resolution for referred YANG entities.
538 */
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530539 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530540
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530541 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530542 public void detectCollidingChild(String identifierName, YangConstructType dataType)
543 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530544 // Asks helper to detect colliding child.
545 detectCollidingChildUtil(identifierName, dataType, this);
546 }
547
548 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530549 public void detectSelfCollision(String identifierName, YangConstructType dataType)
550 throws DataModelException {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530551 // Not required as module doesn't have any parent.
552 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530553
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530554 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530555 public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
556 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
557 return derivedTypeResolutionList;
558 } else {
559 return usesResolutionList;
560 }
561
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530562 }
563
564 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530565 public void addToResolutionList(YangResolutionInfo resolutionInfo,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530566 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530567 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
568 derivedTypeResolutionList.add(resolutionInfo);
569 } else if (type == ResolvableType.YANG_USES) {
570 usesResolutionList.add(resolutionInfo);
571 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530572 }
573
574 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530575 public void setResolutionList(List<YangResolutionInfo> resolutionList,
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530576 ResolvableType type) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530577 if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
578 derivedTypeResolutionList = resolutionList;
579 } else if (type == ResolvableType.YANG_USES) {
580 usesResolutionList = resolutionList;
581 }
582
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530583 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530584
585 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530586 public void addReferencesToImportList(Set<YangNode> yangNodeSet)
587 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530588 Iterator<YangImport> importInfoIterator = getImportList().iterator();
589 // Run through the imported list to add references.
590 while (importInfoIterator.hasNext()) {
591 YangImport yangImport = importInfoIterator.next();
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530592 yangImport.addReferenceToImport(yangNodeSet);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530593 }
594 }
595
596 @Override
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530597 public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
598 throws DataModelException {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530599 Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
600 // Run through the included list to add references.
601 while (includeInfoIterator.hasNext()) {
602 YangInclude yangInclude = includeInfoIterator.next();
603 YangSubModule subModule = null;
604 try {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530605 subModule = yangInclude.addReferenceToInclude(yangNodeSet);
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530606 } catch (DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530607 throw e;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530608 }
609 // Check if the referred sub-modules parent is self
610 if (!(subModule.getBelongsTo().getModuleNode() == this)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530611 yangInclude.reportIncludeError();
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530612 }
613 }
614 }
Vinod Kumar S1ede5ab2016-02-09 20:14:53 +0530615}