blob: adac64034e3cb7634a005c3fa4dc82486ffceffc [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;
22import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053023import org.onosproject.yangutils.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 */
Vinod Kumar S38046502016-03-23 15:30:27 +053082public class YangAugment extends YangNode
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053083 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053084
85 /**
86 * Augment target node.
87 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053088 private String name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053089
90 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053091 * Description of augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092 */
93 private String description;
94
95 /**
96 * List of leaves.
97 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053098 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053099
100 /**
101 * List of leaf-lists.
102 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530103 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530104
105 /**
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530106 * List of node identifiers.
107 */
108 private List<YangNodeIdentifier> targetNode;
109
110 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530111 * Reference of the YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530112 */
113 private String reference;
114
115 /**
116 * Status of the node.
117 */
118 private YangStatusType status;
119
120 /**
121 * Create a YANG augment node.
122 */
123 public YangAugment() {
124 super(YangNodeType.AUGMENT_NODE);
125 }
126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Returns the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530130 * @return the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530131 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530132 public List<YangNodeIdentifier> getTargetNode() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530133 return targetNode;
134 }
135
136 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530137 * Sets the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 *
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530139 * @param nodeIdentifiers the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530140 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530141 public void setTargetNode(List<YangNodeIdentifier> nodeIdentifiers) {
142 this.targetNode = nodeIdentifiers;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143 }
144
145 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530146 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530147 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530148 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530150 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530151 public String getDescription() {
152 return description;
153 }
154
155 /**
156 * Set the description.
157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530159 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530160 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530161 public void setDescription(String description) {
162 this.description = description;
163 }
164
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530165 @Override
166 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
167 // Detect colliding child.
168 detectCollidingChildUtil(identifierName, dataType, this);
169 }
170
171 @Override
172 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
173 if (this.getName().equals(identifierName)) {
174 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
175 + this.getName() + "\"");
176 }
177 }
178
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530180 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530181 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530182 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530183 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530184 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530185 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530186 return listOfLeaf;
187 }
188
189 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530190 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530192 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530193 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530194 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530195 listOfLeaf = leafsList;
196 }
197
198 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530199 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530200 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530201 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530202 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530203 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530204 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530205 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530206 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530207 }
208
209 getListOfLeaf().add(leaf);
210 }
211
212 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530213 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530215 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530216 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530217 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530218 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 return listOfLeafList;
220 }
221
222 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530223 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530224 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530225 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530227 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530228 this.listOfLeafList = listOfLeafList;
229 }
230
231 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530232 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530233 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530234 * @param leafList the leaf-list to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530235 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530236 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530237 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530238 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530239 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240 }
241
242 getListOfLeafList().add(leafList);
243 }
244
245 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530246 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530247 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530248 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530249 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530250 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530251 public String getReference() {
252 return reference;
253 }
254
255 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530256 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530257 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530258 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530259 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530260 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 public void setReference(String reference) {
262 this.reference = reference;
263 }
264
265 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530266 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530267 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530268 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530271 public YangStatusType getStatus() {
272 return status;
273 }
274
275 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530276 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530277 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530278 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530279 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530280 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530281 public void setStatus(YangStatusType status) {
282 this.status = status;
283 }
284
285 /**
286 * Returns the type of the data as belongs-to.
287 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530288 * @return returns AUGMENT_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530289 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530290 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530291 public YangConstructType getYangConstructType() {
292 return YangConstructType.AUGMENT_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530293 }
294
295 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530296 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530297 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530298 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530299 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530300 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530301 public void validateDataOnEntry() throws DataModelException {
302 // TODO auto-generated method stub, to be implemented by parser
303 }
304
305 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530306 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530307 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530308 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530309 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530310 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530311 public void validateDataOnExit() throws DataModelException {
312 // TODO auto-generated method stub, to be implemented by parser
313 }
314
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530315 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530316 * Returns the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530317 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530318 * @return target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530319 */
320 @Override
321 public String getName() {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530322 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530323 }
324
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530325 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530326 * Sets the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530327 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530328 * @param name target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530329 */
330 @Override
331 public void setName(String name) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530332 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530333 }
334
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530335}