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