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 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 21 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 23 | |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.LinkedList; |
| 26 | import java.util.List; |
| 27 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 29 | |
| 30 | /* |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 31 | * The "list" statement is used to define an interior data node in the |
| 32 | * schema tree. A list node may exist in multiple instances in the data |
| 33 | * tree. Each such instance is known as a list entry. The "list" |
| 34 | * statement takes one argument, which is an identifier, followed by a |
| 35 | * block of sub-statements that holds detailed list information. |
| 36 | * |
| 37 | * A list entry is uniquely identified by the values of the list's keys, |
| 38 | * if defined. |
| 39 | * |
| 40 | * The list's sub-statements |
| 41 | * |
| 42 | * +--------------+---------+-------------+------------------+ |
| 43 | * | substatement | section | cardinality |data model mapping| |
| 44 | * +--------------+---------+-------------+------------------+ |
| 45 | * | anyxml | 7.10 | 0..n |-not supported | |
| 46 | * | choice | 7.9 | 0..n |-child nodes | |
| 47 | * | config | 7.19.1 | 0..1 |-boolean | |
| 48 | * | container | 7.5 | 0..n |-child nodes | |
| 49 | * | description | 7.19.3 | 0..1 |-string | |
| 50 | * | grouping | 7.11 | 0..n |-child nodes | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 51 | * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 52 | * | key | 7.8.2 | 0..1 |-String list | |
| 53 | * | leaf | 7.6 | 0..n |-YangLeaf | |
| 54 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
| 55 | * | list | 7.8 | 0..n |-child nodes | |
| 56 | * | max-elements | 7.7.4 | 0..1 |-int | |
| 57 | * | min-elements | 7.7.3 | 0..1 |-int | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 58 | * | must | 7.5.3 | 0..n |-YangMust | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 59 | * | ordered-by | 7.7.5 | 0..1 |-TODO | |
| 60 | * | reference | 7.19.4 | 0..1 |-string | |
| 61 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 62 | * | typedef | 7.3 | 0..n |-child nodes | |
| 63 | * | unique | 7.8.3 | 0..n |-TODO | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 64 | * | uses | 7.12 | 0..n |-child nodes | |
| 65 | * | when | 7.19.5 | 0..1 |-YangWhen | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 66 | * +--------------+---------+-------------+------------------+ |
| 67 | */ |
| 68 | |
| 69 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 70 | * Represents list data represented in YANG. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 71 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 72 | public class YangList |
| 73 | extends YangNode |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 74 | implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, |
| 75 | YangAugmentableNode, YangMustHolder, YangIfFeatureHolder, YangDataNode { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 76 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 77 | private static final long serialVersionUID = 806201609L; |
| 78 | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 79 | /** |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 80 | * Name of the YANG list. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 81 | */ |
| 82 | private String name; |
| 83 | |
| 84 | /** |
| 85 | * If list maintains config data. |
| 86 | */ |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 87 | private Boolean isConfig; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Description of list. |
| 91 | */ |
| 92 | private String description; |
| 93 | |
| 94 | /** |
| 95 | * Reference RFC 6020. |
| 96 | * |
| 97 | * The "key" statement, which MUST be present if the list represents |
| 98 | * configuration, and MAY be present otherwise, takes as an argument a |
| 99 | * string that specifies a space-separated list of leaf identifiers of this |
| 100 | * list. A leaf identifier MUST NOT appear more than once in the key. Each |
| 101 | * such leaf identifier MUST refer to a child leaf of the list. The leafs |
| 102 | * can be defined directly in sub-statements to the list, or in groupings |
| 103 | * used in the list. |
| 104 | * |
| 105 | * The combined values of all the leafs specified in the key are used to |
| 106 | * uniquely identify a list entry. All key leafs MUST be given values when a |
| 107 | * list entry is created. Thus, any default values in the key leafs or their |
| 108 | * types are ignored. It also implies that any mandatory statement in the |
| 109 | * key leafs are ignored. |
| 110 | * |
| 111 | * A leaf that is part of the key can be of any built-in or derived type, |
| 112 | * except it MUST NOT be the built-in type "empty". |
| 113 | * |
| 114 | * All key leafs in a list MUST have the same value for their "config" as |
| 115 | * the list itself. |
| 116 | * |
| 117 | * List of key leaf names. |
| 118 | */ |
| 119 | private List<String> keyList; |
| 120 | |
| 121 | /** |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 122 | * Reference RFC 6020. |
| 123 | * |
| 124 | * The "unique" statement is used to put constraints on valid list |
| 125 | * entries. It takes as an argument a string that contains a space- |
| 126 | * separated list of schema node identifiers, which MUST be given in the |
| 127 | * descendant form. Each such schema node identifier MUST refer to a leaf. |
| 128 | * |
| 129 | * If one of the referenced leafs represents configuration data, then |
| 130 | * all of the referenced leafs MUST represent configuration data. |
| 131 | * |
| 132 | * The "unique" constraint specifies that the combined values of all the |
| 133 | * leaf instances specified in the argument string, including leafs with |
| 134 | * default values, MUST be unique within all list entry instances in |
| 135 | * which all referenced leafs exist. |
| 136 | * |
| 137 | * List of unique leaf/leaf-list names |
| 138 | */ |
| 139 | private List<String> uniqueList; |
| 140 | |
| 141 | /** |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 142 | * List of leaves. |
| 143 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 144 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * List of leaf-lists. |
| 148 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 149 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 150 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 151 | private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>(); |
| 152 | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 153 | /** |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 154 | * Reference RFC 6020. |
| 155 | * |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 156 | * The "max-elements" statement, which is optional, takes as an argument a |
| 157 | * positive integer or the string "unbounded", which puts a constraint on |
| 158 | * valid list entries. A valid leaf-list or list always has at most |
| 159 | * max-elements entries. |
| 160 | * |
| 161 | * If no "max-elements" statement is present, it defaults to "unbounded". |
| 162 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 163 | private YangMaxElement maxElements; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 164 | |
| 165 | /** |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 166 | * Reference RFC 6020. |
| 167 | * |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 168 | * The "min-elements" statement, which is optional, takes as an argument a |
| 169 | * non-negative integer that puts a constraint on valid list entries. A |
| 170 | * valid leaf-list or list MUST have at least min-elements entries. |
| 171 | * |
| 172 | * If no "min-elements" statement is present, it defaults to zero. |
| 173 | * |
| 174 | * The behavior of the constraint depends on the type of the leaf-list's or |
| 175 | * list's closest ancestor node in the schema tree that is not a non- |
| 176 | * presence container: |
| 177 | * |
| 178 | * o If this ancestor is a case node, the constraint is enforced if any |
| 179 | * other node from the case exists. |
| 180 | * |
| 181 | * o Otherwise, it is enforced if the ancestor node exists. |
| 182 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 183 | private YangMinElement minElements; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * reference. |
| 187 | */ |
| 188 | private String reference; |
| 189 | |
| 190 | /** |
| 191 | * Status of the node. |
| 192 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 193 | private YangStatusType status = YangStatusType.CURRENT; |
| 194 | |
| 195 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 196 | * List of must statement constraints. |
| 197 | */ |
| 198 | private List<YangMust> mustConstraintList; |
| 199 | |
| 200 | /** |
| 201 | * When data of the node. |
| 202 | */ |
| 203 | private YangWhen when; |
| 204 | |
| 205 | /** |
| 206 | * List of if-feature. |
| 207 | */ |
| 208 | private List<YangIfFeature> ifFeatureList; |
| 209 | |
| 210 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 211 | * Creates a YANG list object. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 212 | */ |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 213 | public YangList() { |
| 214 | super(YangNodeType.LIST_NODE); |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 215 | } |
| 216 | |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 217 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 218 | * Returns the when. |
| 219 | * |
| 220 | * @return the when |
| 221 | */ |
| 222 | public YangWhen getWhen() { |
| 223 | return when; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Sets the when. |
| 228 | * |
| 229 | * @param when the when to set |
| 230 | */ |
| 231 | public void setWhen(YangWhen when) { |
| 232 | this.when = when; |
| 233 | } |
| 234 | |
| 235 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 236 | * Returns the YANG list name. |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 237 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 238 | * @return YANG list name |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 239 | */ |
| 240 | @Override |
| 241 | public String getName() { |
| 242 | return name; |
| 243 | } |
| 244 | |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 245 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 246 | * Sets the YANG list name. |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 247 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 248 | * @param name YANG list name |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 249 | */ |
| 250 | @Override |
| 251 | public void setName(String name) { |
| 252 | this.name = name; |
| 253 | } |
| 254 | |
| 255 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 256 | * Returns the config flag. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 257 | * |
| 258 | * @return the isConfig |
| 259 | */ |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 260 | public Boolean isConfig() { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 261 | return isConfig; |
| 262 | } |
| 263 | |
| 264 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 265 | * Sets the config flag. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 266 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 267 | * @param isCfg the config flag |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 268 | */ |
| 269 | public void setConfig(boolean isCfg) { |
| 270 | isConfig = isCfg; |
| 271 | } |
| 272 | |
| 273 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 274 | * Returns the description. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 275 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 276 | * @return the description |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 277 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 278 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 279 | public String getDescription() { |
| 280 | return description; |
| 281 | } |
| 282 | |
| 283 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 284 | * Sets the description. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 285 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 286 | * @param description set the description |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 287 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 288 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 289 | public void setDescription(String description) { |
| 290 | this.description = description; |
| 291 | } |
| 292 | |
| 293 | /** |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 294 | * Returns the list of unique field names. |
| 295 | * |
| 296 | * @return the list of unique field names |
| 297 | */ |
| 298 | public List<String> getUniqueList() { |
| 299 | return uniqueList; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Sets the list of unique field names. |
| 304 | * |
| 305 | * @param uniqueList the list of unique field names |
| 306 | */ |
| 307 | private void setUniqueList(List<String> uniqueList) { |
| 308 | this.uniqueList = uniqueList; |
| 309 | } |
| 310 | |
| 311 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 312 | * Returns the list of key field names. |
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 list of key field names |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 315 | */ |
| 316 | public List<String> getKeyList() { |
| 317 | return keyList; |
| 318 | } |
| 319 | |
| 320 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 321 | * Sets the list of key field names. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 322 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 323 | * @param keyList the list of key field names |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 324 | */ |
| 325 | private void setKeyList(List<String> keyList) { |
| 326 | this.keyList = keyList; |
| 327 | } |
| 328 | |
| 329 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 330 | * Adds a key field name. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 331 | * |
| 332 | * @param key key field name. |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 333 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 334 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 335 | public void addKey(String key) |
| 336 | throws DataModelException { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 337 | if (getKeyList() == null) { |
| 338 | setKeyList(new LinkedList<String>()); |
| 339 | } |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 340 | |
| 341 | if (getKeyList().contains(key)) { |
| 342 | throw new DataModelException("A leaf identifier must not appear more than once in the\n" + |
| 343 | " key"); |
| 344 | } |
| 345 | |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 346 | getKeyList().add(key); |
| 347 | } |
| 348 | |
| 349 | /** |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 350 | * Adds a unique field name. |
| 351 | * |
| 352 | * @param unique unique field name. |
| 353 | * @throws DataModelException a violation of data model rules |
| 354 | */ |
| 355 | public void addUnique(String unique) |
| 356 | throws DataModelException { |
| 357 | if (getUniqueList() == null) { |
| 358 | setUniqueList(new LinkedList<>()); |
| 359 | } |
| 360 | if (getUniqueList().contains(unique)) { |
| 361 | throw new DataModelException("A leaf identifier must not appear more than once in the\n" + |
| 362 | " unique"); |
| 363 | } |
| 364 | getUniqueList().add(unique); |
| 365 | } |
| 366 | |
| 367 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 368 | * Returns the list of leaves. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 369 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 370 | * @return the list of leaves |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 371 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 372 | @Override |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 373 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 374 | return listOfLeaf; |
| 375 | } |
| 376 | |
| 377 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 378 | * Sets the list of leaves. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 379 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 380 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 381 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 382 | @Override |
| 383 | public void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 384 | listOfLeaf = leafsList; |
| 385 | } |
| 386 | |
| 387 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 388 | * Adds a leaf. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 389 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 390 | * @param leaf the leaf to be added |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 391 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 392 | @Override |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 393 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 394 | if (getListOfLeaf() == null) { |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 395 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | getListOfLeaf().add(leaf); |
| 399 | } |
| 400 | |
| 401 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 402 | * Returns the list of leaf-list. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 403 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 404 | * @return the list of leaf-list |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 405 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 406 | @Override |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 407 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 408 | return listOfLeafList; |
| 409 | } |
| 410 | |
| 411 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 412 | * Sets the list of leaf-list. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 413 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 414 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 415 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 416 | @Override |
| 417 | public void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 418 | this.listOfLeafList = listOfLeafList; |
| 419 | } |
| 420 | |
| 421 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 422 | * Adds a leaf-list. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 423 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 424 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 425 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 426 | @Override |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 427 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 428 | if (getListOfLeafList() == null) { |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 429 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | getListOfLeafList().add(leafList); |
| 433 | } |
| 434 | |
| 435 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 436 | * Returns the max elements. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 437 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 438 | * @return the max elements |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 439 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 440 | public YangMaxElement getMaxElements() { |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 441 | return maxElements; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 445 | * Sets the max elements. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 446 | * |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 447 | * @param max the max elements |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 448 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 449 | public void setMaxElements(YangMaxElement max) { |
| 450 | this.maxElements = max; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 454 | * Returns the minimum elements. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 455 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 456 | * @return the minimum elements |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 457 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 458 | public YangMinElement getMinElements() { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 459 | return minElements; |
| 460 | } |
| 461 | |
| 462 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 463 | * Sets the minimum elements. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 464 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 465 | * @param minElements the minimum elements |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 466 | */ |
rama-huawei | 6c728a9 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 467 | public void setMinElements(YangMinElement minElements) { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 468 | this.minElements = minElements; |
| 469 | } |
| 470 | |
| 471 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 472 | * Returns the textual reference. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 473 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 474 | * @return the reference |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 475 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 476 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 477 | public String getReference() { |
| 478 | return reference; |
| 479 | } |
| 480 | |
| 481 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 482 | * Sets the textual reference. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 483 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 484 | * @param reference the reference to set |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 485 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 486 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 487 | public void setReference(String reference) { |
| 488 | this.reference = reference; |
| 489 | } |
| 490 | |
| 491 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 492 | * Returns the status. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 493 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 494 | * @return the status |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 495 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 496 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 497 | public YangStatusType getStatus() { |
| 498 | return status; |
| 499 | } |
| 500 | |
| 501 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 502 | * Sets the status. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 503 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 504 | * @param status the status to set |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 505 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 506 | @Override |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 507 | public void setStatus(YangStatusType status) { |
| 508 | this.status = status; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Returns the type of the parsed data. |
| 513 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 514 | * @return returns LIST_DATA |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 515 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 516 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 517 | public YangConstructType getYangConstructType() { |
| 518 | return YangConstructType.LIST_DATA; |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 522 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 523 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 524 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 525 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 526 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 527 | public void validateDataOnEntry() |
| 528 | throws DataModelException { |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 529 | // TODO auto-generated method stub, to be implemented by parser |
| 530 | } |
| 531 | |
| 532 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 533 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 534 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 535 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 536 | */ |
Bharat saraswal | 870c56f | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 537 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 538 | public void validateDataOnExit() |
| 539 | throws DataModelException { |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 540 | List<String> keys = getKeyList(); |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 541 | List<YangLeaf> leaves = getListOfLeaf(); |
| 542 | List<YangLeafList> leafLists = getListOfLeafList(); |
| 543 | |
| 544 | setDefaultConfigValueToChild(leaves, leafLists); |
| 545 | validateConfig(leaves, leafLists); |
| 546 | |
| 547 | /* A list must have atleast one key leaf if config is true */ |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 548 | if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList() |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 549 | && !isListPresentInGrouping()) { |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 550 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); |
| 551 | } else if (keys != null) { |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 552 | validateKey(leaves, keys); |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | /** |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 557 | * Sets the config's value to all leaf if leaf's config statement is not |
| 558 | * specified. |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 559 | * |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 560 | * @param leaves list of leaf attributes of YANG list |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 561 | * @param leafLists list of leaf-list attributes of YANG list |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 562 | */ |
| 563 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
| 564 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 565 | /* |
| 566 | * If "config" is not specified, the default is the same as the parent |
| 567 | * schema node's "config" value. |
| 568 | */ |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 569 | if (leaves != null) { |
| 570 | for (YangLeaf leaf : leaves) { |
| 571 | if (leaf.isConfig() == null) { |
| 572 | leaf.setConfig(isConfig); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 577 | /* |
| 578 | * If "config" is not specified, the default is the same as the parent |
| 579 | * schema node's "config" value. |
| 580 | */ |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 581 | if (leafLists != null) { |
| 582 | for (YangLeafList leafList : leafLists) { |
| 583 | if (leafList.isConfig() == null) { |
| 584 | leafList.setConfig(isConfig); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Validates config statement of YANG list. |
| 592 | * |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 593 | * @param leaves list of leaf attributes of YANG list |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 594 | * @param leafLists list of leaf-list attributes of YANG list |
| 595 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 596 | */ |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 597 | private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) |
| 598 | throws DataModelException { |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 599 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 600 | /* |
| 601 | * If a node has "config" set to "false", no node underneath it can have |
| 602 | * "config" set to "true". |
| 603 | */ |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 604 | if (!isConfig && leaves != null) { |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 605 | for (YangLeaf leaf : leaves) { |
| 606 | if (leaf.isConfig()) { |
| 607 | throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " + |
| 608 | "it can have \"config\" set to \"true\"."); |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 613 | if (!isConfig && leafLists != null) { |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 614 | for (YangLeafList leafList : leafLists) { |
| 615 | if (leafList.isConfig()) { |
| 616 | throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " + |
| 617 | "it can have \"config\" set to \"true\"."); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Validates key statement of list. |
| 625 | * |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 626 | * @param leaves list of leaf attributes of list |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 627 | * @param leafLists list of leaf-list attributes of list |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 628 | * @param keys list of key attributes of list |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 629 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 630 | */ |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame] | 631 | private void validateKey(List<YangLeaf> leaves, List<String> keys) |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 632 | throws DataModelException { |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 633 | boolean leafFound = false; |
| 634 | List<YangLeaf> keyLeaves = new LinkedList<>(); |
| 635 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 636 | /* |
| 637 | * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf |
| 638 | * that is part of the key must not be the built-in type "empty". |
| 639 | */ |
| 640 | for (String key : keys) { |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 641 | if (leaves != null && !leaves.isEmpty()) { |
| 642 | for (YangLeaf leaf : leaves) { |
| 643 | if (key.equals(leaf.getName())) { |
| 644 | if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) { |
| 645 | throw new DataModelException(" A leaf that is part of the key must not be the built-in " + |
| 646 | "type \"empty\"."); |
| 647 | } |
| 648 | leafFound = true; |
| 649 | keyLeaves.add(leaf); |
| 650 | break; |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 651 | } |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 652 | } |
| 653 | } |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 654 | |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 655 | if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) { |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 656 | throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 657 | } |
| 658 | leafFound = false; |
| 659 | } |
| 660 | |
Vinod Kumar S | 71cba68 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 661 | /* |
| 662 | * All key leafs in a list MUST have the same value for their "config" |
| 663 | * as the list itself. |
| 664 | */ |
Vidyashree Rama | f4c617c | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 665 | for (YangLeaf keyLeaf : keyLeaves) { |
| 666 | if (isConfig != keyLeaf.isConfig()) { |
| 667 | throw new DataModelException("All key leafs in a list must have the same value for their" + |
| 668 | " \"config\" as the list itself."); |
| 669 | } |
| 670 | } |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 671 | } |
| 672 | |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 673 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 674 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 675 | throws DataModelException { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 676 | // Asks helper to detect colliding child. |
| 677 | detectCollidingChildUtil(identifierName, dataType, this); |
| 678 | } |
| 679 | |
| 680 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 681 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 682 | throws DataModelException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 683 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 684 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" + |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 685 | getName() + "\""); |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 686 | } |
| 687 | } |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 688 | |
| 689 | private boolean isUsesPresentInList() { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 690 | YangNode node = getChild(); |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 691 | while (node != null) { |
| 692 | if (node instanceof YangUses) { |
| 693 | return true; |
| 694 | } |
| 695 | node = node.getNextSibling(); |
| 696 | } |
| 697 | return false; |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 698 | // TODO When grouping linking is done this method has to be modified. |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 699 | } |
| 700 | |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 701 | private boolean isListPresentInGrouping() { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 702 | YangNode node = getParent(); |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 703 | while (node != null) { |
| 704 | if (node instanceof YangGrouping) { |
| 705 | return true; |
| 706 | } |
| 707 | node = node.getParent(); |
| 708 | } |
| 709 | return false; |
| 710 | // TODO When grouping linking is done this method has to be modified. |
| 711 | } |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 712 | |
| 713 | @Override |
| 714 | public List<YangIfFeature> getIfFeatureList() { |
| 715 | return ifFeatureList; |
| 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 720 | if (getIfFeatureList() == null) { |
| 721 | setIfFeatureList(new LinkedList<>()); |
| 722 | } |
| 723 | getIfFeatureList().add(ifFeature); |
| 724 | } |
| 725 | |
| 726 | @Override |
| 727 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 728 | this.ifFeatureList = ifFeatureList; |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public List<YangMust> getListOfMust() { |
| 733 | return mustConstraintList; |
| 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public void setListOfMust(List<YangMust> mustConstraintList) { |
| 738 | this.mustConstraintList = mustConstraintList; |
| 739 | } |
| 740 | |
| 741 | @Override |
| 742 | public void addMust(YangMust must) { |
| 743 | if (getListOfMust() == null) { |
| 744 | setListOfMust(new LinkedList<>()); |
| 745 | } |
| 746 | getListOfMust().add(must); |
| 747 | } |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 748 | |
| 749 | @Override |
| 750 | public void addAugmentation(YangAugmentedInfo augmentInfo) { |
| 751 | yangAugmentedInfo.add(augmentInfo); |
| 752 | } |
| 753 | |
| 754 | @Override |
| 755 | public void removeAugmentation(YangAugmentedInfo augmentInfo) { |
| 756 | yangAugmentedInfo.remove(augmentInfo); |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public List<YangAugmentedInfo> getAugmentedInfoList() { |
| 761 | return yangAugmentedInfo; |
| 762 | } |
Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 763 | } |