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; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 24 | |
| 25 | /*- |
| 26 | * Reference RFC 6020. |
| 27 | * |
| 28 | * The "augment" statement allows a module or submodule to add to the |
| 29 | * schema tree defined in an external module, or the current module and |
| 30 | * its submodules, and to add to the nodes from a grouping in a "uses" |
| 31 | * statement. The argument is a string that identifies a node in the |
| 32 | * schema tree. This node is called the augment's target node. The |
| 33 | * target node MUST be either a container, list, choice, case, input, |
| 34 | * output, or notification node. It is augmented with the nodes defined |
| 35 | * in the sub-statements that follow the "augment" statement. |
| 36 | * |
| 37 | * The argument string is a schema node identifier. |
| 38 | * If the "augment" statement is on the top level in a module or |
| 39 | * submodule, the absolute form of a schema node identifier |
| 40 | * MUST be used. If the "augment" statement is a sub-statement to the |
| 41 | * "uses" statement, the descendant form MUST be used. |
| 42 | * |
| 43 | * If the target node is a container, list, case, input, output, or |
| 44 | * notification node, the "container", "leaf", "list", "leaf-list", |
| 45 | * "uses", and "choice" statements can be used within the "augment" |
| 46 | * statement. |
| 47 | * |
| 48 | * If the target node is a choice node, the "case" statement, or a case |
| 49 | * shorthand statement can be used within the "augment" statement. |
| 50 | * |
| 51 | * If the target node is in another module, then nodes added by the |
| 52 | * augmentation MUST NOT be mandatory nodes. |
| 53 | * |
| 54 | * The "augment" statement MUST NOT add multiple nodes with the same |
| 55 | * name from the same module to the target node. |
| 56 | * The augment's sub-statements |
| 57 | * |
| 58 | * +--------------+---------+-------------+------------------+ |
| 59 | * | substatement | section | cardinality |data model mapping| |
| 60 | * +--------------+---------+-------------+------------------+ |
| 61 | * | anyxml | 7.10 | 0..n |-not supported | |
| 62 | * | case | 7.9.2 | 0..n |-child nodes | |
| 63 | * | choice | 7.9 | 0..n |-child nodes | |
| 64 | * | container | 7.5 | 0..n |-child nodes | |
| 65 | * | description | 7.19.3 | 0..1 |-string | |
| 66 | * | if-feature | 7.18.2 | 0..n |-TODO | |
| 67 | * | leaf | 7.6 | 0..n |-YangLeaf | |
| 68 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
| 69 | * | list | 7.8 | 0..n |-child nodes | |
| 70 | * | reference | 7.19.4 | 0..1 |-String | |
| 71 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 72 | * | uses | 7.12 | 0..n |-child nodes | |
| 73 | * | when | 7.19.5 | 0..1 |-TODO | |
| 74 | * +--------------+---------+-------------+------------------+ |
| 75 | */ |
| 76 | /** |
| 77 | * Data model node to maintain information defined in YANG augment. |
| 78 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 79 | public class YangAugment extends YangNode |
| 80 | implements YangLeavesHolder, YangCommonInfo, Parsable { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Augment target node. |
| 84 | */ |
| 85 | private String targetNode; |
| 86 | |
| 87 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 88 | * Description of augment. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 89 | */ |
| 90 | private String description; |
| 91 | |
| 92 | /** |
| 93 | * List of leaves. |
| 94 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 95 | private List<YangLeaf> listOfLeaf; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * List of leaf-lists. |
| 99 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 100 | private List<YangLeafList> listOfLeafList; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 101 | |
| 102 | /** |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 103 | * Reference of the YANG augment. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 104 | */ |
| 105 | private String reference; |
| 106 | |
| 107 | /** |
| 108 | * Status of the node. |
| 109 | */ |
| 110 | private YangStatusType status; |
| 111 | |
| 112 | /** |
| 113 | * Create a YANG augment node. |
| 114 | */ |
| 115 | public YangAugment() { |
| 116 | super(YangNodeType.AUGMENT_NODE); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Get the augmented node. |
| 121 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 122 | * @return the augmented node |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 123 | */ |
| 124 | public String getTargetNode() { |
| 125 | return targetNode; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Set the augmented node. |
| 130 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 131 | * @param targetNode the augmented node |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 132 | */ |
| 133 | public void setTargetNode(String targetNode) { |
| 134 | this.targetNode = targetNode; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Get the description. |
| 139 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 140 | * @return the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 141 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 142 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 143 | public String getDescription() { |
| 144 | return description; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Set the description. |
| 149 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 150 | * @param description set the description |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 151 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 152 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 153 | public void setDescription(String description) { |
| 154 | this.description = description; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Get the list of leaves. |
| 159 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | * @return the list of leaves |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 161 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 162 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 163 | public List<YangLeaf> getListOfLeaf() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 164 | return listOfLeaf; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Set the list of leaves. |
| 169 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 170 | * @param leafsList the list of leaf to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 171 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 172 | private void setListOfLeaf(List<YangLeaf> leafsList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 173 | listOfLeaf = leafsList; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Add a leaf. |
| 178 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 179 | * @param leaf the leaf to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 180 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 181 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 182 | public void addLeaf(YangLeaf leaf) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 183 | if (getListOfLeaf() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 184 | setListOfLeaf(new LinkedList<YangLeaf>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | getListOfLeaf().add(leaf); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Get the list of leaf-list. |
| 192 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 193 | * @return the list of leaf-list |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 194 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 195 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 196 | public List<YangLeafList> getListOfLeafList() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 197 | return listOfLeafList; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Set the list of leaf-list. |
| 202 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 203 | * @param listOfLeafList the list of leaf-list to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 204 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 205 | private void setListOfLeafList(List<YangLeafList> listOfLeafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 206 | this.listOfLeafList = listOfLeafList; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Add a leaf-list. |
| 211 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 212 | * @param leafList the leaf-list to be added |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 213 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 214 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 215 | public void addLeafList(YangLeafList leafList) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 216 | if (getListOfLeafList() == null) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 217 | setListOfLeafList(new LinkedList<YangLeafList>()); |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | getListOfLeafList().add(leafList); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Get the textual reference. |
| 225 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 226 | * @return the reference |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 227 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 228 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 229 | public String getReference() { |
| 230 | return reference; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Set the textual reference. |
| 235 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 236 | * @param reference the reference to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 237 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 238 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 239 | public void setReference(String reference) { |
| 240 | this.reference = reference; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Get the status. |
| 245 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 246 | * @return the status |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 247 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 248 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 249 | public YangStatusType getStatus() { |
| 250 | return status; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Set the status. |
| 255 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 256 | * @param status the status to set |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 257 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 258 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 259 | public void setStatus(YangStatusType status) { |
| 260 | this.status = status; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Returns the type of the data as belongs-to. |
| 265 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 266 | * @return returns AUGMENT_DATA |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 267 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 268 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 269 | public YangConstructType getYangConstructType() { |
| 270 | return YangConstructType.AUGMENT_DATA; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Validate the data on entering the corresponding parse tree node. |
| 275 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 276 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 277 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 278 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 279 | public void validateDataOnEntry() throws DataModelException { |
| 280 | // TODO auto-generated method stub, to be implemented by parser |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Validate the data on exiting the corresponding parse tree node. |
| 285 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 286 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 287 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 288 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 289 | public void validateDataOnExit() throws DataModelException { |
| 290 | // TODO auto-generated method stub, to be implemented by parser |
| 291 | } |
| 292 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 293 | /** |
| 294 | * Get the target nodes name where the augmentation is being done. |
| 295 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 296 | * @return target nodes name where the augmentation is being done |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 297 | */ |
| 298 | @Override |
| 299 | public String getName() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 300 | return targetNode; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 301 | } |
| 302 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 303 | /** |
| 304 | * Set the target nodes name where the augmentation is being done. |
| 305 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 306 | * @param name target nodes name where the augmentation is being done |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 307 | */ |
| 308 | @Override |
| 309 | public void setName(String name) { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 310 | targetNode = name; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 311 | |
| 312 | } |
| 313 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 314 | } |