Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 6a6ce4c | 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 | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 23 | import org.onosproject.yangutils.parser.Parsable; |
| 24 | import org.onosproject.yangutils.utils.YangConstructType; |
| 25 | |
| 26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
| 27 | |
| 28 | /* |
Vinod Kumar S | 6a6ce4c | 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 | |
| 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 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 68 | * Represents list data represented in YANG. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 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 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 169 | * Creates a YANG list object. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 170 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 171 | public YangList() { |
| 172 | super(YangNodeType.LIST_NODE); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 173 | } |
| 174 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 175 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 176 | * Returns the YANG list name. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 177 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 178 | * @return YANG list name |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 179 | */ |
| 180 | @Override |
| 181 | public String getName() { |
| 182 | return name; |
| 183 | } |
| 184 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 185 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 186 | * Sets the YANG list name. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 187 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 188 | * @param name YANG list name |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 189 | */ |
| 190 | @Override |
| 191 | public void setName(String name) { |
| 192 | this.name = name; |
| 193 | } |
| 194 | |
| 195 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 196 | * Returns the config flag. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 197 | * |
| 198 | * @return the isConfig |
| 199 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 200 | public Boolean isConfig() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 201 | return isConfig; |
| 202 | } |
| 203 | |
| 204 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 205 | * Sets the config flag. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 206 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 207 | * @param isCfg the config flag |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 208 | */ |
| 209 | public void setConfig(boolean isCfg) { |
| 210 | isConfig = isCfg; |
| 211 | } |
| 212 | |
| 213 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 214 | * Returns the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 215 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 216 | * @return the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 217 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 218 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 219 | public String getDescription() { |
| 220 | return description; |
| 221 | } |
| 222 | |
| 223 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 224 | * Sets the description. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 225 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 226 | * @param description set the description |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 227 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 228 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 229 | public void setDescription(String description) { |
| 230 | this.description = description; |
| 231 | } |
| 232 | |
| 233 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 234 | * Returns the list of key field names. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 235 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 236 | * @return the list of key field names |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 237 | */ |
| 238 | public List<String> getKeyList() { |
| 239 | return keyList; |
| 240 | } |
| 241 | |
| 242 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 243 | * Sets the list of key field names. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 244 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 245 | * @param keyList the list of key field names |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 246 | */ |
| 247 | private void setKeyList(List<String> keyList) { |
| 248 | this.keyList = keyList; |
| 249 | } |
| 250 | |
| 251 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 252 | * Adds a key field name. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 253 | * |
| 254 | * @param key key field name. |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 255 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 256 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 257 | public void addKey(String key) throws DataModelException { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 258 | if (getKeyList() == null) { |
| 259 | setKeyList(new LinkedList<String>()); |
| 260 | } |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 261 | |
| 262 | if (getKeyList().contains(key)) { |
| 263 | throw new DataModelException("A leaf identifier must not appear more than once in the\n" + |
| 264 | " key"); |
| 265 | } |
| 266 | |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 267 | getKeyList().add(key); |
| 268 | } |
| 269 | |
| 270 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 271 | * Returns the list of leaves. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 272 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 273 | * @return the list of leaves |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 274 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 275 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 276 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 277 | return listOfLeaf; |
| 278 | } |
| 279 | |
| 280 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 281 | * Sets the list of leaves. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 282 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 283 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 284 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 285 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 286 | listOfLeaf = leafsList; |
| 287 | } |
| 288 | |
| 289 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 290 | * Adds a leaf. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 291 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 292 | * @param leaf the leaf to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 293 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 294 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 295 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 296 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 297 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | getListOfLeaf().add(leaf); |
| 301 | } |
| 302 | |
| 303 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 304 | * Returns the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 305 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 306 | * @return the list of leaf-list |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 307 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 308 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 309 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 310 | return listOfLeafList; |
| 311 | } |
| 312 | |
| 313 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 314 | * Sets the list of leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 315 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 316 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 317 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 318 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 319 | this.listOfLeafList = listOfLeafList; |
| 320 | } |
| 321 | |
| 322 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 323 | * Adds a leaf-list. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 324 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 325 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 326 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 327 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 328 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 329 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 330 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | getListOfLeafList().add(leafList); |
| 334 | } |
| 335 | |
| 336 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 337 | * Returns the max elements. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 338 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 339 | * @return the max elements |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 340 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 341 | public int getMaxElements() { |
| 342 | return maxElements; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 346 | * Sets the max elements. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 347 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 348 | * @param max the max elements |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 349 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 350 | public void setMaxElements(int max) { |
| 351 | maxElements = max; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 355 | * Returns the minimum elements. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 356 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 357 | * @return the minimum elements |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 358 | */ |
| 359 | public int getMinElements() { |
| 360 | return minElements; |
| 361 | } |
| 362 | |
| 363 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 364 | * Sets the minimum elements. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 365 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 366 | * @param minElements the minimum elements |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 367 | */ |
| 368 | public void setMinElements(int minElements) { |
| 369 | this.minElements = minElements; |
| 370 | } |
| 371 | |
| 372 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 373 | * Returns the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 374 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 375 | * @return the reference |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 376 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 377 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 378 | public String getReference() { |
| 379 | return reference; |
| 380 | } |
| 381 | |
| 382 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 383 | * Sets the textual reference. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 384 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 385 | * @param reference the reference to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 386 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 387 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 388 | public void setReference(String reference) { |
| 389 | this.reference = reference; |
| 390 | } |
| 391 | |
| 392 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 393 | * Returns the status. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 394 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 395 | * @return the status |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 396 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 397 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 398 | public YangStatusType getStatus() { |
| 399 | return status; |
| 400 | } |
| 401 | |
| 402 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 403 | * Sets the status. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 404 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 405 | * @param status the status to set |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 406 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 407 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 408 | public void setStatus(YangStatusType status) { |
| 409 | this.status = status; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Returns the type of the parsed data. |
| 414 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 415 | * @return returns LIST_DATA |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 416 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 417 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 418 | public YangConstructType getYangConstructType() { |
| 419 | return YangConstructType.LIST_DATA; |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 423 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 424 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 425 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 426 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 427 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 428 | public void validateDataOnEntry() throws DataModelException { |
| 429 | // TODO auto-generated method stub, to be implemented by parser |
| 430 | } |
| 431 | |
| 432 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 433 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 434 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 435 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 436 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 437 | @Override |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 438 | public void validateDataOnExit() throws DataModelException { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 439 | List<String> keys = getKeyList(); |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 440 | List<YangLeaf> leaves = getListOfLeaf(); |
| 441 | List<YangLeafList> leafLists = getListOfLeafList(); |
| 442 | |
| 443 | setDefaultConfigValueToChild(leaves, leafLists); |
| 444 | validateConfig(leaves, leafLists); |
| 445 | |
| 446 | /* 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] | 447 | if (isConfig |
| 448 | && (keys == null || leaves == null && leafLists == null)) { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 449 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); |
| 450 | } else if (keys != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 451 | if (leaves != null) { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 452 | validateLeafKey(leaves, keys); |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | if (leafLists != null) { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 456 | validateLeafListKey(leafLists, keys); |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /** |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 462 | * Sets the config's value to all leaf if leaf's config statement is not |
| 463 | * specified. |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 464 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 465 | * @param leaves list of leaf attributes of YANG list |
| 466 | * @param leafLists list of leaf-list attributes of YANG list |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 467 | */ |
| 468 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
| 469 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 470 | /* |
| 471 | * If "config" is not specified, the default is the same as the parent |
| 472 | * schema node's "config" value. |
| 473 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 474 | if (leaves != null) { |
| 475 | for (YangLeaf leaf : leaves) { |
| 476 | if (leaf.isConfig() == null) { |
| 477 | leaf.setConfig(isConfig); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 482 | /* |
| 483 | * If "config" is not specified, the default is the same as the parent |
| 484 | * schema node's "config" value. |
| 485 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 486 | if (leafLists != null) { |
| 487 | for (YangLeafList leafList : leafLists) { |
| 488 | if (leafList.isConfig() == null) { |
| 489 | leafList.setConfig(isConfig); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Validates config statement of YANG list. |
| 497 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 498 | * @param leaves list of leaf attributes of YANG list |
| 499 | * @param leafLists list of leaf-list attributes of YANG list |
| 500 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 501 | */ |
| 502 | private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException { |
| 503 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 504 | /* |
| 505 | * If a node has "config" set to "false", no node underneath it can have |
| 506 | * "config" set to "true". |
| 507 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 508 | if (!isConfig && leaves != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 509 | for (YangLeaf leaf : leaves) { |
| 510 | if (leaf.isConfig()) { |
| 511 | throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " + |
| 512 | "it can have \"config\" set to \"true\"."); |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 517 | if (!isConfig && leafLists != null) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 518 | for (YangLeafList leafList : leafLists) { |
| 519 | if (leafList.isConfig()) { |
| 520 | throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " + |
| 521 | "it can have \"config\" set to \"true\"."); |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Validates key statement of list. |
| 529 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 530 | * @param leaves list of leaf attributes of list |
| 531 | * @param keys list of key attributes of list |
| 532 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 533 | */ |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 534 | private void validateLeafKey(List<YangLeaf> leaves, List<String> keys) throws DataModelException { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 535 | boolean leafFound = false; |
| 536 | List<YangLeaf> keyLeaves = new LinkedList<>(); |
| 537 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 538 | /* |
| 539 | * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf |
| 540 | * that is part of the key must not be the built-in type "empty". |
| 541 | */ |
| 542 | for (String key : keys) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 543 | for (YangLeaf leaf : leaves) { |
| 544 | if (key.equals(leaf.getLeafName())) { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 545 | if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 546 | throw new DataModelException(" A leaf that is part of the key must not be the built-in " + |
| 547 | "type \"empty\"."); |
| 548 | } |
| 549 | leafFound = true; |
| 550 | keyLeaves.add(leaf); |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | if (!leafFound) { |
| 555 | throw new DataModelException("Leaf identifier must refer to a child leaf of the list"); |
| 556 | } |
| 557 | leafFound = false; |
| 558 | } |
| 559 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 560 | /* |
| 561 | * All key leafs in a list MUST have the same value for their "config" |
| 562 | * as the list itself. |
| 563 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 564 | for (YangLeaf keyLeaf : keyLeaves) { |
| 565 | if (isConfig != keyLeaf.isConfig()) { |
| 566 | throw new DataModelException("All key leafs in a list must have the same value for their" + |
| 567 | " \"config\" as the list itself."); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Validates key statement of list. |
| 574 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 575 | * @param leafLists list of leaf-list attributes of list |
| 576 | * @param keys list of key attributes of list |
| 577 | * @throws DataModelException a violation of data model rules |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 578 | */ |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 579 | private void validateLeafListKey(List<YangLeafList> leafLists, List<String> keys) throws DataModelException { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 580 | boolean leafFound = false; |
| 581 | List<YangLeafList> keyLeafLists = new LinkedList<>(); |
| 582 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 583 | /* |
| 584 | * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf |
| 585 | * that is part of the key must not be the built-in type "empty". |
| 586 | */ |
| 587 | for (String key : keys) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 588 | for (YangLeafList leafList : leafLists) { |
| 589 | if (key.equals(leafList.getLeafName())) { |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 590 | if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) { |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 591 | throw new DataModelException(" A leaf-list that is part of the key must not be the built-in " + |
| 592 | "type \"empty\"."); |
| 593 | } |
| 594 | leafFound = true; |
| 595 | keyLeafLists.add(leafList); |
| 596 | break; |
| 597 | } |
| 598 | } |
| 599 | if (!leafFound) { |
| 600 | throw new DataModelException("Leaf-list identifier must refer to a child leaf of the list"); |
| 601 | } |
| 602 | leafFound = false; |
| 603 | } |
| 604 | |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 605 | /* |
| 606 | * All key leafs in a list MUST have the same value for their "config" |
| 607 | * as the list itself. |
| 608 | */ |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 609 | for (YangLeafList keyLeafList : keyLeafLists) { |
| 610 | if (isConfig() != keyLeafList.isConfig()) { |
| 611 | throw new DataModelException("All key leaf-lists in a list must have the same value for their" + |
| 612 | " \"config\" as the list itself."); |
| 613 | } |
| 614 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 615 | } |
| 616 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 617 | @Override |
| 618 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 619 | // Asks helper to detect colliding child. |
| 620 | detectCollidingChildUtil(identifierName, dataType, this); |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 625 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 626 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" + |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 627 | getName() + "\""); |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 628 | } |
| 629 | } |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 630 | } |