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