Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 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 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 88 | * Represents data model node to maintain information defined in YANG container. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 89 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 90 | public class YangContainer extends YangNode |
| 91 | implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Name of the container. |
| 95 | */ |
| 96 | private String name; |
| 97 | |
| 98 | /** |
| 99 | * If container maintains config data. |
| 100 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 101 | private Boolean isConfig; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Description of container. |
| 105 | */ |
| 106 | private String description; |
| 107 | |
| 108 | /** |
| 109 | * List of leaves contained. |
| 110 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 111 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * List of leaf-lists contained. |
| 115 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 116 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * If it is a presence container, then the textual documentation of presence |
| 120 | * usage. |
| 121 | */ |
| 122 | private String presence; |
| 123 | |
| 124 | /** |
| 125 | * Reference of the module. |
| 126 | */ |
| 127 | private String reference; |
| 128 | |
| 129 | /** |
| 130 | * Status of the node. |
| 131 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 132 | private YangStatusType status = YangStatusType.CURRENT; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 133 | |
| 134 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 135 | * Create a container node. |
| 136 | */ |
| 137 | public YangContainer() { |
| 138 | super(YangNodeType.CONTAINER_NODE); |
| 139 | } |
| 140 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 141 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 142 | * Returns the YANG name of container. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 143 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 144 | * @return the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 145 | */ |
| 146 | @Override |
| 147 | public String getName() { |
| 148 | return name; |
| 149 | } |
| 150 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 151 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 152 | * Sets the YANG name of container. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 153 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 154 | * @param name the name of container as defined in YANG file |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 155 | */ |
| 156 | @Override |
| 157 | public void setName(String name) { |
| 158 | this.name = name; |
| 159 | } |
| 160 | |
| 161 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 162 | * Returns the config flag. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 163 | * |
| 164 | * @return the isConfig |
| 165 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 166 | public Boolean isConfig() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 167 | return isConfig; |
| 168 | } |
| 169 | |
| 170 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 171 | * Sets the config flag. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 172 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 173 | * @param isCfg the config flag |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 174 | */ |
| 175 | public void setConfig(boolean isCfg) { |
| 176 | isConfig = isCfg; |
| 177 | } |
| 178 | |
| 179 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 180 | * Returns the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 181 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 182 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 183 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 184 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 185 | public String getDescription() { |
| 186 | return description; |
| 187 | } |
| 188 | |
| 189 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 190 | * Sets the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 191 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 192 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 193 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 194 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 195 | public void setDescription(String description) { |
| 196 | this.description = description; |
| 197 | } |
| 198 | |
| 199 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 200 | * Returns the list of leaves. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 201 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 202 | * @return the list of leaves |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 203 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 204 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 205 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 206 | return listOfLeaf; |
| 207 | } |
| 208 | |
| 209 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 210 | * Sets the list of leaves. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 211 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 212 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 213 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 214 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 215 | listOfLeaf = leafsList; |
| 216 | } |
| 217 | |
| 218 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 219 | * Adds a leaf. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 220 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 221 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 222 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 223 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 224 | public void addLeaf(YangLeaf leaf) { |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 225 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 226 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 227 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | getListOfLeaf().add(leaf); |
| 231 | } |
| 232 | |
| 233 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 234 | * Returns the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 235 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 236 | * @return the list of leaf-list |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 237 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 238 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 239 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 240 | return listOfLeafList; |
| 241 | } |
| 242 | |
| 243 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 244 | * Sets the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 245 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 246 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 247 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 248 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 249 | this.listOfLeafList = listOfLeafList; |
| 250 | } |
| 251 | |
| 252 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 253 | * Adds a leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 254 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 255 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 256 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 257 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 258 | public void addLeafList(YangLeafList leafList) { |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 259 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 260 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 261 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | getListOfLeafList().add(leafList); |
| 265 | } |
| 266 | |
| 267 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 268 | * Returns the presence string if present. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 269 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 270 | * @return the presence |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 271 | */ |
| 272 | public String getPresence() { |
| 273 | return presence; |
| 274 | } |
| 275 | |
| 276 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 277 | * Sets the presence string. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 278 | * |
| 279 | * @param presence the presence flag |
| 280 | */ |
| 281 | public void setPresence(String presence) { |
| 282 | this.presence = presence; |
| 283 | } |
| 284 | |
| 285 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 286 | * Returns the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 287 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 288 | * @return the reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 289 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 290 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 291 | public String getReference() { |
| 292 | return reference; |
| 293 | } |
| 294 | |
| 295 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 296 | * Sets the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 297 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 298 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 299 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 300 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 301 | public void setReference(String reference) { |
| 302 | this.reference = reference; |
| 303 | } |
| 304 | |
| 305 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 306 | * Returns the status. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 307 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 308 | * @return the status |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 309 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 310 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 311 | public YangStatusType getStatus() { |
| 312 | return status; |
| 313 | } |
| 314 | |
| 315 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 316 | * Sets the status. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 317 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 318 | * @param status the status to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 319 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 320 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 321 | public void setStatus(YangStatusType status) { |
| 322 | this.status = status; |
| 323 | } |
| 324 | |
| 325 | /** |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 326 | * Returns the type of the data. |
| 327 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 328 | * @return returns CONTAINER_DATA |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 329 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 330 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 331 | public YangConstructType getYangConstructType() { |
| 332 | return YangConstructType.CONTAINER_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 336 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 337 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 338 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 339 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 340 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 341 | public void validateDataOnEntry() throws DataModelException { |
| 342 | // TODO auto-generated method stub, to be implemented by parser |
| 343 | } |
| 344 | |
| 345 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 346 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 347 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 348 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 349 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 350 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 351 | public void validateDataOnExit() throws DataModelException { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 352 | List<YangLeaf> leaves = getListOfLeaf(); |
| 353 | List<YangLeafList> leafLists = getListOfLeafList(); |
| 354 | |
| 355 | setDefaultConfigValueToChild(leaves, leafLists); |
| 356 | validateConfig(leaves, leafLists); |
| 357 | } |
| 358 | |
| 359 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 360 | * Sets the config's value to all leaf if leaf's config statement is not |
| 361 | * specified. |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 362 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 363 | * @param leaves list of leaf attributes of container |
| 364 | * @param leafLists list of leaf-list attributes of container |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 365 | */ |
| 366 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
| 367 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 368 | /* |
| 369 | * If "config" is not specified, the default is the same as the parent |
| 370 | * schema node's "config" value. |
| 371 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 372 | if (leaves != null) { |
| 373 | for (YangLeaf leaf : leaves) { |
| 374 | if (leaf.isConfig() == null) { |
| 375 | leaf.setConfig(isConfig); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 380 | /* |
| 381 | * If "config" is not specified, the default is the same as the parent |
| 382 | * schema node's "config" value. |
| 383 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 384 | if (leafLists != null) { |
| 385 | for (YangLeafList leafList : leafLists) { |
| 386 | if (leafList.isConfig() == null) { |
| 387 | leafList.setConfig(isConfig); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Validates config statement of container. |
| 395 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 396 | * @param leaves list of leaf attributes of container |
| 397 | * @param leafLists list of leaf-list attributes of container |
| 398 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 399 | */ |
| 400 | private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException { |
| 401 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 402 | /* |
| 403 | * If a node has "config" set to "false", no node underneath it can have |
| 404 | * "config" set to "true". |
| 405 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 406 | if (!isConfig && leaves != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 407 | for (YangLeaf leaf : leaves) { |
| 408 | if (leaf.isConfig()) { |
| 409 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 410 | "it can have \"config\" set to \"true\"."); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 415 | if (!isConfig && leafLists != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 416 | for (YangLeafList leafList : leafLists) { |
| 417 | if (leafList.isConfig()) { |
| 418 | throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " + |
| 419 | "it can have \"config\" set to \"true\"."); |
| 420 | } |
| 421 | } |
| 422 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 423 | } |
| 424 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 425 | @Override |
| 426 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 427 | // Asks helper to detect colliding child. |
| 428 | detectCollidingChildUtil(identifierName, dataType, this); |
| 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 433 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 434 | 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] | 435 | + getName() + "\""); |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 436 | } |
| 437 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 438 | } |