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