blob: 84f0173e201029c514f4709127ee5fb7e9575f0a [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05303 *
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 */
16package org.onosproject.yangutils.datamodel;
17
18import java.util.LinkedList;
19import java.util.List;
20
21import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053022import org.onosproject.yangutils.datamodel.utils.Parsable;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053024
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053025import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
26
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053027/*-
28 * Reference RFC 6020.
29 *
30 * The "augment" statement allows a module or submodule to add to the
31 * schema tree defined in an external module, or the current module and
32 * its submodules, and to add to the nodes from a grouping in a "uses"
33 * statement. The argument is a string that identifies a node in the
34 * schema tree. This node is called the augment's target node. The
35 * target node MUST be either a container, list, choice, case, input,
36 * output, or notification node. It is augmented with the nodes defined
37 * in the sub-statements that follow the "augment" statement.
38 *
39 * The argument string is a schema node identifier.
40 * If the "augment" statement is on the top level in a module or
41 * submodule, the absolute form of a schema node identifier
42 * MUST be used. If the "augment" statement is a sub-statement to the
43 * "uses" statement, the descendant form MUST be used.
44 *
45 * If the target node is a container, list, case, input, output, or
46 * notification node, the "container", "leaf", "list", "leaf-list",
47 * "uses", and "choice" statements can be used within the "augment"
48 * statement.
49 *
50 * If the target node is a choice node, the "case" statement, or a case
51 * shorthand statement can be used within the "augment" statement.
52 *
53 * If the target node is in another module, then nodes added by the
54 * augmentation MUST NOT be mandatory nodes.
55 *
56 * The "augment" statement MUST NOT add multiple nodes with the same
57 * name from the same module to the target node.
58 * The augment's sub-statements
59 *
60 * +--------------+---------+-------------+------------------+
61 * | substatement | section | cardinality |data model mapping|
62 * +--------------+---------+-------------+------------------+
63 * | anyxml | 7.10 | 0..n |-not supported |
64 * | case | 7.9.2 | 0..n |-child nodes |
65 * | choice | 7.9 | 0..n |-child nodes |
66 * | container | 7.5 | 0..n |-child nodes |
67 * | description | 7.19.3 | 0..1 |-string |
68 * | if-feature | 7.18.2 | 0..n |-TODO |
69 * | leaf | 7.6 | 0..n |-YangLeaf |
70 * | leaf-list | 7.7 | 0..n |-YangLeafList |
71 * | list | 7.8 | 0..n |-child nodes |
72 * | reference | 7.19.4 | 0..1 |-String |
73 * | status | 7.19.2 | 0..1 |-YangStatus |
74 * | uses | 7.12 | 0..n |-child nodes |
75 * | when | 7.19.5 | 0..1 |-TODO |
76 * +--------------+---------+-------------+------------------+
77 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053078
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079/**
Bharat saraswald9822e92016-04-05 15:13:44 +053080 * Representation of data model node to maintain information defined in YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053081 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053082public class YangAugment
83 extends YangNode
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053084 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053085
Bharat saraswal96dfef02016-06-16 00:29:12 +053086 private static final long serialVersionUID = 806201602L;
87
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053088 /**
89 * Augment target node.
90 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053091 private String name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092
93 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053094 * Description of augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053095 */
96 private String description;
97
98 /**
99 * List of leaves.
100 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530101 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530102
103 /**
104 * List of leaf-lists.
105 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530106 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530107
108 /**
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530109 * List of node identifiers.
110 */
111 private List<YangNodeIdentifier> targetNode;
112
113 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530114 * Reference of the YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530115 */
116 private String reference;
117
118 /**
119 * Status of the node.
120 */
121 private YangStatusType status;
122
123 /**
124 * Create a YANG augment node.
125 */
126 public YangAugment() {
127 super(YangNodeType.AUGMENT_NODE);
128 }
129
130 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530131 * Returns the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530132 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530133 * @return the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530134 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530135 public List<YangNodeIdentifier> getTargetNode() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530136 return targetNode;
137 }
138
139 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530140 * Sets the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530141 *
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530142 * @param nodeIdentifiers the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530144 public void setTargetNode(List<YangNodeIdentifier> nodeIdentifiers) {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530145 targetNode = nodeIdentifiers;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530146 }
147
148 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530149 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530151 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530153 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 public String getDescription() {
155 return description;
156 }
157
158 /**
159 * Set the description.
160 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530161 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530162 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530163 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530164 public void setDescription(String description) {
165 this.description = description;
166 }
167
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530168 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530169 public void detectCollidingChild(String identifierName, YangConstructType dataType)
170 throws DataModelException {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530171 // Detect colliding child.
172 detectCollidingChildUtil(identifierName, dataType, this);
173 }
174
175 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530176 public void detectSelfCollision(String identifierName, YangConstructType dataType)
177 throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530178 if (getName().equals(identifierName)) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530179 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
Bharat saraswal96dfef02016-06-16 00:29:12 +0530180 + getName() + "\"");
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530181 }
182 }
183
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530185 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530186 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530187 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530188 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530189 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530190 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 return listOfLeaf;
192 }
193
194 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530195 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530196 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530197 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530199 @Override
200 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 listOfLeaf = leafsList;
202 }
203
204 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530205 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530207 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530208 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530209 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530210 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530211 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530212 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 }
214
215 getListOfLeaf().add(leaf);
216 }
217
218 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530219 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530220 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530221 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530222 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530223 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530224 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 return listOfLeafList;
226 }
227
228 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530229 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530230 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530231 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530232 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530233 @Override
234 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530235 this.listOfLeafList = listOfLeafList;
236 }
237
238 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530239 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530242 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530243 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530244 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530245 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530246 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 }
248
249 getListOfLeafList().add(leafList);
250 }
251
252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530254 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530256 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530257 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530258 public String getReference() {
259 return reference;
260 }
261
262 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530263 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530264 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530265 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530267 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530268 public void setReference(String reference) {
269 this.reference = reference;
270 }
271
272 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530273 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530275 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530276 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530277 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 public YangStatusType getStatus() {
279 return status;
280 }
281
282 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530283 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530286 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530287 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530288 public void setStatus(YangStatusType status) {
289 this.status = status;
290 }
291
292 /**
293 * Returns the type of the data as belongs-to.
294 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530295 * @return returns AUGMENT_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530296 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530297 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530298 public YangConstructType getYangConstructType() {
299 return YangConstructType.AUGMENT_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530300 }
301
302 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530303 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530304 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530305 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530306 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530307 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530308 public void validateDataOnEntry()
309 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530310 // TODO auto-generated method stub, to be implemented by parser
311 }
312
313 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530314 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530315 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530316 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530317 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530318 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530319 public void validateDataOnExit()
320 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530321 // TODO auto-generated method stub, to be implemented by parser
322 }
323
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530324 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530325 * Returns the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530326 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530327 * @return target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530328 */
329 @Override
330 public String getName() {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530331 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530332 }
333
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530334 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530335 * Sets the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530336 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530337 * @param name target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530338 */
339 @Override
340 public void setName(String name) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530341 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530342 }
343
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530344}