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 | */ |
| 274 | public List<YangImport> getImportList() { |
| 275 | return importList; |
| 276 | } |
| 277 | |
| 278 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 279 | * Adds the imported module information to the import list. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 280 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 281 | * @param importedModule module being imported |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 282 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 283 | public void addToImportList(YangImport importedModule) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 284 | getImportList().add(importedModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 285 | } |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 286 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 287 | @Override |
| 288 | public void setImportList(List<YangImport> importList) { |
| 289 | this.importList = importList; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 293 | * Returns the list of included sub modules. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 294 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 295 | * @return the included list of sub modules |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 296 | */ |
| 297 | public List<YangInclude> getIncludeList() { |
| 298 | return includeList; |
| 299 | } |
| 300 | |
| 301 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 302 | * Adds the included sub module information to the include list. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 303 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 304 | * @param includeModule submodule being included |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 305 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 306 | public void addToIncludeList(YangInclude includeModule) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 307 | getIncludeList().add(includeModule); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public void setIncludeList(List<YangInclude> includeList) { |
| 312 | this.includeList = includeList; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 316 | * Returns the list of leaves in module. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 317 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 318 | * @return the list of leaves |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 319 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 320 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 321 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 322 | return listOfLeaf; |
| 323 | } |
| 324 | |
| 325 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 326 | * Adds a leaf in module. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 327 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 328 | * @param leaf the leaf to be added |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 329 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 330 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 331 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 332 | getListOfLeaf().add(leaf); |
| 333 | } |
| 334 | |
| 335 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 336 | * Returns the list of leaf-list from module. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 337 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 338 | * @return the list of leaf-list |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 339 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 340 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 341 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 342 | return listOfLeafList; |
| 343 | } |
| 344 | |
| 345 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 346 | * Adds a leaf-list in module. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 347 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 348 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 349 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 350 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 351 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 352 | getListOfLeafList().add(leafList); |
| 353 | } |
| 354 | |
| 355 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 356 | * Returns the name space of module elements. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 357 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 358 | * @return the nameSpace |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 359 | */ |
| 360 | public YangNameSpace getNameSpace() { |
| 361 | return nameSpace; |
| 362 | } |
| 363 | |
| 364 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 365 | * Sets the name space of module elements. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 366 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 367 | * @param nameSpace the nameSpace to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 368 | */ |
| 369 | public void setNameSpace(YangNameSpace nameSpace) { |
| 370 | this.nameSpace = nameSpace; |
| 371 | } |
| 372 | |
| 373 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 374 | * Returns the modules organization. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 375 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 376 | * @return the organization |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 377 | */ |
| 378 | public String getOrganization() { |
| 379 | return organization; |
| 380 | } |
| 381 | |
| 382 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 383 | * Sets the modules organization. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 384 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 385 | * @param org the organization to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 386 | */ |
| 387 | public void setOrganization(String org) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 388 | organization = org; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 392 | * Returns the prefix. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 393 | * |
| 394 | * @return the prefix |
| 395 | */ |
| 396 | public String getPrefix() { |
| 397 | return prefix; |
| 398 | } |
| 399 | |
| 400 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 401 | * Sets the prefix. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 402 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 403 | * @param prefix the prefix to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 404 | */ |
| 405 | public void setPrefix(String prefix) { |
| 406 | this.prefix = prefix; |
| 407 | } |
| 408 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 409 | @Override |
| 410 | public void resolveSelfFileLinking() throws DataModelException { |
| 411 | // Get the list to be resolved. |
| 412 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(); |
| 413 | // Resolve linking for a resolution list. |
| 414 | resolveLinkingForResolutionList(resolutionList, this); |
| 415 | } |
| 416 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 417 | @Override |
| 418 | public void resolveInterFileLinking() throws DataModelException { |
| 419 | // Get the list to be resolved. |
| 420 | List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(); |
| 421 | // Resolve linking for a resolution list. |
| 422 | linkInterFileReferences(resolutionList, this); |
| 423 | } |
| 424 | |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 425 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 426 | * Returns the textual reference. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 427 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 428 | * @return the reference |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 429 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 430 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 431 | public String getReference() { |
| 432 | return reference; |
| 433 | } |
| 434 | |
| 435 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 436 | * Sets the textual reference. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 437 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 438 | * @param reference the reference to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 439 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 440 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 441 | public void setReference(String reference) { |
| 442 | this.reference = reference; |
| 443 | } |
| 444 | |
| 445 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 446 | * Returns the revision. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 447 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 448 | * @return the revision |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 449 | */ |
| 450 | public YangRevision getRevision() { |
| 451 | return revision; |
| 452 | } |
| 453 | |
| 454 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 455 | * Sets the revision. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 456 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 457 | * @param revision the revision to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 458 | */ |
| 459 | public void setRevision(YangRevision revision) { |
| 460 | this.revision = revision; |
| 461 | } |
| 462 | |
| 463 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 464 | * Returns the version. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 465 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 466 | * @return the version |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 467 | */ |
| 468 | public byte getVersion() { |
| 469 | return version; |
| 470 | } |
| 471 | |
| 472 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 473 | * Sets the version. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 474 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 475 | * @param version the version to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 476 | */ |
| 477 | public void setVersion(byte version) { |
| 478 | this.version = version; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Returns the type of the parsed data. |
| 483 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 484 | * @return returns MODULE_DATA |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 485 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 486 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 487 | public YangConstructType getYangConstructType() { |
| 488 | return YangConstructType.MODULE_DATA; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 492 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 493 | * |
| 494 | * @throws DataModelException a violation of data model rules |
| 495 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 496 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 497 | public void validateDataOnEntry() throws DataModelException { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 498 | /* |
| 499 | * Module is root in the data model tree, hence there is no entry |
| 500 | * validation |
| 501 | */ |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 505 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 506 | * |
| 507 | * @throws DataModelException a violation of data model rules |
| 508 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 509 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 510 | public void validateDataOnExit() throws DataModelException { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 511 | /* |
| 512 | * TODO: perform symbol linking for the imported or included YANG info. |
| 513 | * TODO: perform symbol resolution for referred YANG entities. |
| 514 | */ |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 515 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 516 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 517 | @Override |
| 518 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 519 | // Asks helper to detect colliding child. |
| 520 | detectCollidingChildUtil(identifierName, dataType, this); |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
| 525 | // Not required as module doesn't have any parent. |
| 526 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 527 | |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 528 | @Override |
| 529 | public List<YangResolutionInfo> getUnresolvedResolutionList() { |
| 530 | return unresolvedResolutionList; |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public void addToResolutionList(YangResolutionInfo resolutionInfo) { |
| 535 | unresolvedResolutionList.add(resolutionInfo); |
| 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public void setResolutionList(List<YangResolutionInfo> resolutionList) { |
| 540 | unresolvedResolutionList = resolutionList; |
| 541 | } |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 542 | |
| 543 | @Override |
| 544 | public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) |
| 545 | throws LinkerException { |
| 546 | Iterator<YangImport> importInfoIterator = getImportList().iterator(); |
| 547 | // Run through the imported list to add references. |
| 548 | while (importInfoIterator.hasNext()) { |
| 549 | YangImport yangImport = importInfoIterator.next(); |
| 550 | try { |
| 551 | yangImport.addReferenceToImport(yangFileInfoSet); |
| 552 | } catch (DataModelException e) { |
| 553 | throw new LinkerException(e.getMessage()); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) |
| 560 | throws LinkerException { |
| 561 | Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator(); |
| 562 | // Run through the included list to add references. |
| 563 | while (includeInfoIterator.hasNext()) { |
| 564 | YangInclude yangInclude = includeInfoIterator.next(); |
| 565 | YangSubModule subModule = null; |
| 566 | try { |
| 567 | subModule = yangInclude.addReferenceToInclude(yangFileInfoSet); |
| 568 | } catch (DataModelException e) { |
| 569 | throw new LinkerException(e.getMessage()); |
| 570 | } |
| 571 | // Check if the referred sub-modules parent is self |
| 572 | if (!(subModule.getBelongsTo().getModuleNode() == this)) { |
| 573 | try { |
| 574 | yangInclude.reportIncludeError(); |
| 575 | } catch (DataModelException e) { |
| 576 | throw new LinkerException(e.getMessage()); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 581 | } |