blob: 5cd1e7a974a57107903b22fbe2389bf909552f47 [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
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053018import java.util.LinkedList;
19import java.util.List;
Bharat saraswal96dfef02016-06-16 00:29:12 +053020
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053021import 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.ResolvableStatus;
24import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
janani b4e53f9b2016-04-26 18:49:20 +053026import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Bharat saraswal96dfef02016-06-16 00:29:12 +053027import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vidyashree Rama405d2e62016-07-08 20:45:41 +053028import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
janani b23ccc312016-07-14 19:35:22 +053029import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf;
30import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList;
Vinod Kumar S427d2932016-04-20 13:02:58 +053031
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053032/*-
33 * Reference RFC 6020.
34 *
35 * The "uses" statement is used to reference a "grouping" definition. It takes
36 * one argument, which is the name of the grouping.
37 *
38 * The effect of a "uses" reference to a grouping is that the nodes defined by
39 * the grouping are copied into the current schema tree, and then updated
40 * according to the "refine" and "augment" statements.
41 *
42 * The identifiers defined in the grouping are not bound to a namespace until
43 * the contents of the grouping are added to the schema tree via a "uses"
44 * statement that does not appear inside a "grouping" statement, at which point
45 * they are bound to the namespace of the current module.
46 *
47 * The uses's sub-statements
48 *
49 * +--------------+---------+-------------+------------------+
50 * | substatement | section | cardinality |data model mapping|
51 * +--------------+---------+-------------+------------------+
52 * | augment | 7.15 | 0..1 | -child nodes |
53 * | description | 7.19.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053054 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053055 * | refine | 7.12.2 | 0..1 | -TODO |
56 * | reference | 7.19.4 | 0..1 | -string |
57 * | status | 7.19.2 | 0..1 | -YangStatus |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053058 * | when | 7.19.5 | 0..1 | -YangWhen |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053059 * +--------------+---------+-------------+------------------+
60 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053061
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053062/**
Bharat saraswald9822e92016-04-05 15:13:44 +053063 * Represents data model node to maintain information defined in YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053064 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053065public class YangUses
66 extends YangNode
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053067 implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
68 YangIfFeatureHolder {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053069
Bharat saraswal96dfef02016-06-16 00:29:12 +053070 private static final long serialVersionUID = 806201617L;
71
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053072 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053073 * YANG node identifier.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053074 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053075 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053076
77 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053078 * Referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079 */
80 private YangGrouping refGroup;
81
82 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053083 * Description of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053084 */
85 private String description;
86
87 /**
88 * YANG reference.
89 */
90 private String reference;
91
92 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053093 * Status of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094 */
95 private YangStatusType status;
96
97 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053098 * When data of the node.
99 */
100 private YangWhen when;
101
102 /**
103 * List of if-feature.
104 */
105 private List<YangIfFeature> ifFeatureList;
106
107 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530108 * Status of resolution. If completely resolved enum value is "RESOLVED",
109 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
110 * is added to uses/type but it's not resolved value of enum should be
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530111 * "INTRA_FILE_RESOLVED".
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530112 */
113 private ResolvableStatus resolvableStatus;
114
115 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530116 * Effective list of nodes of grouping that needs to replicated at YANG uses.
117 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530118 private List<YangNode> resolvedGroupingNodes;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530119
120 /**
121 * Effective list of leaves of grouping that needs to replicated at YANG uses.
122 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530123 private List<List<YangLeaf>> resolvedGroupingLeaves;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530124
125 /**
126 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
127 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530128 private List<List<YangLeafList>> resolvedGroupingLeafLists;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530129
130 /**
janani b23ccc312016-07-14 19:35:22 +0530131 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
132 */
133 private List<YangEntityToResolveInfoImpl> entityToResolveInfoList;
134
135 /**
136 * Current grouping depth for uses.
137 */
138 private int currentGroupingDepth;
139
140 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530141 * Creates an YANG uses node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530142 */
143 public YangUses() {
144 super(YangNodeType.USES_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530145 nodeIdentifier = new YangNodeIdentifier();
146 resolvableStatus = ResolvableStatus.UNRESOLVED;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530147 resolvedGroupingNodes = new LinkedList<YangNode>();
148 resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
149 resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 }
151
152 /**
janani b23ccc312016-07-14 19:35:22 +0530153 * Returns the list of entity to resolve.
154 *
155 * @return the list of entity to resolve
156 */
157 public List<YangEntityToResolveInfoImpl> getEntityToResolveInfoList() {
158 return entityToResolveInfoList;
159 }
160
161 /**
162 * Sets the list of entity to resolve.
163 *
164 * @param entityToResolveInfoList the list of entity to resolve
165 */
166 public void setEntityToResolveInfoList(List<YangEntityToResolveInfoImpl> entityToResolveInfoList) {
167 this.entityToResolveInfoList = entityToResolveInfoList;
168 }
169
170 /**
171 * Adds an entity to resolve in list.
172 *
173 * @param entityToResolve entity to resolved
174 * @throws DataModelException a violation of data model rules
175 */
176 public void addEntityToResolve(YangEntityToResolveInfoImpl entityToResolve)
177 throws DataModelException {
178 if (getEntityToResolveInfoList() == null) {
179 setEntityToResolveInfoList(new LinkedList<YangEntityToResolveInfoImpl>());
180 }
181 getEntityToResolveInfoList().add(entityToResolve);
182 }
183
184 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530185 * Returns the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530186 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530187 * @return the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530188 */
189 public YangGrouping getRefGroup() {
190 return refGroup;
191 }
192
193 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530194 * Sets the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530195 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530196 * @param refGroup the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 */
198 public void setRefGroup(YangGrouping refGroup) {
199 this.refGroup = refGroup;
200 }
201
202 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530203 * Returns the when.
204 *
205 * @return the when
206 */
207 @Override
208 public YangWhen getWhen() {
209 return when;
210 }
211
212 /**
213 * Sets the when.
214 *
215 * @param when the when to set
216 */
217 @Override
218 public void setWhen(YangWhen when) {
219 this.when = when;
220 }
221
222 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530223 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530224 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530225 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530227 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530228 public String getDescription() {
229 return description;
230 }
231
232 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530233 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530234 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530235 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530236 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530237 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530238 public void setDescription(String description) {
239 this.description = description;
240 }
241
242 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530243 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530244 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530245 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530246 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530247 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530248 public String getReference() {
249 return reference;
250 }
251
252 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530253 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530254 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530255 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530256 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530257 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530258 public void setReference(String reference) {
259 this.reference = reference;
260 }
261
262 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530263 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530264 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530265 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530267 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530268 public YangStatusType getStatus() {
269 return status;
270 }
271
272 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530273 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530275 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530276 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530277 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 public void setStatus(YangStatusType status) {
279 this.status = status;
280 }
281
282 /**
283 * Returns the type of the data.
284 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530285 * @return returns USES_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530286 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530287 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530288 public YangConstructType getYangConstructType() {
289 return YangConstructType.USES_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530290 }
291
292 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530293 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530294 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530295 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530296 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530297 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530298 public void validateDataOnEntry()
299 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530300 // TODO auto-generated method stub, to be implemented by parser
301 }
302
303 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530304 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530305 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530306 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530307 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530308 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530309 public void validateDataOnExit()
310 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530311 // TODO auto-generated method stub, to be implemented by parser
312 }
313
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530314 @Override
315 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530316 return nodeIdentifier.getName();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530317 }
318
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530319 @Override
320 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530321 nodeIdentifier.setName(name);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530322 }
323
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530324 /**
325 * Returns node identifier.
326 *
327 * @return node identifier
328 */
329 public YangNodeIdentifier getNodeIdentifier() {
330 return nodeIdentifier;
331 }
332
333 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530334 * Sets node identifier.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530335 *
336 * @param nodeIdentifier the node identifier
337 */
338 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
339 this.nodeIdentifier = nodeIdentifier;
340 }
341
342 /**
343 * Returns prefix associated with uses.
344 *
345 * @return prefix associated with uses
346 */
347 public String getPrefix() {
348 return nodeIdentifier.getPrefix();
349 }
350
351 /**
352 * Get prefix associated with uses.
353 *
354 * @param prefix prefix associated with uses
355 */
356 public void setPrefix(String prefix) {
357 nodeIdentifier.setPrefix(prefix);
358 }
359
360 @Override
janani b23ccc312016-07-14 19:35:22 +0530361 public Object resolve()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530362 throws DataModelException {
Vinod Kumar S427d2932016-04-20 13:02:58 +0530363
364 YangGrouping referredGrouping = getRefGroup();
365
366 if (referredGrouping == null) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530367 throw new DataModelException("YANG uses linker error, cannot resolve uses");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530368 }
369
370 YangNode usesParentNode = getParentNodeInGenCode(this);
Bharat saraswalcad0e652016-05-26 23:48:38 +0530371 if (!(usesParentNode instanceof YangLeavesHolder)
372 || !(usesParentNode instanceof CollisionDetector)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530373 throw new DataModelException("YANG uses holder construct is wrong");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530374 }
375
376 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530377 if (referredGrouping.getListOfLeaf() != null) {
378 for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
379 YangLeaf clonedLeaf = null;
380 try {
381 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
382 YangConstructType.LEAF_DATA);
383 clonedLeaf = leaf.clone();
janani b23ccc312016-07-14 19:35:22 +0530384 if (getCurrentGroupingDepth() == 0) {
385 YangEntityToResolveInfoImpl resolveInfo = resolveLeafrefUnderGroupingForLeaf(clonedLeaf,
386 usesParentLeavesHolder, this);
387 if (resolveInfo != null) {
388 addEntityToResolve(resolveInfo);
389 }
390 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530391 } catch (CloneNotSupportedException | DataModelException e) {
392 throw new DataModelException(e.getMessage());
393 }
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530394
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530395 clonedLeaf.setContainedIn(usesParentLeavesHolder);
396 usesParentLeavesHolder.addLeaf(clonedLeaf);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530397 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530398 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530399 if (referredGrouping.getListOfLeafList() != null) {
400 for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
401 YangLeafList clonedLeafList = null;
402 try {
403 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
404 YangConstructType.LEAF_LIST_DATA);
405 clonedLeafList = leafList.clone();
janani b23ccc312016-07-14 19:35:22 +0530406 if (getCurrentGroupingDepth() == 0) {
407 YangEntityToResolveInfoImpl resolveInfo =
408 resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
409 if (resolveInfo != null) {
410 addEntityToResolve(resolveInfo);
411 }
412 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530413 } catch (CloneNotSupportedException | DataModelException e) {
414 throw new DataModelException(e.getMessage());
415 }
416
417 clonedLeafList.setContainedIn(usesParentLeavesHolder);
418 usesParentLeavesHolder.addLeafList(clonedLeafList);
419 }
420 }
421
422 try {
janani b23ccc312016-07-14 19:35:22 +0530423 YangNode.cloneSubTree(referredGrouping, usesParentNode, this);
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530424 } catch (DataModelException e) {
425 throw new DataModelException(e.getMessage());
426 }
427 updateClonedLeavesUnionEnumRef(usesParentLeavesHolder);
janani b23ccc312016-07-14 19:35:22 +0530428 return getEntityToResolveInfoList();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530429 }
430
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530431 /**
432 * Clone the resolved uses contained in grouping to the uses of grouping.
433 *
434 * @param usesInGrouping resolved uses in grouping
435 * @param usesHolder holder of uses
436 */
437 private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
janani b23ccc312016-07-14 19:35:22 +0530438 YangLeavesHolder usesHolder) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530439 for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530440 addNodeOfGrouping(usesResolvedNode);
441 }
442
Bharat saraswal96dfef02016-06-16 00:29:12 +0530443 for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530444 addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
445 }
446
Bharat saraswal96dfef02016-06-16 00:29:12 +0530447 for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530448 addListOfLeafListOfGrouping(
449 cloneListOfLeafList(listOfLeafLists, usesHolder));
450 }
451 }
452
453 /**
454 * Clone the list of leaves and return the cloned list leaves.
455 *
456 * @param listOfLeaves list of leaves to be cloned
457 * @param usesParentNode parent of the cloned location
458 * @return cloned list of leaves
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530459 * @throws DataModelException a violation in data model rule
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530460 */
461 private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
janani b23ccc312016-07-14 19:35:22 +0530462 YangLeavesHolder usesParentNode) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530463 if (listOfLeaves == null || listOfLeaves.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530464 throw new DataModelException("No leaves to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530465 }
466
467 List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
468 for (YangLeaf leaf : listOfLeaves) {
469 YangLeaf clonedLeaf;
470 try {
471 ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
472 YangConstructType.LEAF_DATA);
473 clonedLeaf = leaf.clone();
474 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530475 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530476 }
477
478 clonedLeaf.setContainedIn(usesParentNode);
479 newLeavesList.add(clonedLeaf);
480 }
481
482 return newLeavesList;
483 }
484
485 /**
486 * Clone the list of leaf list.
487 *
488 * @param listOfLeafList list of leaf list that needs to be cloned
489 * @param usesParentNode parent of uses
490 * @return cloned list of leaf list
491 */
492 private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
janani b23ccc312016-07-14 19:35:22 +0530493 YangLeavesHolder usesParentNode) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530494 if (listOfLeafList == null || listOfLeafList.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530495 throw new DataModelException("No leaf lists to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530496 }
497
498 List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
499 for (YangLeafList leafList : listOfLeafList) {
500 YangLeafList clonedLeafList;
501 try {
502 ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
503 YangConstructType.LEAF_LIST_DATA);
504 clonedLeafList = leafList.clone();
505 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530506 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530507 }
508
509 clonedLeafList.setContainedIn(usesParentNode);
510 newListOfLeafList.add(clonedLeafList);
511 }
512
513 return newListOfLeafList;
514 }
515
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530516 @Override
517 public ResolvableStatus getResolvableStatus() {
518 return resolvableStatus;
519 }
520
521 @Override
522 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
523 this.resolvableStatus = resolvableStatus;
524 }
janani b4e53f9b2016-04-26 18:49:20 +0530525
526 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530527 public void detectCollidingChild(String identifierName, YangConstructType dataType)
528 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530529 detectCollidingChildUtil(identifierName, dataType, this);
530 }
531
532 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530533 public void detectSelfCollision(String identifierName, YangConstructType dataType)
534 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530535
536 if (getName().equals(identifierName)) {
537 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
538 + getName() + "\"");
539 }
540 }
541
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530542 /**
543 * Adds the node under grouping to the effective uses resolved info.
544 *
545 * @param nodeInGrouping node defined under grouping which needs to be copied in
546 * the context of uses
547 */
548 public void addNodeOfGrouping(YangNode nodeInGrouping) {
549 resolvedGroupingNodes.add(nodeInGrouping);
550 }
551
552 /**
553 * Returns the effective list of nodes added due to uses linking.
554 *
555 * @return effective list of nodes added due to uses linking
556 */
557 public List<YangNode> getUsesResolvedNodeList() {
558 return resolvedGroupingNodes;
559 }
560
561 /**
562 * Adds the leaves under grouping to the effective uses resolved info.
563 *
564 * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
565 * the context of uses
566 */
567 public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
568 resolvedGroupingLeaves.add(leavesInGrouping);
569 }
570
571 /**
572 * Returns the effective list of Leaves added due to uses linking.
573 *
574 * @return effective list of Leaves added due to uses linking
575 */
576 public List<List<YangLeaf>> getUsesResolvedLeavesList() {
577 return resolvedGroupingLeaves;
578 }
579
580 /**
581 * Adds the leaf-lists under grouping to the effective uses resolved info.
582 *
583 * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
584 * the context of uses
585 */
586 public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
587 resolvedGroupingLeafLists.add(leafListsInGrouping);
588 }
589
590 /**
591 * Returns the effective list of Leaves added due to uses linking.
592 *
593 * @return effective list of Leaves added due to uses linking
594 */
595 public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
596 return resolvedGroupingLeafLists;
597 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530598
599 @Override
600 public List<YangIfFeature> getIfFeatureList() {
601 return ifFeatureList;
602 }
603
604 @Override
605 public void addIfFeatureList(YangIfFeature ifFeature) {
606 if (getIfFeatureList() == null) {
607 setIfFeatureList(new LinkedList<>());
608 }
609 getIfFeatureList().add(ifFeature);
610 }
611
612 @Override
613 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
614 this.ifFeatureList = ifFeatureList;
615 }
janani b23ccc312016-07-14 19:35:22 +0530616
617 public void setCurrentGroupingDepth(int currentGroupingDepth) {
618 this.currentGroupingDepth = currentGroupingDepth;
619 }
620
621 public int getCurrentGroupingDepth() {
622 return currentGroupingDepth;
623 }
624
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530625}