Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.yangutils.datamodel; |
| 17 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 18 | import java.util.Iterator; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 19 | import java.util.LinkedList; |
| 20 | import java.util.List; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 21 | import java.util.Set; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
| 24 | import org.onosproject.yangutils.linker.impl.YangReferenceResolver; |
| 25 | import org.onosproject.yangutils.linker.impl.YangResolutionInfo; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.plugin.manager.YangFileInfo; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.utils.YangConstructType; |
| 29 | |
| 30 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 31 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 32 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 33 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 34 | /* |
| 35 | * Reference RFC 6020. |
| 36 | * |
| 37 | * While the primary unit in YANG is a module, a YANG module can itself |
| 38 | * be constructed out of several submodules. Submodules allow a module |
| 39 | * designer to split a complex model into several pieces where all the |
| 40 | * submodules contribute to a single namespace, which is defined by the |
| 41 | * module that includes the submodules. |
| 42 | * |
| 43 | * The "submodule" statement defines the submodule's name, and groups |
| 44 | * all statements that belong to the submodule together. The |
| 45 | * "submodule" statement's argument is the name of the submodule, |
| 46 | * followed by a block of sub-statements that hold detailed submodule |
| 47 | * information. |
| 48 | * |
| 49 | * The submodule's sub-statements |
| 50 | * |
| 51 | * +--------------+---------+-------------+------------------+ |
| 52 | * | substatement | section | cardinality |data model mapping| |
| 53 | * +--------------+---------+-------------+------------------+ |
| 54 | * | anyxml | 7.10 | 0..n | - not supported | |
| 55 | * | augment | 7.15 | 0..n | - child nodes | |
| 56 | * | belongs-to | 7.2.2 | 1 | - YangBelongsTo | |
| 57 | * | choice | 7.9 | 0..n | - child nodes | |
| 58 | * | contact | 7.1.8 | 0..1 | - string | |
| 59 | * | container | 7.5 | 0..n | - child nodes | |
| 60 | * | description | 7.19.3 | 0..1 | - string | |
| 61 | * | deviation | 7.18.3 | 0..n | - TODO | |
| 62 | * | extension | 7.17 | 0..n | - TODO | |
| 63 | * | feature | 7.18.1 | 0..n | - TODO | |
| 64 | * | grouping | 7.11 | 0..n | - child nodes | |
| 65 | * | identity | 7.16 | 0..n | - TODO | |
| 66 | * | import | 7.1.5 | 0..n | - YangImport | |
| 67 | * | include | 7.1.6 | 0..n | - YangInclude | |
| 68 | * | leaf | 7.6 | 0..n | - YangLeaf | |
| 69 | * | leaf-list | 7.7 | 0..n | - YangLeafList | |
| 70 | * | list | 7.8 | 0..n | - child nodes | |
| 71 | * | notification | 7.14 | 0..n | - TODO | |
| 72 | * | organization | 7.1.7 | 0..1 | - string | |
| 73 | * | reference | 7.19.4 | 0..1 | - string | |
| 74 | * | revision | 7.1.9 | 0..n | - string | |
| 75 | * | rpc | 7.13 | 0..n | - TODO | |
| 76 | * | typedef | 7.3 | 0..n | - child nodes | |
| 77 | * | uses | 7.12 | 0..n | - child nodes | |
| 78 | * | YANG-version | 7.1.2 | 0..1 | - int | |
| 79 | * +--------------+---------+-------------+------------------+ |
| 80 | */ |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 81 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 82 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 83 | * Represents data model node to maintain information defined in YANG sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 84 | */ |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 85 | public class YangSubModule extends YangNode |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 86 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, |
| 87 | RpcNotificationContainer { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Name of sub module. |
| 91 | */ |
| 92 | private String name; |
| 93 | |
| 94 | /** |
| 95 | * Module to which it belongs to. |
| 96 | */ |
| 97 | private YangBelongsTo belongsTo; |
| 98 | |
| 99 | /** |
| 100 | * Reference RFC 6020. |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 101 | * <p> |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 102 | * The "contact" statement provides contact information for the module. The |
| 103 | * argument is a string that is used to specify contact information for the |
| 104 | * person or persons to whom technical queries concerning this module should |
| 105 | * be sent, such as their name, postal address, telephone number, and |
| 106 | * electronic mail address. |
| 107 | */ |
| 108 | private String contact; |
| 109 | |
| 110 | /** |
| 111 | * Description. |
| 112 | */ |
| 113 | private String description; |
| 114 | |
| 115 | /** |
| 116 | * List of YANG modules imported. |
| 117 | */ |
| 118 | private List<YangImport> importList; |
| 119 | |
| 120 | /** |
| 121 | * List of YANG sub-modules included. |
| 122 | */ |
| 123 | private List<YangInclude> includeList; |
| 124 | |
| 125 | /** |
| 126 | * List of leaves at root level in the sub-module. |
| 127 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 128 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * List of leaf-lists at root level in the sub-module. |
| 132 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 133 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 134 | |
| 135 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 136 | * Organization owner of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 137 | */ |
| 138 | private String organization; |
| 139 | |
| 140 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 141 | * Reference of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 142 | */ |
| 143 | private String reference; |
| 144 | |
| 145 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 146 | * Revision info of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 147 | */ |
| 148 | private YangRevision revision; |
| 149 | |
| 150 | /** |
| 151 | * YANG version. |
| 152 | */ |
| 153 | private byte version; |
| 154 | |
| 155 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 156 | * Prefix of parent module. |
| 157 | */ |
| 158 | private String prefix; |
| 159 | /*- |
| 160 | * Reference RFC 6020. |
| 161 | * |
| 162 | * 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 | */ |
| 193 | private List<YangResolutionInfo> unresolvedResolutionList; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 194 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 195 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 196 | * Creates a sub module node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 197 | */ |
| 198 | public YangSubModule() { |
| 199 | super(YangNodeType.SUB_MODULE_NODE); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 200 | unresolvedResolutionList = new LinkedList<YangResolutionInfo>(); |
| 201 | importList = new LinkedList<YangImport>(); |
| 202 | includeList = new LinkedList<YangInclude>(); |
| 203 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 204 | listOfLeafList = new LinkedList<YangLeafList>(); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 205 | } |
| 206 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 207 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 208 | * Returns the YANG name of the sub module. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 209 | * |
| 210 | * @return YANG name of the sub module |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 211 | */ |
| 212 | @Override |
| 213 | public String getName() { |
| 214 | return name; |
| 215 | } |
| 216 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 217 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 218 | * Sets YANG name of the sub module. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 219 | * |
| 220 | * @param subModuleName YANG name of the sub module |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 221 | */ |
| 222 | @Override |
| 223 | public void setName(String subModuleName) { |
| 224 | name = subModuleName; |
| 225 | } |
| 226 | |
| 227 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 228 | * Returns the module info. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 229 | * |
| 230 | * @return the belongs to info |
| 231 | */ |
| 232 | public YangBelongsTo getBelongsTo() { |
| 233 | return belongsTo; |
| 234 | } |
| 235 | |
| 236 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 237 | * Sets the module info. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 238 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 239 | * @param belongsTo module info to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 240 | */ |
| 241 | public void setBelongsTo(YangBelongsTo belongsTo) { |
| 242 | this.belongsTo = belongsTo; |
| 243 | } |
| 244 | |
| 245 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 246 | * Returns the contact. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 247 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 248 | * @return the contact |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 249 | */ |
| 250 | public String getContact() { |
| 251 | return contact; |
| 252 | } |
| 253 | |
| 254 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 255 | * Sets the contact. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 256 | * |
| 257 | * @param contact the contact to set |
| 258 | */ |
| 259 | public void setContact(String contact) { |
| 260 | this.contact = contact; |
| 261 | } |
| 262 | |
| 263 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 264 | * Returns the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 265 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 266 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 267 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 268 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 269 | public String getDescription() { |
| 270 | return description; |
| 271 | } |
| 272 | |
| 273 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 274 | * Sets the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 275 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 276 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 277 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 278 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 279 | public void setDescription(String description) { |
| 280 | this.description = description; |
| 281 | } |
| 282 | |
| 283 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 284 | * Returns the list of imported modules. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 285 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 286 | * @return the list of imported modules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 287 | */ |
| 288 | public List<YangImport> getImportList() { |
| 289 | return importList; |
| 290 | } |
| 291 | |
| 292 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 293 | * Adds the imported module information to the import list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 294 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 295 | * @param importedModule module being imported |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 296 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 297 | public void addToImportList(YangImport importedModule) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 298 | getImportList().add(importedModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 299 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 300 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 301 | @Override |
| 302 | public void setImportList(List<YangImport> importList) { |
| 303 | this.importList = importList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 307 | * Returns the list of included sub modules. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 308 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 309 | * @return the included list of sub modules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 310 | */ |
| 311 | public List<YangInclude> getIncludeList() { |
| 312 | return includeList; |
| 313 | } |
| 314 | |
| 315 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 316 | * Returns the included sub module information to the include list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 317 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 318 | * @param includeModule submodule being included |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 319 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 320 | public void addToIncludeList(YangInclude includeModule) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 321 | getIncludeList().add(includeModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void setIncludeList(List<YangInclude> includeList) { |
| 326 | this.includeList = includeList; |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public String getPrefix() { |
| 331 | return prefix; |
| 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public void setPrefix(String prefix) { |
| 336 | this.prefix = prefix; |
| 337 | } |
| 338 | |
| 339 | @Override |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 340 | public void resolveSelfFileLinking() throws DataModelException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 341 | // Get the list to be resolved. |
| 342 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(); |
| 343 | // Resolve linking for a resolution list. |
| 344 | resolveLinkingForResolutionList(resolutionList, this); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 345 | } |
| 346 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 347 | @Override |
| 348 | public void resolveInterFileLinking() throws DataModelException { |
| 349 | // Get the list to be resolved. |
| 350 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(); |
| 351 | // Resolve linking for a resolution list. |
| 352 | linkInterFileReferences(resolutionList, this); |
| 353 | } |
| 354 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 355 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 356 | * Returns the list of leaves. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 357 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 358 | * @return the list of leaves |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 359 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 360 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 361 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 362 | return listOfLeaf; |
| 363 | } |
| 364 | |
| 365 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 366 | * Adds a leaf. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 367 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 368 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 369 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 370 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 371 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 372 | getListOfLeaf().add(leaf); |
| 373 | } |
| 374 | |
| 375 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 376 | * Returns the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 377 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 378 | * @return the list of leaf-list |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 379 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 380 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 381 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 382 | return listOfLeafList; |
| 383 | } |
| 384 | |
| 385 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 386 | * Adds a leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 387 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 388 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 389 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 390 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 391 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 392 | getListOfLeafList().add(leafList); |
| 393 | } |
| 394 | |
| 395 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 396 | * Returns the sub-modules organization. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 397 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 398 | * @return the organization |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 399 | */ |
| 400 | public String getOrganization() { |
| 401 | return organization; |
| 402 | } |
| 403 | |
| 404 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 405 | * Sets the sub-modules organization. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 406 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 407 | * @param org the organization to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 408 | */ |
| 409 | public void setOrganization(String org) { |
| 410 | organization = org; |
| 411 | } |
| 412 | |
| 413 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 414 | * Returns the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 415 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 416 | * @return the reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 417 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 418 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 419 | public String getReference() { |
| 420 | return reference; |
| 421 | } |
| 422 | |
| 423 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 424 | * Sets the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 425 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 426 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 427 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 428 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 429 | public void setReference(String reference) { |
| 430 | this.reference = reference; |
| 431 | } |
| 432 | |
| 433 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 434 | * Returns the revision. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 435 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 436 | * @return the revision |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 437 | */ |
| 438 | public YangRevision getRevision() { |
| 439 | return revision; |
| 440 | } |
| 441 | |
| 442 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 443 | * Sets the revision. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 444 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 445 | * @param revision the revision to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 446 | */ |
| 447 | public void setRevision(YangRevision revision) { |
| 448 | this.revision = revision; |
| 449 | } |
| 450 | |
| 451 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 452 | * Returns the version. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 453 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 454 | * @return the version |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 455 | */ |
| 456 | public byte getVersion() { |
| 457 | return version; |
| 458 | } |
| 459 | |
| 460 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 461 | * Sets the version. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 462 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 463 | * @param version the version to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 464 | */ |
| 465 | public void setVersion(byte version) { |
| 466 | this.version = version; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Returns the type of the parsed data. |
| 471 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 472 | * @return returns SUB_MODULE_DATA |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 473 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 474 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 475 | public YangConstructType getYangConstructType() { |
| 476 | return YangConstructType.SUB_MODULE_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 480 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 481 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 482 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 483 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 484 | @Override |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 485 | public void validateDataOnEntry() throws DataModelException { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 486 | // TODO auto-generated method stub, to be implemented by parser |
| 487 | } |
| 488 | |
| 489 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 490 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 491 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 492 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 493 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 494 | @Override |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 495 | public void validateDataOnExit() throws DataModelException { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 496 | // TODO auto-generated method stub, to be implemented by parser |
| 497 | } |
| 498 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 499 | @Override |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 500 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 501 | // Asks helper to detect colliding child. |
| 502 | detectCollidingChildUtil(identifierName, dataType, this); |
| 503 | } |
| 504 | |
| 505 | @Override |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 506 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 507 | // Not required as module doesn't have any parent. |
| 508 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 509 | |
| 510 | @Override |
| 511 | public List<YangResolutionInfo> getUnresolvedResolutionList() { |
| 512 | return unresolvedResolutionList; |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public void addToResolutionList(YangResolutionInfo resolutionInfo) { |
| 517 | this.unresolvedResolutionList.add(resolutionInfo); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public void setResolutionList(List<YangResolutionInfo> resolutionList) { |
| 522 | this.unresolvedResolutionList = resolutionList; |
| 523 | } |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * Links the sub-module with module. |
| 527 | * |
| 528 | * @param yangFileInfoSet YANG file information set |
| 529 | * @throws DataModelException a violation in data model rule |
| 530 | */ |
| 531 | public void linkWithModule(Set<YangFileInfo> yangFileInfoSet) |
| 532 | throws DataModelException { |
| 533 | getBelongsTo().linkWithModule(yangFileInfoSet); |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) |
| 538 | throws LinkerException { |
| 539 | Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator(); |
| 540 | // Run through the included list to add references. |
| 541 | while (includeInfoIterator.hasNext()) { |
| 542 | YangInclude yangInclude = includeInfoIterator.next(); |
| 543 | YangSubModule subModule = null; |
| 544 | try { |
| 545 | subModule = yangInclude.addReferenceToInclude(yangFileInfoSet); |
| 546 | } catch (DataModelException e) { |
| 547 | throw new LinkerException(e.getMessage()); |
| 548 | } |
| 549 | // Check if the referred sub-modules parent is self |
| 550 | if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) { |
| 551 | try { |
| 552 | yangInclude.reportIncludeError(); |
| 553 | } catch (DataModelException e) { |
| 554 | throw new LinkerException(e.getMessage()); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) |
| 562 | throws LinkerException { |
| 563 | Iterator<YangImport> importInfoIterator = getImportList().iterator(); |
| 564 | // Run through the imported list to add references. |
| 565 | while (importInfoIterator.hasNext()) { |
| 566 | YangImport yangImport = importInfoIterator.next(); |
| 567 | try { |
| 568 | yangImport.addReferenceToImport(yangFileInfoSet); |
| 569 | } catch (DataModelException e) { |
| 570 | throw new LinkerException(e.getMessage()); |
| 571 | } |
| 572 | } |
| 573 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 574 | } |