blob: 9d37d463b2747cada127afc43d99dda07fb27ed7 [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;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053023import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
Bharat saraswal96dfef02016-06-16 00:29:12 +053024import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053026import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
27
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053028/*-
29 * Reference RFC 6020.
30 *
31 * The "augment" statement allows a module or submodule to add to the
32 * schema tree defined in an external module, or the current module and
33 * its submodules, and to add to the nodes from a grouping in a "uses"
34 * statement. The argument is a string that identifies a node in the
35 * schema tree. This node is called the augment's target node. The
36 * target node MUST be either a container, list, choice, case, input,
37 * output, or notification node. It is augmented with the nodes defined
38 * in the sub-statements that follow the "augment" statement.
39 *
40 * The argument string is a schema node identifier.
41 * If the "augment" statement is on the top level in a module or
42 * submodule, the absolute form of a schema node identifier
43 * MUST be used. If the "augment" statement is a sub-statement to the
44 * "uses" statement, the descendant form MUST be used.
45 *
46 * If the target node is a container, list, case, input, output, or
47 * notification node, the "container", "leaf", "list", "leaf-list",
48 * "uses", and "choice" statements can be used within the "augment"
49 * statement.
50 *
51 * If the target node is a choice node, the "case" statement, or a case
52 * shorthand statement can be used within the "augment" statement.
53 *
54 * If the target node is in another module, then nodes added by the
55 * augmentation MUST NOT be mandatory nodes.
56 *
57 * The "augment" statement MUST NOT add multiple nodes with the same
58 * name from the same module to the target node.
59 * The augment's sub-statements
60 *
61 * +--------------+---------+-------------+------------------+
62 * | substatement | section | cardinality |data model mapping|
63 * +--------------+---------+-------------+------------------+
64 * | anyxml | 7.10 | 0..n |-not supported |
65 * | case | 7.9.2 | 0..n |-child nodes |
66 * | choice | 7.9 | 0..n |-child nodes |
67 * | container | 7.5 | 0..n |-child nodes |
68 * | description | 7.19.3 | 0..1 |-string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053069 * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053070 * | leaf | 7.6 | 0..n |-YangLeaf |
71 * | leaf-list | 7.7 | 0..n |-YangLeafList |
72 * | list | 7.8 | 0..n |-child nodes |
73 * | reference | 7.19.4 | 0..1 |-String |
74 * | status | 7.19.2 | 0..1 |-YangStatus |
75 * | uses | 7.12 | 0..n |-child nodes |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053076 * | when | 7.19.5 | 0..1 |-YangWhen |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053077 * +--------------+---------+-------------+------------------+
78 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053079
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053080/**
Bharat saraswald9822e92016-04-05 15:13:44 +053081 * Representation of data model node to maintain information defined in YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053082 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053083public class YangAugment
84 extends YangNode
Bharat saraswalb1170bd2016-07-14 13:26:18 +053085 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentedInfo, Resolvable,
86 YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053087
Bharat saraswal96dfef02016-06-16 00:29:12 +053088 private static final long serialVersionUID = 806201602L;
89
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053090 /**
91 * Augment target node.
92 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053093 private String name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094
95 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053096 * Description of augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053097 */
98 private String description;
99
100 /**
101 * List of leaves.
102 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530103 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530104
105 /**
106 * List of leaf-lists.
107 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530108 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530109
110 /**
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530111 * List of node identifiers.
112 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530113 private List<YangAtomicPath> targetNode;
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530114
115 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530116 * Reference of the YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530117 */
118 private String reference;
119
120 /**
121 * Status of the node.
122 */
123 private YangStatusType status;
124
125 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530126 * Resolved augmented node.
127 */
128 private YangNode augmentedNode;
129
130 /**
131 * Status of resolution. If completely resolved enum value is "RESOLVED",
132 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
133 * is added to uses/type but it's not resolved value of enum should be
134 * "INTRA_FILE_RESOLVED".
135 */
136 private ResolvableStatus resolvableStatus;
137
138 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530139 * When data of the node.
140 */
141 private YangWhen when;
142
143 /**
144 * List of if-feature.
145 */
146 private List<YangIfFeature> ifFeatureList;
147
148 /**
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 * Create a YANG augment node.
150 */
151 public YangAugment() {
152 super(YangNodeType.AUGMENT_NODE);
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530153 resolvableStatus = ResolvableStatus.UNRESOLVED;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 }
155
156 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530157 * Returns the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530159 * @return the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530161 public List<YangAtomicPath> getTargetNode() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530162 return targetNode;
163 }
164
165 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530166 * Sets the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530167 *
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530168 * @param nodeIdentifiers the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530170 public void setTargetNode(List<YangAtomicPath> nodeIdentifiers) {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530171 targetNode = nodeIdentifiers;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530172 }
173
174 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530175 * Returns the when.
176 *
177 * @return the when
178 */
179 @Override
180 public YangWhen getWhen() {
181 return when;
182 }
183
184 /**
185 * Sets the when.
186 *
187 * @param when the when to set
188 */
189 @Override
190 public void setWhen(YangWhen when) {
191 this.when = when;
192 }
193
194 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530195 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530196 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530197 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530199 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530200 public String getDescription() {
201 return description;
202 }
203
204 /**
205 * Set the description.
206 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530207 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530208 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530209 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530210 public void setDescription(String description) {
211 this.description = description;
212 }
213
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530214 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530215 public void detectCollidingChild(String identifierName, YangConstructType dataType)
216 throws DataModelException {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530217 // Detect colliding child.
218 detectCollidingChildUtil(identifierName, dataType, this);
219 }
220
221 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530222 public void detectSelfCollision(String identifierName, YangConstructType dataType)
223 throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530224 if (getName().equals(identifierName)) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530225 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
Bharat saraswal96dfef02016-06-16 00:29:12 +0530226 + getName() + "\"");
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530227 }
228 }
229
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530232 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530233 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530234 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530235 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530236 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 return listOfLeaf;
238 }
239
240 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530241 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530242 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530243 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530244 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530245 @Override
246 public void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 listOfLeaf = leafsList;
248 }
249
250 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530251 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530252 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530253 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530254 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530255 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530256 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530257 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530258 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530259 }
260
261 getListOfLeaf().add(leaf);
262 }
263
264 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530265 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530267 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530268 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530269 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530270 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530271 return listOfLeafList;
272 }
273
274 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530275 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530276 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530277 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530279 @Override
280 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530281 this.listOfLeafList = listOfLeafList;
282 }
283
284 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530285 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530286 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530287 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530288 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530289 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530290 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530291 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530292 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530293 }
294
295 getListOfLeafList().add(leafList);
296 }
297
298 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530299 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530300 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530301 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530302 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530303 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530304 public String getReference() {
305 return reference;
306 }
307
308 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530309 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530310 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530311 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530312 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530313 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530314 public void setReference(String reference) {
315 this.reference = reference;
316 }
317
318 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530319 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530320 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530321 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530322 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530323 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530324 public YangStatusType getStatus() {
325 return status;
326 }
327
328 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530329 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530330 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530331 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530332 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530333 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530334 public void setStatus(YangStatusType status) {
335 this.status = status;
336 }
337
338 /**
339 * Returns the type of the data as belongs-to.
340 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530341 * @return returns AUGMENT_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530342 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530343 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530344 public YangConstructType getYangConstructType() {
345 return YangConstructType.AUGMENT_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530346 }
347
348 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530349 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530350 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530351 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530352 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530353 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530354 public void validateDataOnEntry()
355 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530356 // TODO auto-generated method stub, to be implemented by parser
357 }
358
359 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530360 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530361 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530362 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530363 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530364 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530365 public void validateDataOnExit()
366 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530367 // TODO auto-generated method stub, to be implemented by parser
368 }
369
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530370 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530371 * Returns the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530372 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530373 * @return target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530374 */
375 @Override
376 public String getName() {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530377 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530378 }
379
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530380 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530381 * Sets the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530382 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530383 * @param name target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530384 */
385 @Override
386 public void setName(String name) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530387 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530388 }
389
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530390 /**
391 * Returns augmented node.
392 *
393 * @return augmented node
394 */
395 public YangNode getAugmentedNode() {
396 return augmentedNode;
397 }
398
399 /**
400 * Sets augmented node.
401 *
402 * @param augmentedNode augmented node
403 */
404 public void setAugmentedNode(YangNode augmentedNode) {
405 this.augmentedNode = augmentedNode;
406 }
407
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530408 @Override
409 public List<YangIfFeature> getIfFeatureList() {
410 return ifFeatureList;
411 }
412
413 @Override
414 public void addIfFeatureList(YangIfFeature ifFeature) {
415 if (getIfFeatureList() == null) {
416 setIfFeatureList(new LinkedList<>());
417 }
418 getIfFeatureList().add(ifFeature);
419 }
420
421 @Override
422 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
423 this.ifFeatureList = ifFeatureList;
424 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530425
426 @Override
427 public ResolvableStatus getResolvableStatus() {
428 return resolvableStatus;
429 }
430
431 @Override
432 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
433 this.resolvableStatus = resolvableStatus;
434
435 }
436
437 @Override
438 public void resolve() throws DataModelException {
439 // Resolving of target node is being done in XPathLinker.
440 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530441}