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