Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 20 | import java.util.LinkedList; |
| 21 | import java.util.List; |
| 22 | |
| 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 24 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 26 | import org.onosproject.yangutils.utils.YangConstructType; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.translator.CachedFileHandle; |
| 28 | import org.onosproject.yangutils.translator.GeneratedFileType; |
| 29 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.utils.UtilConstants; |
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 | * Reference RFC 6020. |
| 34 | * |
| 35 | * The "container" statement is used to define an interior data node in the |
| 36 | * schema tree. It takes one argument, which is an identifier, followed by a |
| 37 | * block of sub-statements that holds detailed container information. |
| 38 | * |
| 39 | * A container node does not have a value, but it has a list of child nodes in |
| 40 | * the data tree. The child nodes are defined in the container's sub-statements. |
| 41 | * |
| 42 | * Containers with Presence |
| 43 | * |
| 44 | * YANG supports two styles of containers, those that exist only for organizing |
| 45 | * the hierarchy of data nodes, and those whose presence in the configuration |
| 46 | * has an explicit meaning. |
| 47 | * |
| 48 | * In the first style, the container has no meaning of its own, existing only to |
| 49 | * contain child nodes. This is the default style. |
| 50 | * |
| 51 | * For example, the set of scrambling options for Synchronous Optical Network |
| 52 | * (SONET) interfaces may be placed inside a "scrambling" container to enhance |
| 53 | * the organization of the configuration hierarchy, and to keep these nodes |
| 54 | * together. The "scrambling" node itself has no meaning, so removing the node |
| 55 | * when it becomes empty relieves the user from performing this task. |
| 56 | * |
| 57 | * In the second style, the presence of the container itself is configuration |
| 58 | * data, representing a single bit of configuration data. The container acts as |
| 59 | * both a configuration knob and a means of organizing related configuration. |
| 60 | * These containers are explicitly created and deleted. |
| 61 | * |
| 62 | * YANG calls this style a "presence container" and it is indicated using the |
| 63 | * "presence" statement, which takes as its argument a text string indicating |
| 64 | * what the presence of the node means. |
| 65 | * |
| 66 | * The container's Substatements |
| 67 | * |
| 68 | * +--------------+---------+-------------+------------------+ |
| 69 | * | substatement | section | cardinality |data model mapping| |
| 70 | * +--------------+---------+-------------+------------------+ |
| 71 | * | anyxml | 7.10 | 0..n | -not supported | |
| 72 | * | choice | 7.9 | 0..n | -child nodes | |
| 73 | * | config | 7.19.1 | 0..1 | -boolean | |
| 74 | * | container | 7.5 | 0..n | -child nodes | |
| 75 | * | description | 7.19.3 | 0..1 | -string | |
| 76 | * | grouping | 7.11 | 0..n | -child nodes | |
| 77 | * | if-feature | 7.18.2 | 0..n | -TODO | |
| 78 | * | leaf | 7.6 | 0..n | -YangLeaf | |
| 79 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
| 80 | * | list | 7.8 | 0..n | -child nodes | |
| 81 | * | must | 7.5.3 | 0..n | -TODO | |
| 82 | * | presence | 7.5.5 | 0..1 | -boolean | |
| 83 | * | reference | 7.19.4 | 0..1 | -string | |
| 84 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 85 | * | typedef | 7.3 | 0..n | -child nodes | |
| 86 | * | uses | 7.12 | 0..n | -child nodes | |
| 87 | * | when | 7.19.5 | 0..1 | -TODO | |
| 88 | * +--------------+---------+-------------+------------------+ |
| 89 | */ |
| 90 | |
| 91 | /** |
| 92 | * Data model node to maintain information defined in YANG container. |
| 93 | */ |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 94 | public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Name of the container. |
| 98 | */ |
| 99 | private String name; |
| 100 | |
| 101 | /** |
| 102 | * If container maintains config data. |
| 103 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 104 | private Boolean isConfig; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Description of container. |
| 108 | */ |
| 109 | private String description; |
| 110 | |
| 111 | /** |
| 112 | * List of leaves contained. |
| 113 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 114 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * List of leaf-lists contained. |
| 118 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 119 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * If it is a presence container, then the textual documentation of presence |
| 123 | * usage. |
| 124 | */ |
| 125 | private String presence; |
| 126 | |
| 127 | /** |
| 128 | * Reference of the module. |
| 129 | */ |
| 130 | private String reference; |
| 131 | |
| 132 | /** |
| 133 | * Status of the node. |
| 134 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 135 | private YangStatusType status = YangStatusType.CURRENT; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 136 | |
| 137 | /** |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 138 | * Package of the generated java code. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 139 | */ |
| 140 | private String pkg; |
| 141 | |
| 142 | /** |
| 143 | * Cached Java File Handle. |
| 144 | */ |
| 145 | private CachedFileHandle fileHandle; |
| 146 | |
| 147 | /** |
| 148 | * Create a container node. |
| 149 | */ |
| 150 | public YangContainer() { |
| 151 | super(YangNodeType.CONTAINER_NODE); |
| 152 | } |
| 153 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 154 | /** |
| 155 | * Get the YANG name of container. |
| 156 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 157 | * @return the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 158 | */ |
| 159 | @Override |
| 160 | public String getName() { |
| 161 | return name; |
| 162 | } |
| 163 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 164 | /** |
| 165 | * Set the YANG name of container. |
| 166 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 167 | * @param name the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 168 | */ |
| 169 | @Override |
| 170 | public void setName(String name) { |
| 171 | this.name = name; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get the config flag. |
| 176 | * |
| 177 | * @return the isConfig |
| 178 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 179 | public Boolean isConfig() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 180 | return isConfig; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Set the config flag. |
| 185 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 186 | * @param isCfg the config flag |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 187 | */ |
| 188 | public void setConfig(boolean isCfg) { |
| 189 | isConfig = isCfg; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Get the description. |
| 194 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 195 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 196 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 197 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 198 | public String getDescription() { |
| 199 | return description; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Set the description. |
| 204 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 205 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 206 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 207 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 208 | public void setDescription(String description) { |
| 209 | this.description = description; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Get the list of leaves. |
| 214 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 215 | * @return the list of leaves |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 216 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 217 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 218 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 219 | return listOfLeaf; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Set the list of leaves. |
| 224 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 225 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 226 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 227 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 228 | listOfLeaf = leafsList; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Add a leaf. |
| 233 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 234 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 235 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 236 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 237 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 238 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 239 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | getListOfLeaf().add(leaf); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Get the list of leaf-list. |
| 247 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 248 | * @return the list of leaf-list |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 249 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 250 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 251 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 252 | return listOfLeafList; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Set the list of leaf-list. |
| 257 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 258 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 259 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 260 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 261 | this.listOfLeafList = listOfLeafList; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Add a leaf-list. |
| 266 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 267 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 268 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 269 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 270 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 271 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 272 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | getListOfLeafList().add(leafList); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Get the presence string if present. |
| 280 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 281 | * @return the presence |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 282 | */ |
| 283 | public String getPresence() { |
| 284 | return presence; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Set the presence string. |
| 289 | * |
| 290 | * @param presence the presence flag |
| 291 | */ |
| 292 | public void setPresence(String presence) { |
| 293 | this.presence = presence; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Get the textual reference. |
| 298 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 299 | * @return the reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 300 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 301 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 302 | public String getReference() { |
| 303 | return reference; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Set the textual reference. |
| 308 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 309 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 310 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 311 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 312 | public void setReference(String reference) { |
| 313 | this.reference = reference; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Get the status. |
| 318 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 319 | * @return the status |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 320 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 321 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 322 | public YangStatusType getStatus() { |
| 323 | return status; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Set the status. |
| 328 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 329 | * @param status the status to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 330 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 331 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 332 | public void setStatus(YangStatusType status) { |
| 333 | this.status = status; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Get the cached file handle. |
| 338 | * |
| 339 | * @return the fileHandle |
| 340 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 341 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 342 | public CachedFileHandle getFileHandle() { |
| 343 | return fileHandle; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Set the cached file handle. |
| 348 | * |
| 349 | * @param handle the fileHandle to set |
| 350 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 351 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 352 | public void setFileHandle(CachedFileHandle handle) { |
| 353 | fileHandle = handle; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Returns the type of the data. |
| 358 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 359 | * @return returns CONTAINER_DATA |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 360 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 361 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 362 | public YangConstructType getYangConstructType() { |
| 363 | return YangConstructType.CONTAINER_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Validate the data on entering the corresponding parse tree node. |
| 368 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 369 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 370 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 371 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 372 | public void validateDataOnEntry() throws DataModelException { |
| 373 | // TODO auto-generated method stub, to be implemented by parser |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Validate the data on exiting the corresponding parse tree node. |
| 378 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 379 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 380 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 381 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 382 | public void validateDataOnExit() throws DataModelException { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 383 | List<YangLeaf> leaves = getListOfLeaf(); |
| 384 | List<YangLeafList> leafLists = getListOfLeafList(); |
| 385 | |
| 386 | setDefaultConfigValueToChild(leaves, leafLists); |
| 387 | validateConfig(leaves, leafLists); |
| 388 | } |
| 389 | |
| 390 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 391 | * Sets the config's value to all leaf if leaf's config statement is not |
| 392 | * specified. |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 393 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 394 | * @param leaves list of leaf attributes of container |
| 395 | * @param leafLists list of leaf-list attributes of container |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 396 | */ |
| 397 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
| 398 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 399 | /* |
| 400 | * If "config" is not specified, the default is the same as the parent |
| 401 | * schema node's "config" value. |
| 402 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 403 | if (leaves != null) { |
| 404 | for (YangLeaf leaf : leaves) { |
| 405 | if (leaf.isConfig() == null) { |
| 406 | leaf.setConfig(isConfig); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 411 | /* |
| 412 | * If "config" is not specified, the default is the same as the parent |
| 413 | * schema node's "config" value. |
| 414 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 415 | if (leafLists != null) { |
| 416 | for (YangLeafList leafList : leafLists) { |
| 417 | if (leafList.isConfig() == null) { |
| 418 | leafList.setConfig(isConfig); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Validates config statement of container. |
| 426 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 427 | * @param leaves list of leaf attributes of container |
| 428 | * @param leafLists list of leaf-list attributes of container |
| 429 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 430 | */ |
| 431 | private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException { |
| 432 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 433 | /* |
| 434 | * If a node has "config" set to "false", no node underneath it can have |
| 435 | * "config" set to "true". |
| 436 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 437 | if ((!isConfig) && (leaves != null)) { |
| 438 | for (YangLeaf leaf : leaves) { |
| 439 | if (leaf.isConfig()) { |
| 440 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 441 | "it can have \"config\" set to \"true\"."); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if ((!isConfig) && (leafLists != null)) { |
| 447 | for (YangLeafList leafList : leafLists) { |
| 448 | if (leafList.isConfig()) { |
| 449 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 450 | "it can have \"config\" set to \"true\"."); |
| 451 | } |
| 452 | } |
| 453 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Get the mapped java package. |
| 458 | * |
| 459 | * @return the java package |
| 460 | */ |
| 461 | @Override |
| 462 | public String getPackage() { |
| 463 | return pkg; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Set the mapped java package. |
| 468 | * |
| 469 | * @param pcg the package to set |
| 470 | */ |
| 471 | @Override |
| 472 | public void setPackage(String pcg) { |
| 473 | pkg = pcg; |
| 474 | } |
| 475 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 476 | /** |
| 477 | * Generate the java code corresponding to YANG container. |
| 478 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 479 | * @throws IOException when fails to generate the source files |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 480 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 481 | @Override |
| 482 | public void generateJavaCodeEntry() throws IOException { |
| 483 | YangNode parent = getParent(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 484 | String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName()); |
| 485 | setPackage(contPkg); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 486 | |
| 487 | CachedFileHandle handle = null; |
| 488 | try { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 489 | FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 490 | handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 491 | handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/")); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 492 | } catch (IOException e) { |
| 493 | throw new IOException("Failed to create the source files."); |
| 494 | } |
| 495 | setFileHandle(handle); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 496 | |
| 497 | addLeavesAttributes(); |
| 498 | addLeafListAttributes(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 499 | addAttributeInParent(); |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Adds current node attribute to parent file. |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 504 | */ |
| 505 | private void addAttributeInParent() { |
| 506 | if (getParent() != null) { |
| 507 | getParent().getFileHandle().setChildsPackage(getPackage()); |
| 508 | getParent().getFileHandle().addAttributeInfo(null, getName(), false); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public void generateJavaCodeExit() throws IOException { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 514 | getFileHandle().close(); |
| 515 | return; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Adds leaf attributes in generated files. |
| 520 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 521 | private void addLeavesAttributes() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 522 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 523 | List<YangLeaf> leaves = getListOfLeaf(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 524 | if (leaves != null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 525 | for (YangLeaf leaf : leaves) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 526 | getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false); |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Adds leaf list's attributes in generated files. |
| 533 | */ |
| 534 | private void addLeafListAttributes() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 535 | List<YangLeafList> leavesList = getListOfLeafList(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 536 | if (leavesList != null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 537 | for (YangLeafList leafList : leavesList) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 538 | getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true); |
| 539 | } |
| 540 | } |
| 541 | return; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 542 | } |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame^] | 543 | |
| 544 | @Override |
| 545 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 546 | // Asks helper to detect colliding child. |
| 547 | detectCollidingChildUtil(identifierName, dataType, this); |
| 548 | } |
| 549 | |
| 550 | @Override |
| 551 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
| 552 | if (this.getName().equals(identifierName)) { |
| 553 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \"" |
| 554 | + this.getName() + "\""); |
| 555 | } |
| 556 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 557 | } |