Vinod Kumar S | 67e7be6 | 2016-02-11 20:13:28 +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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
| 19 | import java.util.LinkedList; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 23 | import org.onosproject.yangutils.parser.Parsable; |
| 24 | import org.onosproject.yangutils.parser.ParsableDataType; |
| 25 | import org.onosproject.yangutils.utils.io.CachedFileHandle; |
| 26 | /*- |
| 27 | * Reference RFC 6020. |
| 28 | * |
| 29 | * The "container" statement is used to define an interior data node in the |
| 30 | * schema tree. It takes one argument, which is an identifier, followed by a |
| 31 | * block of sub-statements that holds detailed container information. |
| 32 | * |
| 33 | * A container node does not have a value, but it has a list of child nodes in |
| 34 | * the data tree. The child nodes are defined in the container's sub-statements. |
| 35 | * |
| 36 | * Containers with Presence |
| 37 | * |
| 38 | * YANG supports two styles of containers, those that exist only for organizing |
| 39 | * the hierarchy of data nodes, and those whose presence in the configuration |
| 40 | * has an explicit meaning. |
| 41 | * |
| 42 | * In the first style, the container has no meaning of its own, existing only to |
| 43 | * contain child nodes. This is the default style. |
| 44 | * |
| 45 | * For example, the set of scrambling options for Synchronous Optical Network |
| 46 | * (SONET) interfaces may be placed inside a "scrambling" container to enhance |
| 47 | * the organization of the configuration hierarchy, and to keep these nodes |
| 48 | * together. The "scrambling" node itself has no meaning, so removing the node |
| 49 | * when it becomes empty relieves the user from performing this task. |
| 50 | * |
| 51 | * In the second style, the presence of the container itself is configuration |
| 52 | * data, representing a single bit of configuration data. The container acts as |
| 53 | * both a configuration knob and a means of organizing related configuration. |
| 54 | * These containers are explicitly created and deleted. |
| 55 | * |
| 56 | * YANG calls this style a "presence container" and it is indicated using the |
| 57 | * "presence" statement, which takes as its argument a text string indicating |
| 58 | * what the presence of the node means. |
| 59 | * |
| 60 | * The container's Substatements |
| 61 | * |
| 62 | * +--------------+---------+-------------+------------------+ |
| 63 | * | substatement | section | cardinality |data model mapping| |
| 64 | * +--------------+---------+-------------+------------------+ |
| 65 | * | anyxml | 7.10 | 0..n | -not supported | |
| 66 | * | choice | 7.9 | 0..n | -child nodes | |
| 67 | * | config | 7.19.1 | 0..1 | -boolean | |
| 68 | * | container | 7.5 | 0..n | -child nodes | |
| 69 | * | description | 7.19.3 | 0..1 | -string | |
| 70 | * | grouping | 7.11 | 0..n | -child nodes | |
| 71 | * | if-feature | 7.18.2 | 0..n | -TODO | |
| 72 | * | leaf | 7.6 | 0..n | -YangLeaf | |
| 73 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
| 74 | * | list | 7.8 | 0..n | -child nodes | |
| 75 | * | must | 7.5.3 | 0..n | -TODO | |
| 76 | * | presence | 7.5.5 | 0..1 | -boolean | |
| 77 | * | reference | 7.19.4 | 0..1 | -string | |
| 78 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 79 | * | typedef | 7.3 | 0..n | -child nodes | |
| 80 | * | uses | 7.12 | 0..n | -child nodes | |
| 81 | * | when | 7.19.5 | 0..1 | -TODO | |
| 82 | * +--------------+---------+-------------+------------------+ |
| 83 | */ |
| 84 | |
| 85 | /** |
| 86 | * Data model node to maintain information defined in YANG container. |
| 87 | */ |
| 88 | public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable { |
| 89 | |
| 90 | /** |
| 91 | * Name of the container. |
| 92 | */ |
| 93 | private String name; |
| 94 | |
| 95 | /** |
| 96 | * If container maintains config data. |
| 97 | */ |
| 98 | private boolean isConfig; |
| 99 | |
| 100 | /** |
| 101 | * Description of container. |
| 102 | */ |
| 103 | private String description; |
| 104 | |
| 105 | /** |
| 106 | * List of leaves contained. |
| 107 | */ |
| 108 | @SuppressWarnings("rawtypes") |
| 109 | private List<YangLeaf> listOfLeaf; |
| 110 | |
| 111 | /** |
| 112 | * List of leaf-lists contained. |
| 113 | */ |
| 114 | @SuppressWarnings("rawtypes") |
| 115 | private List<YangLeafList> listOfLeafList; |
| 116 | |
| 117 | /** |
| 118 | * If it is a presence container, then the textual documentation of presence |
| 119 | * usage. |
| 120 | */ |
| 121 | private String presence; |
| 122 | |
| 123 | /** |
| 124 | * Reference of the module. |
| 125 | */ |
| 126 | private String reference; |
| 127 | |
| 128 | /** |
| 129 | * Status of the node. |
| 130 | */ |
| 131 | private YangStatusType status; |
| 132 | |
| 133 | /** |
| 134 | * package of the generated java code. |
| 135 | */ |
| 136 | private String pkg; |
| 137 | |
| 138 | /** |
| 139 | * Cached Java File Handle. |
| 140 | */ |
| 141 | private CachedFileHandle fileHandle; |
| 142 | |
| 143 | /** |
| 144 | * Create a container node. |
| 145 | */ |
| 146 | public YangContainer() { |
| 147 | super(YangNodeType.CONTAINER_NODE); |
| 148 | } |
| 149 | |
| 150 | /* (non-Javadoc) |
| 151 | * @see org.onosproject.yangutils.datamodel.YangNode#getName() |
| 152 | */ |
| 153 | @Override |
| 154 | public String getName() { |
| 155 | return name; |
| 156 | } |
| 157 | |
| 158 | /* (non-Javadoc) |
| 159 | * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String) |
| 160 | */ |
| 161 | @Override |
| 162 | public void setName(String name) { |
| 163 | this.name = name; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the config flag. |
| 168 | * |
| 169 | * @return the isConfig |
| 170 | */ |
| 171 | public boolean isConfig() { |
| 172 | return isConfig; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Set the config flag. |
| 177 | * |
| 178 | * @param isCfg the config flag. |
| 179 | */ |
| 180 | public void setConfig(boolean isCfg) { |
| 181 | isConfig = isCfg; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Get the description. |
| 186 | * |
| 187 | * @return the description. |
| 188 | */ |
| 189 | public String getDescription() { |
| 190 | return description; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Set the description. |
| 195 | * |
| 196 | * @param description set the description. |
| 197 | */ |
| 198 | public void setDescription(String description) { |
| 199 | this.description = description; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Get the list of leaves. |
| 204 | * |
| 205 | * @return the list of leaves. |
| 206 | */ |
| 207 | @SuppressWarnings("rawtypes") |
| 208 | public List<YangLeaf> getListOfLeaf() { |
| 209 | return listOfLeaf; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Set the list of leaves. |
| 214 | * |
| 215 | * @param leafsList the list of leaf to set. |
| 216 | */ |
| 217 | @SuppressWarnings("rawtypes") |
| 218 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
| 219 | listOfLeaf = leafsList; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Add a leaf. |
| 224 | * |
| 225 | * @param leaf the leaf to be added. |
| 226 | */ |
| 227 | @SuppressWarnings("rawtypes") |
| 228 | public void addLeaf(YangLeaf<?> leaf) { |
| 229 | if (getListOfLeaf() == null) { |
| 230 | setListOfLeaf(new LinkedList<YangLeaf>()); |
| 231 | } |
| 232 | |
| 233 | getListOfLeaf().add(leaf); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Get the list of leaf-list. |
| 238 | * |
| 239 | * @return the list of leaf-list. |
| 240 | */ |
| 241 | @SuppressWarnings("rawtypes") |
| 242 | public List<YangLeafList> getListOfLeafList() { |
| 243 | return listOfLeafList; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Set the list of leaf-list. |
| 248 | * |
| 249 | * @param listOfLeafList the list of leaf-list to set. |
| 250 | */ |
| 251 | @SuppressWarnings("rawtypes") |
| 252 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
| 253 | this.listOfLeafList = listOfLeafList; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Add a leaf-list. |
| 258 | * |
| 259 | * @param leafList the leaf-list to be added. |
| 260 | */ |
| 261 | @SuppressWarnings("rawtypes") |
| 262 | public void addLeafList(YangLeafList<?> leafList) { |
| 263 | if (getListOfLeafList() == null) { |
| 264 | setListOfLeafList(new LinkedList<YangLeafList>()); |
| 265 | } |
| 266 | |
| 267 | getListOfLeafList().add(leafList); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Get the presence string if present. |
| 272 | * |
| 273 | * @return the isPressence. |
| 274 | */ |
| 275 | public String getPresence() { |
| 276 | return presence; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Set the presence string. |
| 281 | * |
| 282 | * @param presence the presence flag |
| 283 | */ |
| 284 | public void setPresence(String presence) { |
| 285 | this.presence = presence; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Get the textual reference. |
| 290 | * |
| 291 | * @return the reference. |
| 292 | */ |
| 293 | public String getReference() { |
| 294 | return reference; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Set the textual reference. |
| 299 | * |
| 300 | * @param reference the reference to set. |
| 301 | */ |
| 302 | public void setReference(String reference) { |
| 303 | this.reference = reference; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Get the status. |
| 308 | * |
| 309 | * @return the status. |
| 310 | */ |
| 311 | public YangStatusType getStatus() { |
| 312 | return status; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Set the status. |
| 317 | * |
| 318 | * @param status the status to set. |
| 319 | */ |
| 320 | public void setStatus(YangStatusType status) { |
| 321 | this.status = status; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Get the cached file handle. |
| 326 | * |
| 327 | * @return the fileHandle |
| 328 | */ |
| 329 | public CachedFileHandle getFileHandle() { |
| 330 | return fileHandle; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Set the cached file handle. |
| 335 | * |
| 336 | * @param handle the fileHandle to set |
| 337 | */ |
| 338 | public void setFileHandle(CachedFileHandle handle) { |
| 339 | fileHandle = handle; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Returns the type of the data. |
| 344 | * |
| 345 | * @return returns CONTAINER_DATA. |
| 346 | */ |
| 347 | public ParsableDataType getParsableDataType() { |
| 348 | return ParsableDataType.CONTAINER_DATA; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Validate the data on entering the corresponding parse tree node. |
| 353 | * |
| 354 | * @throws DataModelException a violation of data model rules. |
| 355 | */ |
| 356 | public void validateDataOnEntry() throws DataModelException { |
| 357 | // TODO auto-generated method stub, to be implemented by parser |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Validate the data on exiting the corresponding parse tree node. |
| 362 | * |
| 363 | * @throws DataModelException a violation of data model rules. |
| 364 | */ |
| 365 | public void validateDataOnExit() throws DataModelException { |
| 366 | // TODO auto-generated method stub, to be implemented by parser |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Get the mapped java package. |
| 371 | * |
| 372 | * @return the java package |
| 373 | */ |
| 374 | @Override |
| 375 | public String getPackage() { |
| 376 | return pkg; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Set the mapped java package. |
| 381 | * |
| 382 | * @param pcg the package to set |
| 383 | */ |
| 384 | @Override |
| 385 | public void setPackage(String pcg) { |
| 386 | pkg = pcg; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Generate the java code corresponding to YANG container. |
| 391 | */ |
| 392 | public void generateJavaCodeEntry() { |
| 393 | //TODO: autogenerated method stub, to be implemented |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Free resources used to generate code. |
| 399 | */ |
| 400 | public void generateJavaCodeExit() { |
| 401 | //TODO: autogenerated method stub, to be implemented |
| 402 | return; |
| 403 | } |
| 404 | } |