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 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 18 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 19 | |
| 20 | import java.io.IOException; |
| 21 | import java.util.LinkedList; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.parser.Parsable; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.translator.CachedFileHandle; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.translator.CodeGenerator; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.translator.GeneratedFileType; |
| 29 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.utils.YangConstructType; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 32 | |
| 33 | /*- |
Vinod Kumar S | 0e12297 | 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 | 0e12297 | 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 | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 76 | public class YangModule extends YangNode |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 77 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator, CollisionDetector { |
Vinod Kumar S | 0e12297 | 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 | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 86 | * |
Vinod Kumar S | 0e12297 | 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 | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 97 | * |
Vinod Kumar S | 0e12297 | 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 | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 118 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 0e12297 | 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 | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 123 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 0e12297 | 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 | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 132 | * |
Vinod Kumar S | 0e12297 | 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 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 161 | * Cached Java File Handle. |
| 162 | */ |
| 163 | private CachedFileHandle fileHandle; |
| 164 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 165 | /*- |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 166 | * Reference RFC 6020. |
| 167 | * |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 168 | * Nested typedefs and groupings. |
| 169 | * Typedefs and groupings may appear nested under many YANG statements, |
| 170 | * allowing these to be lexically scoped by the hierarchy under which |
| 171 | * they appear. This allows types and groupings to be defined near |
| 172 | * where they are used, rather than placing them at the top level of the |
| 173 | * hierarchy. The close proximity increases readability. |
| 174 | * |
| 175 | * Scoping also allows types to be defined without concern for naming |
| 176 | * conflicts between types in different submodules. Type names can be |
| 177 | * specified without adding leading strings designed to prevent name |
| 178 | * collisions within large modules. |
| 179 | * |
| 180 | * Finally, scoping allows the module author to keep types and groupings |
| 181 | * private to their module or submodule, preventing their reuse. Since |
| 182 | * only top-level types and groupings (i.e., those appearing as |
| 183 | * sub-statements to a module or submodule statement) can be used outside |
| 184 | * the module or submodule, the developer has more control over what |
| 185 | * pieces of their module are presented to the outside world, supporting |
| 186 | * the need to hide internal information and maintaining a boundary |
| 187 | * between what is shared with the outside world and what is kept |
| 188 | * private. |
| 189 | * |
| 190 | * Scoped definitions MUST NOT shadow definitions at a higher scope. A |
| 191 | * type or grouping cannot be defined if a higher level in the schema |
| 192 | * hierarchy has a definition with a matching identifier. |
| 193 | * |
| 194 | * A reference to an unprefixed type or grouping, or one which uses the |
| 195 | * prefix of the current module, is resolved by locating the closest |
| 196 | * matching "typedef" or "grouping" statement among the immediate |
| 197 | * sub-statements of each ancestor statement. |
| 198 | */ |
| 199 | /** |
| 200 | * List of nodes which require nested reference resolution. |
| 201 | */ |
| 202 | private List<YangNode> nestedReferenceResoulutionList; |
| 203 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 204 | /** |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 205 | * Create a YANG node of module type. |
| 206 | */ |
| 207 | public YangModule() { |
| 208 | super(YangNodeType.MODULE_NODE); |
| 209 | } |
| 210 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 211 | /** |
| 212 | * Get name of the module. |
| 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 | /** |
| 222 | * Set module name. |
| 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 | /** |
| 232 | * Get the contact details of the module owner. |
| 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 | /** |
| 241 | * Set the contact details of the module owner. |
| 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 | /** |
| 250 | * Get the description of module. |
| 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 | /** |
| 260 | * Set the description of module. |
| 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 | /** |
| 270 | * Get the list of imported modules. |
| 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 | /** |
| 279 | * prevent setting the import list from outside. |
| 280 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 281 | * @param importList the import list to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 282 | */ |
| 283 | private void setImportList(List<YangImport> importList) { |
| 284 | this.importList = importList; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Add the imported module information to the import list. |
| 289 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 290 | * @param importedModule module being imported |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 291 | */ |
| 292 | public void addImportedInfo(YangImport importedModule) { |
| 293 | |
| 294 | if (getImportList() == null) { |
| 295 | setImportList(new LinkedList<YangImport>()); |
| 296 | } |
| 297 | |
| 298 | getImportList().add(importedModule); |
| 299 | |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Get the list of included sub modules. |
| 305 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 306 | * @return the included list of sub modules |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 307 | */ |
| 308 | public List<YangInclude> getIncludeList() { |
| 309 | return includeList; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Set the list of included sub modules. |
| 314 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 315 | * @param includeList the included list to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 316 | */ |
| 317 | private void setIncludeList(List<YangInclude> includeList) { |
| 318 | this.includeList = includeList; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Add the included sub module information to the include list. |
| 323 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 324 | * @param includeModule submodule being included |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 325 | */ |
| 326 | public void addIncludedInfo(YangInclude includeModule) { |
| 327 | |
| 328 | if (getIncludeList() == null) { |
| 329 | setIncludeList(new LinkedList<YangInclude>()); |
| 330 | } |
| 331 | |
| 332 | getIncludeList().add(includeModule); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Get the list of leaves in module. |
| 338 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 339 | * @return the list of leaves |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 340 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 341 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 342 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 343 | return listOfLeaf; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Set the list of leaf in module. |
| 348 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 349 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 350 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 351 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 352 | listOfLeaf = leafsList; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Add a leaf in module. |
| 357 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 358 | * @param leaf the leaf to be added |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 359 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 360 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 361 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 362 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 363 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | getListOfLeaf().add(leaf); |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Get the list of leaf-list from module. |
| 371 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 372 | * @return the list of leaf-list |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 373 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 374 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 375 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 376 | return listOfLeafList; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Set the list of leaf-list in module. |
| 381 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 382 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 383 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 384 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 385 | this.listOfLeafList = listOfLeafList; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Add a leaf-list in module. |
| 390 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 391 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 392 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 393 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 394 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 395 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 396 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | getListOfLeafList().add(leafList); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Get the name space of module elements. |
| 404 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 405 | * @return the nameSpace |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 406 | */ |
| 407 | public YangNameSpace getNameSpace() { |
| 408 | return nameSpace; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Set the name space of module elements. |
| 413 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 414 | * @param nameSpace the nameSpace to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 415 | */ |
| 416 | public void setNameSpace(YangNameSpace nameSpace) { |
| 417 | this.nameSpace = nameSpace; |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Get the modules organization. |
| 422 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 423 | * @return the organization |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 424 | */ |
| 425 | public String getOrganization() { |
| 426 | return organization; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Set the modules organization. |
| 431 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 432 | * @param org the organization to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 433 | */ |
| 434 | public void setOrganization(String org) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 435 | organization = org; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Get the prefix. |
| 440 | * |
| 441 | * @return the prefix |
| 442 | */ |
| 443 | public String getPrefix() { |
| 444 | return prefix; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Set the prefix. |
| 449 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 450 | * @param prefix the prefix to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 451 | */ |
| 452 | public void setPrefix(String prefix) { |
| 453 | this.prefix = prefix; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Get the textual reference. |
| 458 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 459 | * @return the reference |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 460 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 461 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 462 | public String getReference() { |
| 463 | return reference; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Set the textual reference. |
| 468 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 469 | * @param reference the reference to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 470 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 471 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 472 | public void setReference(String reference) { |
| 473 | this.reference = reference; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Get the revision. |
| 478 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 479 | * @return the revision |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 480 | */ |
| 481 | public YangRevision getRevision() { |
| 482 | return revision; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Set the revision. |
| 487 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 488 | * @param revision the revision to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 489 | */ |
| 490 | public void setRevision(YangRevision revision) { |
| 491 | this.revision = revision; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Get the version. |
| 496 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 497 | * @return the version |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 498 | */ |
| 499 | public byte getVersion() { |
| 500 | return version; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Set the version. |
| 505 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 506 | * @param version the version to set |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 507 | */ |
| 508 | public void setVersion(byte version) { |
| 509 | this.version = version; |
| 510 | } |
| 511 | |
| 512 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 513 | * Get the mapped java package. |
| 514 | * |
| 515 | * @return the java package |
| 516 | */ |
| 517 | @Override |
| 518 | public String getPackage() { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 519 | if (getFileHandle() != null) { |
| 520 | return getFileHandle().getRelativeFilePath().replace("/", "."); |
| 521 | } |
| 522 | return null; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 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) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 532 | if (getFileHandle() != null) { |
| 533 | pcg.replace(".", "/"); |
| 534 | getFileHandle().setRelativeFilePath(pcg); |
| 535 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Get the cached file handle. |
| 540 | * |
| 541 | * @return the fileHandle |
| 542 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 543 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 544 | public CachedFileHandle getFileHandle() { |
| 545 | return fileHandle; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Set the cached file handle. |
| 550 | * |
| 551 | * @param handle the fileHandle to set |
| 552 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 553 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 554 | public void setFileHandle(CachedFileHandle handle) { |
| 555 | fileHandle = handle; |
| 556 | } |
| 557 | |
| 558 | /** |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 559 | * Get the list of nested reference's which required resolution. |
| 560 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 561 | * @return list of nested reference's which required resolution |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 562 | */ |
| 563 | public List<YangNode> getNestedReferenceResoulutionList() { |
| 564 | return nestedReferenceResoulutionList; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Set list of nested reference's which requires resolution. |
| 569 | * |
| 570 | * @param nestedReferenceResoulutionList list of nested reference's which |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 571 | * requires resolution |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 572 | */ |
| 573 | private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) { |
| 574 | this.nestedReferenceResoulutionList = nestedReferenceResoulutionList; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Set list of nested reference's which requires resolution. |
| 579 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 580 | * @param nestedReference nested reference which requires resolution |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 581 | */ |
| 582 | public void addToNestedReferenceResoulutionList(YangNode nestedReference) { |
| 583 | if (getNestedReferenceResoulutionList() == null) { |
| 584 | setNestedReferenceResoulutionList(new LinkedList<YangNode>()); |
| 585 | } |
| 586 | getNestedReferenceResoulutionList().add(nestedReference); |
| 587 | } |
| 588 | |
| 589 | /** |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 590 | * Returns the type of the parsed data. |
| 591 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 592 | * @return returns MODULE_DATA |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 593 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 594 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 595 | public YangConstructType getYangConstructType() { |
| 596 | return YangConstructType.MODULE_DATA; |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Validate the data on entering the corresponding parse tree node. |
| 601 | * |
| 602 | * @throws DataModelException a violation of data model rules |
| 603 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 604 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 605 | public void validateDataOnEntry() throws DataModelException { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 606 | /* |
| 607 | * Module is root in the data model tree, hence there is no entry |
| 608 | * validation |
| 609 | */ |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Validate the data on exiting the corresponding parse tree node. |
| 614 | * |
| 615 | * @throws DataModelException a violation of data model rules |
| 616 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 617 | @Override |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 618 | public void validateDataOnExit() throws DataModelException { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 619 | /* |
| 620 | * TODO: perform symbol linking for the imported or included YANG info. |
| 621 | * TODO: perform symbol resolution for referred YANG entities. |
| 622 | */ |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 623 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * Generates java code for module. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 627 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 628 | * @param codeGenDir code generation directory |
| 629 | * @throws IOException when fails to generate the source files |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 630 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 631 | @Override |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 632 | public void generateJavaCodeEntry(String codeGenDir) throws IOException { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 633 | String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(), |
| 634 | getRevision().getRevDate()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 635 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 636 | modPkg = JavaIdentifierSyntax.getCamelCase(modPkg); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 637 | CachedFileHandle handle = null; |
| 638 | try { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 639 | FileSystemUtil.createPackage(codeGenDir + modPkg, getName()); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 640 | handle = FileSystemUtil.createSourceFiles(modPkg, getName(), |
| 641 | GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 642 | handle.setCodeGenFilePath(codeGenDir); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 643 | } catch (IOException e) { |
| 644 | throw new IOException("Failed to create the source files."); |
| 645 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 646 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 647 | setFileHandle(handle); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 648 | addLeavesAttributes(); |
| 649 | addLeafListAttributes(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | @Override |
| 653 | public void generateJavaCodeExit() throws IOException { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 654 | getFileHandle().close(); |
| 655 | return; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Adds leaf attributes in generated files. |
| 660 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 661 | private void addLeavesAttributes() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 662 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 663 | List<YangLeaf> leaves = getListOfLeaf(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 664 | if (leaves != null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 665 | for (YangLeaf leaf : leaves) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 666 | getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false); |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Adds leaf list's attributes in generated files. |
| 673 | */ |
| 674 | private void addLeafListAttributes() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 675 | List<YangLeafList> leavesList = getListOfLeafList(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 676 | if (leavesList != null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 677 | for (YangLeafList leafList : leavesList) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 678 | getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true); |
| 679 | } |
| 680 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 681 | } |
| 682 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 683 | /** |
| 684 | * Add a type to resolve the nested references. |
| 685 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 686 | * @param node grouping or typedef node which needs to be resolved |
| 687 | * @throws DataModelException data model exception |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 688 | */ |
| 689 | public static void addToResolveList(YangNode node) throws DataModelException { |
| 690 | /* get the module node to add maintain the list of nested reference */ |
| 691 | YangModule module; |
| 692 | YangNode curNode = node; |
| 693 | while (curNode.getNodeType() != YangNodeType.MODULE_NODE) { |
| 694 | curNode = curNode.getParent(); |
| 695 | if (curNode == null) { |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | if (curNode == null) { |
| 700 | throw new DataModelException("Datamodel tree is not correct"); |
| 701 | } |
| 702 | |
| 703 | module = (YangModule) curNode; |
| 704 | module.addToNestedReferenceResoulutionList(node); |
| 705 | return; |
| 706 | } |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 707 | |
| 708 | @Override |
| 709 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 710 | // Asks helper to detect colliding child. |
| 711 | detectCollidingChildUtil(identifierName, dataType, this); |
| 712 | } |
| 713 | |
| 714 | @Override |
| 715 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
| 716 | // Not required as module doesn't have any parent. |
| 717 | } |
Vinod Kumar S | 0e12297 | 2016-02-09 20:14:53 +0530 | [diff] [blame] | 718 | } |