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