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