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