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; |
| 23 | import org.onosproject.yangutils.parser.Parsable; |
| 24 | import org.onosproject.yangutils.utils.YangConstructType; |
| 25 | |
| 26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 29 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 30 | /* |
| 31 | * Reference RFC 6020. |
| 32 | * |
| 33 | * While the primary unit in YANG is a module, a YANG module can itself |
| 34 | * be constructed out of several submodules. Submodules allow a module |
| 35 | * designer to split a complex model into several pieces where all the |
| 36 | * submodules contribute to a single namespace, which is defined by the |
| 37 | * module that includes the submodules. |
| 38 | * |
| 39 | * The "submodule" statement defines the submodule's name, and groups |
| 40 | * all statements that belong to the submodule together. The |
| 41 | * "submodule" statement's argument is the name of the submodule, |
| 42 | * followed by a block of sub-statements that hold detailed submodule |
| 43 | * information. |
| 44 | * |
| 45 | * The submodule's sub-statements |
| 46 | * |
| 47 | * +--------------+---------+-------------+------------------+ |
| 48 | * | substatement | section | cardinality |data model mapping| |
| 49 | * +--------------+---------+-------------+------------------+ |
| 50 | * | anyxml | 7.10 | 0..n | - not supported | |
| 51 | * | augment | 7.15 | 0..n | - child nodes | |
| 52 | * | belongs-to | 7.2.2 | 1 | - YangBelongsTo | |
| 53 | * | choice | 7.9 | 0..n | - child nodes | |
| 54 | * | contact | 7.1.8 | 0..1 | - string | |
| 55 | * | container | 7.5 | 0..n | - child nodes | |
| 56 | * | description | 7.19.3 | 0..1 | - string | |
| 57 | * | deviation | 7.18.3 | 0..n | - TODO | |
| 58 | * | extension | 7.17 | 0..n | - TODO | |
| 59 | * | feature | 7.18.1 | 0..n | - TODO | |
| 60 | * | grouping | 7.11 | 0..n | - child nodes | |
| 61 | * | identity | 7.16 | 0..n | - TODO | |
| 62 | * | import | 7.1.5 | 0..n | - YangImport | |
| 63 | * | include | 7.1.6 | 0..n | - YangInclude | |
| 64 | * | leaf | 7.6 | 0..n | - YangLeaf | |
| 65 | * | leaf-list | 7.7 | 0..n | - YangLeafList | |
| 66 | * | list | 7.8 | 0..n | - child nodes | |
| 67 | * | notification | 7.14 | 0..n | - TODO | |
| 68 | * | organization | 7.1.7 | 0..1 | - string | |
| 69 | * | reference | 7.19.4 | 0..1 | - string | |
| 70 | * | revision | 7.1.9 | 0..n | - string | |
| 71 | * | rpc | 7.13 | 0..n | - TODO | |
| 72 | * | typedef | 7.3 | 0..n | - child nodes | |
| 73 | * | uses | 7.12 | 0..n | - child nodes | |
| 74 | * | YANG-version | 7.1.2 | 0..1 | - int | |
| 75 | * +--------------+---------+-------------+------------------+ |
| 76 | */ |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 77 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 78 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 79 | * 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] | 80 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 81 | public class YangSubModule |
| 82 | extends YangNode |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, |
| 84 | RpcNotificationContainer { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Name of sub module. |
| 88 | */ |
| 89 | private String name; |
| 90 | |
| 91 | /** |
| 92 | * Module to which it belongs to. |
| 93 | */ |
| 94 | private YangBelongsTo belongsTo; |
| 95 | |
| 96 | /** |
| 97 | * Reference RFC 6020. |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 98 | * <p> |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 99 | * The "contact" statement provides contact information for the module. The |
| 100 | * argument is a string that is used to specify contact information for the |
| 101 | * person or persons to whom technical queries concerning this module should |
| 102 | * be sent, such as their name, postal address, telephone number, and |
| 103 | * electronic mail address. |
| 104 | */ |
| 105 | private String contact; |
| 106 | |
| 107 | /** |
| 108 | * Description. |
| 109 | */ |
| 110 | private String description; |
| 111 | |
| 112 | /** |
| 113 | * List of YANG modules imported. |
| 114 | */ |
| 115 | private List<YangImport> importList; |
| 116 | |
| 117 | /** |
| 118 | * List of YANG sub-modules included. |
| 119 | */ |
| 120 | private List<YangInclude> includeList; |
| 121 | |
| 122 | /** |
| 123 | * List of leaves at root level in the sub-module. |
| 124 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 125 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * List of leaf-lists at root level in the sub-module. |
| 129 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 130 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 131 | |
| 132 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 133 | * Organization owner of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 134 | */ |
| 135 | private String organization; |
| 136 | |
| 137 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 138 | * Reference of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 139 | */ |
| 140 | private String reference; |
| 141 | |
| 142 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 143 | * Revision info of the sub-module. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 144 | */ |
| 145 | private YangRevision revision; |
| 146 | |
| 147 | /** |
| 148 | * YANG version. |
| 149 | */ |
| 150 | private byte version; |
| 151 | |
| 152 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 153 | * Prefix of parent module. |
| 154 | */ |
| 155 | private String prefix; |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 156 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 157 | /*- |
| 158 | * Reference RFC 6020. |
| 159 | * |
| 160 | * Nested typedefs and groupings. |
| 161 | * Typedefs and groupings may appear nested under many YANG statements, |
| 162 | * allowing these to be lexically scoped by the hierarchy under which |
| 163 | * they appear. This allows types and groupings to be defined near |
| 164 | * where they are used, rather than placing them at the top level of the |
| 165 | * hierarchy. The close proximity increases readability. |
| 166 | * |
| 167 | * Scoping also allows types to be defined without concern for naming |
| 168 | * conflicts between types in different submodules. Type names can be |
| 169 | * specified without adding leading strings designed to prevent name |
| 170 | * collisions within large modules. |
| 171 | * |
| 172 | * Finally, scoping allows the module author to keep types and groupings |
| 173 | * private to their module or submodule, preventing their reuse. Since |
| 174 | * only top-level types and groupings (i.e., those appearing as |
| 175 | * sub-statements to a module or submodule statement) can be used outside |
| 176 | * the module or submodule, the developer has more control over what |
| 177 | * pieces of their module are presented to the outside world, supporting |
| 178 | * the need to hide internal information and maintaining a boundary |
| 179 | * between what is shared with the outside world and what is kept |
| 180 | * private. |
| 181 | * |
| 182 | * Scoped definitions MUST NOT shadow definitions at a higher scope. A |
| 183 | * type or grouping cannot be defined if a higher level in the schema |
| 184 | * hierarchy has a definition with a matching identifier. |
| 185 | * |
| 186 | * A reference to an unprefixed type or grouping, or one which uses the |
| 187 | * prefix of the current module, is resolved by locating the closest |
| 188 | * matching "typedef" or "grouping" statement among the immediate |
| 189 | * sub-statements of each ancestor statement. |
| 190 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 191 | private List<YangResolutionInfo> derivedTypeResolutionList; |
| 192 | |
| 193 | /** |
| 194 | * uses resolution list. |
| 195 | */ |
| 196 | private List<YangResolutionInfo> usesResolutionList; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 197 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 198 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 199 | * Creates a sub module node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 200 | */ |
| 201 | public YangSubModule() { |
| 202 | super(YangNodeType.SUB_MODULE_NODE); |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 203 | derivedTypeResolutionList = new LinkedList<>(); |
| 204 | usesResolutionList = new LinkedList<>(); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 205 | importList = new LinkedList<YangImport>(); |
| 206 | includeList = new LinkedList<YangInclude>(); |
| 207 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 208 | listOfLeafList = new LinkedList<YangLeafList>(); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 211 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 212 | * Returns the YANG name of the sub module. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 213 | * |
| 214 | * @return YANG name of the sub module |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 215 | */ |
| 216 | @Override |
| 217 | public String getName() { |
| 218 | return name; |
| 219 | } |
| 220 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 221 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 222 | * Sets YANG name of the sub module. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 223 | * |
| 224 | * @param subModuleName YANG name of the sub module |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 225 | */ |
| 226 | @Override |
| 227 | public void setName(String subModuleName) { |
| 228 | name = subModuleName; |
| 229 | } |
| 230 | |
| 231 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 232 | * Returns the module info. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 233 | * |
| 234 | * @return the belongs to info |
| 235 | */ |
| 236 | public YangBelongsTo getBelongsTo() { |
| 237 | return belongsTo; |
| 238 | } |
| 239 | |
| 240 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 241 | * Sets the module info. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 242 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 243 | * @param belongsTo module info to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 244 | */ |
| 245 | public void setBelongsTo(YangBelongsTo belongsTo) { |
| 246 | this.belongsTo = belongsTo; |
| 247 | } |
| 248 | |
| 249 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 250 | * Returns the contact. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 251 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 252 | * @return the contact |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 253 | */ |
| 254 | public String getContact() { |
| 255 | return contact; |
| 256 | } |
| 257 | |
| 258 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 259 | * Sets the contact. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 260 | * |
| 261 | * @param contact the contact to set |
| 262 | */ |
| 263 | public void setContact(String contact) { |
| 264 | this.contact = contact; |
| 265 | } |
| 266 | |
| 267 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 268 | * Returns the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 269 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 270 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 271 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 272 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 273 | public String getDescription() { |
| 274 | return description; |
| 275 | } |
| 276 | |
| 277 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 278 | * Sets the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 279 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 280 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 281 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 282 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 283 | public void setDescription(String description) { |
| 284 | this.description = description; |
| 285 | } |
| 286 | |
| 287 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 288 | * Returns the list of imported modules. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 289 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 290 | * @return the list of imported modules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 291 | */ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 292 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 293 | public List<YangImport> getImportList() { |
| 294 | return importList; |
| 295 | } |
| 296 | |
| 297 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 298 | * Adds the imported module information to the import list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 299 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 300 | * @param importedModule module being imported |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 301 | */ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 302 | @Override |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 303 | public void addToImportList(YangImport importedModule) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 304 | getImportList().add(importedModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 305 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 306 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 307 | @Override |
| 308 | public void setImportList(List<YangImport> importList) { |
| 309 | this.importList = importList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 313 | * Returns the list of included sub modules. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 314 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 315 | * @return the included list of sub modules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 316 | */ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 317 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 318 | public List<YangInclude> getIncludeList() { |
| 319 | return includeList; |
| 320 | } |
| 321 | |
| 322 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 323 | * Returns the included sub module information to the include list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 324 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 325 | * @param includeModule submodule being included |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 326 | */ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 327 | @Override |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 328 | public void addToIncludeList(YangInclude includeModule) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 329 | getIncludeList().add(includeModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public void setIncludeList(List<YangInclude> includeList) { |
| 334 | this.includeList = includeList; |
| 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public String getPrefix() { |
| 339 | return prefix; |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void setPrefix(String prefix) { |
| 344 | this.prefix = prefix; |
| 345 | } |
| 346 | |
| 347 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 348 | public void resolveSelfFileLinking(ResolvableType type) |
| 349 | throws DataModelException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 350 | // Get the list to be resolved. |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 351 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 352 | // Resolve linking for a resolution list. |
| 353 | resolveLinkingForResolutionList(resolutionList, this); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 354 | } |
| 355 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 356 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 357 | public void resolveInterFileLinking(ResolvableType type) |
| 358 | throws DataModelException { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 359 | // Get the list to be resolved. |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 360 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 361 | // Resolve linking for a resolution list. |
| 362 | linkInterFileReferences(resolutionList, this); |
| 363 | } |
| 364 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 365 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 366 | * Returns the list of leaves. |
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 | * @return the list of leaves |
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 List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 372 | return listOfLeaf; |
| 373 | } |
| 374 | |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 375 | @Override |
| 376 | public void setListOfLeaf(List<YangLeaf> leafsList) { |
| 377 | listOfLeaf = leafsList; |
| 378 | } |
| 379 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 380 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 381 | * Adds a leaf. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 382 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 383 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 384 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 385 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 386 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 387 | getListOfLeaf().add(leaf); |
| 388 | } |
| 389 | |
| 390 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 391 | * Returns the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 392 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 393 | * @return the list of leaf-list |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 394 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 395 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 396 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 397 | return listOfLeafList; |
| 398 | } |
| 399 | |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 400 | @Override |
| 401 | public void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
| 402 | this.listOfLeafList = listOfLeafList; |
| 403 | } |
| 404 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 405 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 406 | * Adds a leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 407 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 408 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 409 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 410 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 411 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 412 | getListOfLeafList().add(leafList); |
| 413 | } |
| 414 | |
| 415 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 416 | * Returns the sub-modules organization. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 417 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 418 | * @return the organization |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 419 | */ |
| 420 | public String getOrganization() { |
| 421 | return organization; |
| 422 | } |
| 423 | |
| 424 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 425 | * Sets the sub-modules organization. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 426 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 427 | * @param org the organization to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 428 | */ |
| 429 | public void setOrganization(String org) { |
| 430 | organization = org; |
| 431 | } |
| 432 | |
| 433 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 434 | * Returns the textual reference. |
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 reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 437 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 438 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 439 | public String getReference() { |
| 440 | return reference; |
| 441 | } |
| 442 | |
| 443 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 444 | * Sets the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 445 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 446 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 447 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 448 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 449 | public void setReference(String reference) { |
| 450 | this.reference = reference; |
| 451 | } |
| 452 | |
| 453 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 454 | * Returns the revision. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 455 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 456 | * @return the revision |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 457 | */ |
| 458 | public YangRevision getRevision() { |
| 459 | return revision; |
| 460 | } |
| 461 | |
| 462 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 463 | * Sets the revision. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 464 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 465 | * @param revision the revision to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 466 | */ |
| 467 | public void setRevision(YangRevision revision) { |
| 468 | this.revision = revision; |
| 469 | } |
| 470 | |
| 471 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 472 | * Returns the version. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 473 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 474 | * @return the version |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 475 | */ |
| 476 | public byte getVersion() { |
| 477 | return version; |
| 478 | } |
| 479 | |
| 480 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 481 | * Sets the version. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 482 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 483 | * @param version the version to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 484 | */ |
| 485 | public void setVersion(byte version) { |
| 486 | this.version = version; |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Returns the type of the parsed data. |
| 491 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 492 | * @return returns SUB_MODULE_DATA |
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 |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 495 | public YangConstructType getYangConstructType() { |
| 496 | return YangConstructType.SUB_MODULE_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 500 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 501 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 502 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 503 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 504 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 505 | public void validateDataOnEntry() |
| 506 | throws DataModelException { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 507 | // TODO auto-generated method stub, to be implemented by parser |
| 508 | } |
| 509 | |
| 510 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 511 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 512 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 513 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 514 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 515 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 516 | public void validateDataOnExit() |
| 517 | throws DataModelException { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 518 | // TODO auto-generated method stub, to be implemented by parser |
| 519 | } |
| 520 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 521 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 522 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 523 | throws DataModelException { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 524 | // Asks helper to detect colliding child. |
| 525 | detectCollidingChildUtil(identifierName, dataType, this); |
| 526 | } |
| 527 | |
| 528 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 529 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 530 | throws DataModelException { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 531 | // Not required as module doesn't have any parent. |
| 532 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 533 | |
| 534 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 535 | public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) { |
| 536 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { |
| 537 | return derivedTypeResolutionList; |
| 538 | } else { |
| 539 | return usesResolutionList; |
| 540 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 544 | public void addToResolutionList(YangResolutionInfo resolutionInfo, |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 545 | ResolvableType type) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 546 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { |
| 547 | derivedTypeResolutionList.add(resolutionInfo); |
| 548 | } else if (type == ResolvableType.YANG_USES) { |
| 549 | usesResolutionList.add(resolutionInfo); |
| 550 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | @Override |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 554 | public void setResolutionList(List<YangResolutionInfo> resolutionList, |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 555 | ResolvableType type) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 556 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { |
| 557 | derivedTypeResolutionList = resolutionList; |
| 558 | } else if (type == ResolvableType.YANG_USES) { |
| 559 | usesResolutionList = resolutionList; |
| 560 | } |
| 561 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 562 | } |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Links the sub-module with module. |
| 566 | * |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 567 | * @param yangNodeSet YANG file information set |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 568 | * @throws DataModelException a violation in data model rule |
| 569 | */ |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 570 | public void linkWithModule(Set<YangNode> yangNodeSet) |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 571 | throws DataModelException { |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 572 | getBelongsTo().linkWithModule(yangNodeSet); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | @Override |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 576 | public void addReferencesToIncludeList(Set<YangNode> yangNodeSet) |
| 577 | throws DataModelException { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 578 | Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator(); |
| 579 | // Run through the included list to add references. |
| 580 | while (includeInfoIterator.hasNext()) { |
| 581 | YangInclude yangInclude = includeInfoIterator.next(); |
| 582 | YangSubModule subModule = null; |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 583 | subModule = yangInclude.addReferenceToInclude(yangNodeSet); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 584 | // Check if the referred sub-modules parent is self |
| 585 | if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) { |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 586 | yangInclude.reportIncludeError(); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | @Override |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 592 | public void addReferencesToImportList(Set<YangNode> yangNodeSet) |
| 593 | throws DataModelException { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 594 | Iterator<YangImport> importInfoIterator = getImportList().iterator(); |
| 595 | // Run through the imported list to add references. |
| 596 | while (importInfoIterator.hasNext()) { |
| 597 | YangImport yangImport = importInfoIterator.next(); |
Gaurav Agrawal | 58b348e | 2016-06-07 14:00:26 +0530 | [diff] [blame^] | 598 | yangImport.addReferenceToImport(yangNodeSet); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 599 | } |
| 600 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 601 | } |