blob: 374e2ab1beb32395a5d0ef9bfa70db971ed52c3e [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 */
78/**
Bharat saraswald9822e92016-04-05 15:13:44 +053079 * Representation of data model node to maintain information defined in YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053080 */
Vinod Kumar S38046502016-03-23 15:30:27 +053081public class YangAugment extends YangNode
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053082 implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053083
84 /**
85 * Augment target node.
86 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053087 private String name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053088
89 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053090 * Description of augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053091 */
92 private String description;
93
94 /**
95 * List of leaves.
96 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053097 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053098
99 /**
100 * List of leaf-lists.
101 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530102 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103
104 /**
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530105 * List of node identifiers.
106 */
107 private List<YangNodeIdentifier> targetNode;
108
109 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530110 * Reference of the YANG augment.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111 */
112 private String reference;
113
114 /**
115 * Status of the node.
116 */
117 private YangStatusType status;
118
119 /**
120 * Create a YANG augment node.
121 */
122 public YangAugment() {
123 super(YangNodeType.AUGMENT_NODE);
124 }
125
126 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Returns the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530129 * @return the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530131 public List<YangNodeIdentifier> getTargetNode() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530132 return targetNode;
133 }
134
135 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Sets the augmented node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530137 *
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530138 * @param nodeIdentifiers the augmented node
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530139 */
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530140 public void setTargetNode(List<YangNodeIdentifier> nodeIdentifiers) {
141 this.targetNode = nodeIdentifiers;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530142 }
143
144 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530145 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530146 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530147 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530148 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530149 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 public String getDescription() {
151 return description;
152 }
153
154 /**
155 * Set the description.
156 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530157 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530159 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 public void setDescription(String description) {
161 this.description = description;
162 }
163
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530164 @Override
165 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
166 // Detect colliding child.
167 detectCollidingChildUtil(identifierName, dataType, this);
168 }
169
170 @Override
171 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
172 if (this.getName().equals(identifierName)) {
173 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
174 + this.getName() + "\"");
175 }
176 }
177
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530178 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530179 * Returns the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530180 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530181 * @return the list of leaves
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530182 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530183 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530184 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530185 return listOfLeaf;
186 }
187
188 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530189 * Sets the list of leaves.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530190 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530191 * @param leafsList the list of leaf to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530193 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530194 listOfLeaf = leafsList;
195 }
196
197 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530198 * Adds a leaf.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530199 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530200 * @param leaf the leaf to be added
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530202 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530203 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530204 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530205 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530206 }
207
208 getListOfLeaf().add(leaf);
209 }
210
211 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530212 * Returns the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530214 * @return the list of leaf-list
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530215 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530216 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530217 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530218 return listOfLeafList;
219 }
220
221 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530222 * Sets the list of leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530223 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530224 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530226 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530227 this.listOfLeafList = listOfLeafList;
228 }
229
230 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530231 * Adds a leaf-list.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530232 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530233 * @param leafList the leaf-list to be added
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 void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530238 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530239 }
240
241 getListOfLeafList().add(leafList);
242 }
243
244 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530245 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530246 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530247 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530248 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530249 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530250 public String getReference() {
251 return reference;
252 }
253
254 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530255 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530256 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530257 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530258 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530259 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530260 public void setReference(String reference) {
261 this.reference = reference;
262 }
263
264 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530265 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530267 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530268 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530269 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530270 public YangStatusType getStatus() {
271 return status;
272 }
273
274 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530275 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530276 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530277 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530279 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530280 public void setStatus(YangStatusType status) {
281 this.status = status;
282 }
283
284 /**
285 * Returns the type of the data as belongs-to.
286 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530287 * @return returns AUGMENT_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530288 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530289 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530290 public YangConstructType getYangConstructType() {
291 return YangConstructType.AUGMENT_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530292 }
293
294 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530295 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530296 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530297 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530298 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530299 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530300 public void validateDataOnEntry() throws DataModelException {
301 // TODO auto-generated method stub, to be implemented by parser
302 }
303
304 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530305 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530306 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530307 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530308 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530309 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530310 public void validateDataOnExit() throws DataModelException {
311 // TODO auto-generated method stub, to be implemented by parser
312 }
313
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530314 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530315 * Returns the target nodes name where the augmentation is being done.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530316 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530317 * @return target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530318 */
319 @Override
320 public String getName() {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530321 return name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530322 }
323
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530324 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530325 * Sets 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 * @param name target nodes name where the augmentation is being done
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530328 */
329 @Override
330 public void setName(String name) {
Vidyashree Rama25bf4d02016-03-29 14:37:02 +0530331 this.name = name;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530332 }
333
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530334}