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