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