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