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 | |
| 19 | import java.util.LinkedList; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 23 | import org.onosproject.yangutils.parser.Parsable; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 25 | |
| 26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 27 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 28 | /*- |
| 29 | * Reference RFC 6020. |
| 30 | * |
| 31 | * The "container" statement is used to define an interior data node in the |
| 32 | * schema tree. It takes one argument, which is an identifier, followed by a |
| 33 | * block of sub-statements that holds detailed container information. |
| 34 | * |
| 35 | * A container node does not have a value, but it has a list of child nodes in |
| 36 | * the data tree. The child nodes are defined in the container's sub-statements. |
| 37 | * |
| 38 | * Containers with Presence |
| 39 | * |
| 40 | * YANG supports two styles of containers, those that exist only for organizing |
| 41 | * the hierarchy of data nodes, and those whose presence in the configuration |
| 42 | * has an explicit meaning. |
| 43 | * |
| 44 | * In the first style, the container has no meaning of its own, existing only to |
| 45 | * contain child nodes. This is the default style. |
| 46 | * |
| 47 | * For example, the set of scrambling options for Synchronous Optical Network |
| 48 | * (SONET) interfaces may be placed inside a "scrambling" container to enhance |
| 49 | * the organization of the configuration hierarchy, and to keep these nodes |
| 50 | * together. The "scrambling" node itself has no meaning, so removing the node |
| 51 | * when it becomes empty relieves the user from performing this task. |
| 52 | * |
| 53 | * In the second style, the presence of the container itself is configuration |
| 54 | * data, representing a single bit of configuration data. The container acts as |
| 55 | * both a configuration knob and a means of organizing related configuration. |
| 56 | * These containers are explicitly created and deleted. |
| 57 | * |
| 58 | * YANG calls this style a "presence container" and it is indicated using the |
| 59 | * "presence" statement, which takes as its argument a text string indicating |
| 60 | * what the presence of the node means. |
| 61 | * |
| 62 | * The container's Substatements |
| 63 | * |
| 64 | * +--------------+---------+-------------+------------------+ |
| 65 | * | substatement | section | cardinality |data model mapping| |
| 66 | * +--------------+---------+-------------+------------------+ |
| 67 | * | anyxml | 7.10 | 0..n | -not supported | |
| 68 | * | choice | 7.9 | 0..n | -child nodes | |
| 69 | * | config | 7.19.1 | 0..1 | -boolean | |
| 70 | * | container | 7.5 | 0..n | -child nodes | |
| 71 | * | description | 7.19.3 | 0..1 | -string | |
| 72 | * | grouping | 7.11 | 0..n | -child nodes | |
| 73 | * | if-feature | 7.18.2 | 0..n | -TODO | |
| 74 | * | leaf | 7.6 | 0..n | -YangLeaf | |
| 75 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
| 76 | * | list | 7.8 | 0..n | -child nodes | |
| 77 | * | must | 7.5.3 | 0..n | -TODO | |
| 78 | * | presence | 7.5.5 | 0..1 | -boolean | |
| 79 | * | reference | 7.19.4 | 0..1 | -string | |
| 80 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 81 | * | typedef | 7.3 | 0..n | -child nodes | |
| 82 | * | uses | 7.12 | 0..n | -child nodes | |
| 83 | * | when | 7.19.5 | 0..1 | -TODO | |
| 84 | * +--------------+---------+-------------+------------------+ |
| 85 | */ |
| 86 | |
| 87 | /** |
| 88 | * Data model node to maintain information defined in YANG container. |
| 89 | */ |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 90 | public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Name of the container. |
| 94 | */ |
| 95 | private String name; |
| 96 | |
| 97 | /** |
| 98 | * If container maintains config data. |
| 99 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 100 | private Boolean isConfig; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Description of container. |
| 104 | */ |
| 105 | private String description; |
| 106 | |
| 107 | /** |
| 108 | * List of leaves contained. |
| 109 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 110 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * List of leaf-lists contained. |
| 114 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 115 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * If it is a presence container, then the textual documentation of presence |
| 119 | * usage. |
| 120 | */ |
| 121 | private String presence; |
| 122 | |
| 123 | /** |
| 124 | * Reference of the module. |
| 125 | */ |
| 126 | private String reference; |
| 127 | |
| 128 | /** |
| 129 | * Status of the node. |
| 130 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 131 | private YangStatusType status = YangStatusType.CURRENT; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 132 | |
| 133 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 134 | * Create a container node. |
| 135 | */ |
| 136 | public YangContainer() { |
| 137 | super(YangNodeType.CONTAINER_NODE); |
| 138 | } |
| 139 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 140 | /** |
| 141 | * Get the YANG name of container. |
| 142 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 143 | * @return the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 144 | */ |
| 145 | @Override |
| 146 | public String getName() { |
| 147 | return name; |
| 148 | } |
| 149 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 150 | /** |
| 151 | * Set the YANG name of container. |
| 152 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 153 | * @param name the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 154 | */ |
| 155 | @Override |
| 156 | public void setName(String name) { |
| 157 | this.name = name; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Get the config flag. |
| 162 | * |
| 163 | * @return the isConfig |
| 164 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 165 | public Boolean isConfig() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 166 | return isConfig; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Set the config flag. |
| 171 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 172 | * @param isCfg the config flag |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 173 | */ |
| 174 | public void setConfig(boolean isCfg) { |
| 175 | isConfig = isCfg; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Get the description. |
| 180 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 181 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 182 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 183 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 184 | public String getDescription() { |
| 185 | return description; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Set the description. |
| 190 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 191 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 192 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 193 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 194 | public void setDescription(String description) { |
| 195 | this.description = description; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Get the list of leaves. |
| 200 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 201 | * @return the list of leaves |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 202 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 203 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 204 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 205 | return listOfLeaf; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Set the list of leaves. |
| 210 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 211 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 212 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 213 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 214 | listOfLeaf = leafsList; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Add a leaf. |
| 219 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 220 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 221 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 222 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 223 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 224 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 225 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | getListOfLeaf().add(leaf); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Get the list of leaf-list. |
| 233 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 234 | * @return the list of leaf-list |
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 List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 238 | return listOfLeafList; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Set the list of leaf-list. |
| 243 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 244 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 245 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 246 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 247 | this.listOfLeafList = listOfLeafList; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Add a leaf-list. |
| 252 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 253 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 254 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 255 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 256 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 257 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 258 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | getListOfLeafList().add(leafList); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Get the presence string if present. |
| 266 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 267 | * @return the presence |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 268 | */ |
| 269 | public String getPresence() { |
| 270 | return presence; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Set the presence string. |
| 275 | * |
| 276 | * @param presence the presence flag |
| 277 | */ |
| 278 | public void setPresence(String presence) { |
| 279 | this.presence = presence; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Get the textual reference. |
| 284 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 285 | * @return the reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 286 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 287 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 288 | public String getReference() { |
| 289 | return reference; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Set the textual reference. |
| 294 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 295 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 296 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 297 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 298 | public void setReference(String reference) { |
| 299 | this.reference = reference; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Get the status. |
| 304 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 305 | * @return the status |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 306 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 307 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 308 | public YangStatusType getStatus() { |
| 309 | return status; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Set the status. |
| 314 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 315 | * @param status the status to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 316 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 317 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 318 | public void setStatus(YangStatusType status) { |
| 319 | this.status = status; |
| 320 | } |
| 321 | |
| 322 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 323 | * Returns the type of the data. |
| 324 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 325 | * @return returns CONTAINER_DATA |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 326 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 327 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 328 | public YangConstructType getYangConstructType() { |
| 329 | return YangConstructType.CONTAINER_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Validate the data on entering the corresponding parse tree node. |
| 334 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 335 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 336 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 337 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 338 | public void validateDataOnEntry() throws DataModelException { |
| 339 | // TODO auto-generated method stub, to be implemented by parser |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Validate the data on exiting the corresponding parse tree node. |
| 344 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 345 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 346 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 347 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 348 | public void validateDataOnExit() throws DataModelException { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 349 | List<YangLeaf> leaves = getListOfLeaf(); |
| 350 | List<YangLeafList> leafLists = getListOfLeafList(); |
| 351 | |
| 352 | setDefaultConfigValueToChild(leaves, leafLists); |
| 353 | validateConfig(leaves, leafLists); |
| 354 | } |
| 355 | |
| 356 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 357 | * Sets the config's value to all leaf if leaf's config statement is not |
| 358 | * specified. |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 359 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 360 | * @param leaves list of leaf attributes of container |
| 361 | * @param leafLists list of leaf-list attributes of container |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 362 | */ |
| 363 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
| 364 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 365 | /* |
| 366 | * If "config" is not specified, the default is the same as the parent |
| 367 | * schema node's "config" value. |
| 368 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 369 | if (leaves != null) { |
| 370 | for (YangLeaf leaf : leaves) { |
| 371 | if (leaf.isConfig() == null) { |
| 372 | leaf.setConfig(isConfig); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 377 | /* |
| 378 | * If "config" is not specified, the default is the same as the parent |
| 379 | * schema node's "config" value. |
| 380 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 381 | if (leafLists != null) { |
| 382 | for (YangLeafList leafList : leafLists) { |
| 383 | if (leafList.isConfig() == null) { |
| 384 | leafList.setConfig(isConfig); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Validates config statement of container. |
| 392 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 393 | * @param leaves list of leaf attributes of container |
| 394 | * @param leafLists list of leaf-list attributes of container |
| 395 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 396 | */ |
| 397 | private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException { |
| 398 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 399 | /* |
| 400 | * If a node has "config" set to "false", no node underneath it can have |
| 401 | * "config" set to "true". |
| 402 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 403 | if (!isConfig && leaves != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 404 | for (YangLeaf leaf : leaves) { |
| 405 | if (leaf.isConfig()) { |
| 406 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 407 | "it can have \"config\" set to \"true\"."); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 412 | if (!isConfig && leafLists != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 413 | for (YangLeafList leafList : leafLists) { |
| 414 | if (leafList.isConfig()) { |
| 415 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 416 | "it can have \"config\" set to \"true\"."); |
| 417 | } |
| 418 | } |
| 419 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 420 | } |
| 421 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 422 | @Override |
| 423 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 424 | // Asks helper to detect colliding child. |
| 425 | detectCollidingChildUtil(identifierName, dataType, this); |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 430 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 431 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \"" |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 432 | + getName() + "\""); |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 433 | } |
| 434 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 435 | } |