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