Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | |
| 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 22 | import org.onosproject.yangutils.parser.Parsable; |
| 23 | import org.onosproject.yangutils.parser.ParsableDataType; |
| 24 | |
| 25 | /*- |
| 26 | * Reference RFC 6020. |
| 27 | * |
| 28 | * The "choice" statement defines a set of alternatives, only one of |
| 29 | * which may exist at any one time. The argument is an identifier, |
| 30 | * followed by a block of sub-statements that holds detailed choice |
| 31 | * information. The identifier is used to identify the choice node in |
| 32 | * the schema tree. A choice node does not exist in the data tree. |
| 33 | * |
| 34 | * A choice consists of a number of branches, defined with the "case" |
| 35 | * sub-statement. Each branch contains a number of child nodes. The |
| 36 | * nodes from at most one of the choice's branches exist at the same |
| 37 | * time. |
| 38 | * |
| 39 | * The choice's sub-statements |
| 40 | * |
| 41 | * +--------------+---------+-------------+------------------+ |
| 42 | * | substatement | section | cardinality |data model mapping| |
| 43 | * +--------------+---------+-------------+------------------+ |
| 44 | * | anyxml | 7.10 | 0..n |-not supported | |
| 45 | * | case | 7.9.2 | 0..n |-YangChoice | |
| 46 | * | config | 7.19.1 | 0..1 |-boolean | |
| 47 | * | container | 7.5 | 0..n |-child case nodes | |
| 48 | * | default | 7.9.3 | 0..1 |-string | |
| 49 | * | description | 7.19.3 | 0..1 |-string | |
| 50 | * | if-feature | 7.18.2 | 0..n |-TODO | |
| 51 | * | leaf | 7.6 | 0..n |-child case nodes | |
| 52 | * | leaf-list | 7.7 | 0..n |-child case nodes | |
| 53 | * | list | 7.8 | 0..n |-child case nodes | |
| 54 | * | mandatory | 7.9.4 | 0..1 |-string | |
| 55 | * | reference | 7.19.4 | 0..1 |-string | |
| 56 | * | status | 7.19.2 | 0..1 |-string | |
| 57 | * | when | 7.19.5 | 0..1 |-TODO | |
| 58 | * +--------------+---------+-------------+------------------+ |
| 59 | */ |
| 60 | /** |
| 61 | * Data model node to maintain information defined in YANG choice. |
| 62 | */ |
| 63 | public class YangChoice extends YangNode implements YangCommonInfo, Parsable { |
| 64 | |
| 65 | /** |
| 66 | * Name of choice. |
| 67 | */ |
| 68 | private String name; |
| 69 | |
| 70 | /** |
| 71 | * List of cases for the current choice. |
| 72 | */ |
| 73 | private List<YangCase> caseList; |
| 74 | |
| 75 | /** |
| 76 | * If the choice represents config data. |
| 77 | */ |
| 78 | private boolean isConfig; |
| 79 | |
| 80 | /** |
| 81 | * Reference RFC 6020. |
| 82 | * |
| 83 | * The "default" statement indicates if a case should be considered as the |
| 84 | * default if no child nodes from any of the choice's cases exist. The |
| 85 | * argument is the identifier of the "case" statement. If the "default" |
| 86 | * statement is missing, there is no default case. |
| 87 | * |
| 88 | * The "default" statement MUST NOT be present on choices where "mandatory" |
| 89 | * is true. |
| 90 | * |
| 91 | * The default case is only important when considering the default values of |
| 92 | * nodes under the cases. The default values for nodes under the default |
| 93 | * case are used if none of the nodes under any of the cases are present. |
| 94 | * |
| 95 | * There MUST NOT be any mandatory nodes directly under the default case. |
| 96 | * |
| 97 | * Default values for child nodes under a case are only used if one of the |
| 98 | * nodes under that case is present, or if that case is the default case. If |
| 99 | * none of the nodes under a case are present and the case is not the |
| 100 | * default case, the default values of the cases' child nodes are ignored. |
| 101 | * |
| 102 | * the default case to be used if no case members is present. |
| 103 | */ |
| 104 | private String defaultCase; |
| 105 | |
| 106 | /** |
| 107 | * Description. |
| 108 | */ |
| 109 | private String description; |
| 110 | |
| 111 | /** |
| 112 | * Reference RFC 6020. |
| 113 | * |
| 114 | * The "mandatory" statement, which is optional, takes as an argument the |
| 115 | * string "true" or "false", and puts a constraint on valid data. If |
| 116 | * "mandatory" is "true", at least one node from exactly one of the choice's |
| 117 | * case branches MUST exist. |
| 118 | * |
| 119 | * If not specified, the default is "false". |
| 120 | * |
| 121 | * The behavior of the constraint depends on the type of the choice's |
| 122 | * closest ancestor node in the schema tree which is not a non-presence |
| 123 | * container: |
| 124 | * |
| 125 | * o If this ancestor is a case node, the constraint is enforced if any |
| 126 | * other node from the case exists. |
| 127 | * |
| 128 | * o Otherwise, it is enforced if the ancestor node exists. |
| 129 | */ |
| 130 | private String mandatory; |
| 131 | |
| 132 | /** |
| 133 | * reference of the choice. |
| 134 | */ |
| 135 | private String reference; |
| 136 | |
| 137 | /** |
| 138 | * Status of the node. |
| 139 | */ |
| 140 | private YangStatusType status; |
| 141 | |
| 142 | /** |
| 143 | * Create a Choice node. |
| 144 | */ |
| 145 | public YangChoice() { |
| 146 | super(YangNodeType.CHOICE_NODE); |
| 147 | } |
| 148 | |
| 149 | /* (non-Javadoc) |
| 150 | * @see org.onosproject.yangutils.datamodel.YangNode#getName() |
| 151 | */ |
| 152 | @Override |
| 153 | public String getName() { |
| 154 | return name; |
| 155 | } |
| 156 | |
| 157 | /* (non-Javadoc) |
| 158 | * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) |
| 159 | */ |
| 160 | @Override |
| 161 | public void setName(String name) { |
| 162 | this.name = name; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Get the list of cases. |
| 167 | * |
| 168 | * @return the case list |
| 169 | */ |
| 170 | public List<YangCase> getCaseList() { |
| 171 | return caseList; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Set the list of cases. |
| 176 | * |
| 177 | * @param caseList list of cases. |
| 178 | */ |
| 179 | private void setCaseList(List<YangCase> caseList) { |
| 180 | this.caseList = caseList; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Add a case. |
| 185 | * |
| 186 | * @param newCase new case for the choice |
| 187 | */ |
| 188 | public void addCase(YangCase newCase) { |
| 189 | if (getCaseList() == null) { |
| 190 | setCaseList(new LinkedList<YangCase>()); |
| 191 | } |
| 192 | |
| 193 | getCaseList().add(newCase); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Get config flag. |
| 198 | * |
| 199 | * @return the config flag. |
| 200 | */ |
| 201 | public boolean isConfig() { |
| 202 | return isConfig; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Set config flag. |
| 207 | * |
| 208 | * @param isCfg the config flag. |
| 209 | */ |
| 210 | public void setConfig(boolean isCfg) { |
| 211 | isConfig = isCfg; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Get the default case. |
| 216 | * |
| 217 | * @return the default case. |
| 218 | */ |
| 219 | public String getDefaultCase() { |
| 220 | return defaultCase; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Set the default case. |
| 225 | * |
| 226 | * @param defaultCase the default case to set |
| 227 | */ |
| 228 | public void setDefaultCase(String defaultCase) { |
| 229 | this.defaultCase = defaultCase; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Get the mandatory status. |
| 234 | * |
| 235 | * @return the mandatory status. |
| 236 | */ |
| 237 | public String getMandatory() { |
| 238 | return mandatory; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Set the mandatory status. |
| 243 | * |
| 244 | * @param mandatory the mandatory status. |
| 245 | */ |
| 246 | public void setMandatory(String mandatory) { |
| 247 | this.mandatory = mandatory; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Get the description. |
| 252 | * |
| 253 | * @return the description. |
| 254 | */ |
| 255 | public String getDescription() { |
| 256 | return description; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Set the description. |
| 261 | * |
| 262 | * @param description set the description. |
| 263 | */ |
| 264 | public void setDescription(String description) { |
| 265 | this.description = description; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Get the textual reference. |
| 270 | * |
| 271 | * @return the reference. |
| 272 | */ |
| 273 | public String getReference() { |
| 274 | return reference; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Set the textual reference. |
| 279 | * |
| 280 | * @param reference the reference to set. |
| 281 | */ |
| 282 | public void setReference(String reference) { |
| 283 | this.reference = reference; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Get the status. |
| 288 | * |
| 289 | * @return the status. |
| 290 | */ |
| 291 | public YangStatusType getStatus() { |
| 292 | return status; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Set the status. |
| 297 | * |
| 298 | * @param status the status to set. |
| 299 | */ |
| 300 | public void setStatus(YangStatusType status) { |
| 301 | this.status = status; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Returns the type of the data. |
| 306 | * |
| 307 | * @return returns CHOICE_DATA |
| 308 | */ |
| 309 | public ParsableDataType getParsableDataType() { |
| 310 | return ParsableDataType.CHOICE_DATA; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Validate the data on entering the corresponding parse tree node. |
| 315 | * |
| 316 | * @throws DataModelException a violation of data model rules. |
| 317 | */ |
| 318 | public void validateDataOnEntry() throws DataModelException { |
| 319 | // TODO auto-generated method stub, to be implemented by parser |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Validate the data on exiting the corresponding parse tree node. |
| 324 | * |
| 325 | * @throws DataModelException a violation of data model rules. |
| 326 | */ |
| 327 | public void validateDataOnExit() throws DataModelException { |
| 328 | // TODO auto-generated method stub, to be implemented by parser |
| 329 | } |
| 330 | |
| 331 | /* (non-Javadoc) |
| 332 | * @see org.onosproject.yangutils.datamodel.YangNode#getPackage() |
| 333 | */ |
| 334 | @Override |
| 335 | public String getPackage() { |
| 336 | // TODO Auto-generated method stub |
| 337 | return null; |
| 338 | } |
| 339 | |
| 340 | /* (non-Javadoc) |
| 341 | * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String) |
| 342 | */ |
| 343 | @Override |
| 344 | public void setPackage(String pkg) { |
| 345 | // TODO Auto-generated method stub |
| 346 | |
| 347 | } |
| 348 | |
| 349 | /* (non-Javadoc) |
| 350 | * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry() |
| 351 | */ |
| 352 | public void generateJavaCodeEntry() { |
| 353 | // TODO Auto-generated method stub |
| 354 | |
| 355 | } |
| 356 | |
| 357 | /* (non-Javadoc) |
| 358 | * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit() |
| 359 | */ |
| 360 | public void generateJavaCodeExit() { |
| 361 | // TODO Auto-generated method stub |
| 362 | |
| 363 | } |
| 364 | } |