Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +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 | 2ff139c | 2016-02-16 01:37:16 +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 | package org.onosproject.yangutils.datamodel; |
| 17 | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 22 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 23 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 24 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 25 | |
| 26 | /*- |
| 27 | * Reference RFC 6020. |
| 28 | * |
| 29 | * The "choice" statement defines a set of alternatives, only one of |
| 30 | * which may exist at any one time. The argument is an identifier, |
| 31 | * followed by a block of sub-statements that holds detailed choice |
| 32 | * information. The identifier is used to identify the choice node in |
| 33 | * the schema tree. A choice node does not exist in the data tree. |
| 34 | * |
| 35 | * A choice consists of a number of branches, defined with the "case" |
| 36 | * sub-statement. Each branch contains a number of child nodes. The |
| 37 | * nodes from at most one of the choice's branches exist at the same |
| 38 | * time. |
| 39 | * |
| 40 | * The choice's sub-statements |
| 41 | * |
| 42 | * +--------------+---------+-------------+------------------+ |
| 43 | * | substatement | section | cardinality |data model mapping| |
| 44 | * +--------------+---------+-------------+------------------+ |
| 45 | * | anyxml | 7.10 | 0..n |-not supported | |
| 46 | * | case | 7.9.2 | 0..n |-YangChoice | |
| 47 | * | config | 7.19.1 | 0..1 |-boolean | |
| 48 | * | container | 7.5 | 0..n |-child case nodes | |
| 49 | * | default | 7.9.3 | 0..1 |-string | |
| 50 | * | description | 7.19.3 | 0..1 |-string | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 51 | * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 52 | * | leaf | 7.6 | 0..n |-child case nodes | |
| 53 | * | leaf-list | 7.7 | 0..n |-child case nodes | |
| 54 | * | list | 7.8 | 0..n |-child case nodes | |
| 55 | * | mandatory | 7.9.4 | 0..1 |-string | |
| 56 | * | reference | 7.19.4 | 0..1 |-string | |
| 57 | * | status | 7.19.2 | 0..1 |-string | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 58 | * | when | 7.19.5 | 0..1 |-YangWhen | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 59 | * +--------------+---------+-------------+------------------+ |
| 60 | */ |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 61 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 62 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 63 | * Represents data model node to maintain information defined in YANG choice. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 64 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 65 | public class YangChoice extends YangNode |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 66 | implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, YangWhenHolder, |
| 67 | YangIfFeatureHolder { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 68 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 69 | private static final long serialVersionUID = 806201604L; |
| 70 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 71 | /** |
| 72 | * Name of choice. |
| 73 | */ |
| 74 | private String name; |
| 75 | |
| 76 | /** |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 77 | * If the choice represents config data. |
| 78 | */ |
| 79 | private boolean isConfig; |
| 80 | |
| 81 | /** |
| 82 | * Reference RFC 6020. |
| 83 | * |
| 84 | * The "default" statement indicates if a case should be considered as the |
| 85 | * default if no child nodes from any of the choice's cases exist. The |
| 86 | * argument is the identifier of the "case" statement. If the "default" |
| 87 | * statement is missing, there is no default case. |
| 88 | * |
| 89 | * The "default" statement MUST NOT be present on choices where "mandatory" |
| 90 | * is true. |
| 91 | * |
| 92 | * The default case is only important when considering the default values of |
| 93 | * nodes under the cases. The default values for nodes under the default |
| 94 | * case are used if none of the nodes under any of the cases are present. |
| 95 | * |
| 96 | * There MUST NOT be any mandatory nodes directly under the default case. |
| 97 | * |
| 98 | * Default values for child nodes under a case are only used if one of the |
| 99 | * nodes under that case is present, or if that case is the default case. If |
| 100 | * none of the nodes under a case are present and the case is not the |
| 101 | * default case, the default values of the cases' child nodes are ignored. |
| 102 | * |
| 103 | * the default case to be used if no case members is present. |
| 104 | */ |
| 105 | private String defaultCase; |
| 106 | |
| 107 | /** |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 108 | * Description of choice. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 109 | */ |
| 110 | private String description; |
| 111 | |
| 112 | /** |
| 113 | * Reference RFC 6020. |
| 114 | * |
| 115 | * The "mandatory" statement, which is optional, takes as an argument the |
| 116 | * string "true" or "false", and puts a constraint on valid data. If |
| 117 | * "mandatory" is "true", at least one node from exactly one of the choice's |
| 118 | * case branches MUST exist. |
| 119 | * |
| 120 | * If not specified, the default is "false". |
| 121 | * |
| 122 | * The behavior of the constraint depends on the type of the choice's |
| 123 | * closest ancestor node in the schema tree which is not a non-presence |
| 124 | * container: |
| 125 | * |
| 126 | * o If this ancestor is a case node, the constraint is enforced if any |
| 127 | * other node from the case exists. |
| 128 | * |
| 129 | * o Otherwise, it is enforced if the ancestor node exists. |
| 130 | */ |
| 131 | private String mandatory; |
| 132 | |
| 133 | /** |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 134 | * Reference of the choice. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 135 | */ |
| 136 | private String reference; |
| 137 | |
| 138 | /** |
| 139 | * Status of the node. |
| 140 | */ |
| 141 | private YangStatusType status; |
| 142 | |
| 143 | /** |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 144 | * Default value in string, needs to be converted to the target object, |
| 145 | * based on the type. |
| 146 | */ |
| 147 | private String defaultValueInString; |
| 148 | |
| 149 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 150 | * When data of the node. |
| 151 | */ |
| 152 | private YangWhen when; |
| 153 | |
| 154 | /** |
| 155 | * List of if-feature. |
| 156 | */ |
| 157 | private List<YangIfFeature> ifFeatureList; |
| 158 | |
| 159 | /** |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | * Create a choice node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 161 | */ |
| 162 | public YangChoice() { |
| 163 | super(YangNodeType.CHOICE_NODE); |
| 164 | } |
| 165 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 166 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 167 | * Returns the when. |
| 168 | * |
| 169 | * @return the when |
| 170 | */ |
| 171 | @Override |
| 172 | public YangWhen getWhen() { |
| 173 | return when; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Sets the when. |
| 178 | * |
| 179 | * @param when the when to set |
| 180 | */ |
| 181 | @Override |
| 182 | public void setWhen(YangWhen when) { |
| 183 | this.when = when; |
| 184 | } |
| 185 | |
| 186 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 187 | * Returns the choice name. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 188 | * |
| 189 | * @return choice name |
| 190 | */ |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 191 | @Override |
| 192 | public String getName() { |
| 193 | return name; |
| 194 | } |
| 195 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 196 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 197 | * Sets the choice name. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 198 | * |
| 199 | * @param name choice name |
| 200 | */ |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 201 | @Override |
| 202 | public void setName(String name) { |
| 203 | this.name = name; |
| 204 | } |
| 205 | |
| 206 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 207 | * Returns config flag. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 208 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 209 | * @return the config flag |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 210 | */ |
| 211 | public boolean isConfig() { |
| 212 | return isConfig; |
| 213 | } |
| 214 | |
| 215 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 216 | * Sets config flag. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 217 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 218 | * @param isCfg the config flag |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 219 | */ |
| 220 | public void setConfig(boolean isCfg) { |
| 221 | isConfig = isCfg; |
| 222 | } |
| 223 | |
| 224 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 225 | * Returns the default case. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 226 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 227 | * @return the default case |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 228 | */ |
| 229 | public String getDefaultCase() { |
| 230 | return defaultCase; |
| 231 | } |
| 232 | |
| 233 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 234 | * Sets the default case. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 235 | * |
| 236 | * @param defaultCase the default case to set |
| 237 | */ |
| 238 | public void setDefaultCase(String defaultCase) { |
| 239 | this.defaultCase = defaultCase; |
| 240 | } |
| 241 | |
| 242 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 243 | * Returns the mandatory status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 244 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 245 | * @return the mandatory status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 246 | */ |
| 247 | public String getMandatory() { |
| 248 | return mandatory; |
| 249 | } |
| 250 | |
| 251 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 252 | * Sets the mandatory status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 253 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 254 | * @param mandatory the mandatory status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 255 | */ |
| 256 | public void setMandatory(String mandatory) { |
| 257 | this.mandatory = mandatory; |
| 258 | } |
| 259 | |
| 260 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 261 | * Returns the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 262 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 263 | * @return the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 264 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 265 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 266 | public String getDescription() { |
| 267 | return description; |
| 268 | } |
| 269 | |
| 270 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 271 | * Sets the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 272 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 273 | * @param description set the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 274 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 275 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 276 | public void setDescription(String description) { |
| 277 | this.description = description; |
| 278 | } |
| 279 | |
| 280 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 281 | * Returns the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 282 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 283 | * @return the reference |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 284 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 285 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 286 | public String getReference() { |
| 287 | return reference; |
| 288 | } |
| 289 | |
| 290 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 291 | * Sets the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 292 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 293 | * @param reference the reference to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 294 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 295 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 296 | public void setReference(String reference) { |
| 297 | this.reference = reference; |
| 298 | } |
| 299 | |
| 300 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 301 | * Returns the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 302 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 303 | * @return the status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 304 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 305 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 306 | public YangStatusType getStatus() { |
| 307 | return status; |
| 308 | } |
| 309 | |
| 310 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 311 | * Sets the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 312 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 313 | * @param status the status to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 314 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 315 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 316 | public void setStatus(YangStatusType status) { |
| 317 | this.status = status; |
| 318 | } |
| 319 | |
| 320 | /** |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 321 | * Returns the default value. |
| 322 | * |
| 323 | * @return the default value |
| 324 | */ |
| 325 | public String getDefaultValueInString() { |
| 326 | return defaultValueInString; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Sets the default value. |
| 331 | * |
| 332 | * @param defaultValueInString the default value |
| 333 | */ |
| 334 | public void setDefaultValueInString(String defaultValueInString) { |
| 335 | this.defaultValueInString = defaultValueInString; |
| 336 | } |
| 337 | |
| 338 | /** |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 339 | * Returns the type of the data. |
| 340 | * |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 341 | * @return choice data |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 342 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 343 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 344 | public YangConstructType getYangConstructType() { |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 345 | return CHOICE_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 349 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 350 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 351 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 352 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 353 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 354 | public void validateDataOnEntry() throws DataModelException { |
| 355 | // TODO auto-generated method stub, to be implemented by parser |
| 356 | } |
| 357 | |
| 358 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 359 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 360 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 361 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 362 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 363 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 364 | public void validateDataOnExit() throws DataModelException { |
| 365 | // TODO auto-generated method stub, to be implemented by parser |
| 366 | } |
| 367 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 368 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 369 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 370 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 371 | if (getParent() instanceof YangCase && dataType != YangConstructType.CASE_DATA) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 372 | ((CollisionDetector) getParent()).detectCollidingChild(identifierName, dataType); |
| 373 | } |
| 374 | YangNode node = getChild(); |
| 375 | while (node != null) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 376 | if (node instanceof CollisionDetector) { |
| 377 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
| 378 | } |
| 379 | node = node.getNextSibling(); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { |
| 385 | |
| 386 | if (dataType == CHOICE_DATA) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 387 | if (getName().equals(identifierName)) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 388 | throw new DataModelException("YANG file error: Identifier collision detected in choice \"" + |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 389 | getName() + "\""); |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 390 | } |
| 391 | return; |
| 392 | } |
| 393 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 394 | YangNode node = getChild(); |
| 395 | while (node != null) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 396 | if (node instanceof CollisionDetector) { |
| 397 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
| 398 | } |
| 399 | node = node.getNextSibling(); |
| 400 | } |
| 401 | } |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 402 | |
| 403 | @Override |
| 404 | public List<YangIfFeature> getIfFeatureList() { |
| 405 | return ifFeatureList; |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 410 | if (getIfFeatureList() == null) { |
| 411 | setIfFeatureList(new LinkedList<>()); |
| 412 | } |
| 413 | getIfFeatureList().add(ifFeature); |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 418 | this.ifFeatureList = ifFeatureList; |
| 419 | } |
| 420 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 421 | } |