blob: 6b76dfd77d1d8199f0d23e24ac49dd26e6c5ae80 [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;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053020import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053021import org.onosproject.yangutils.datamodel.utils.Parsable;
22import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
23import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053024
Vidyashree Rama07c26bb2016-07-28 17:33:15 +053025import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
26import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
27import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
28import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
janani b4e53f9b2016-04-26 18:49:20 +053029import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
Bharat saraswal96dfef02016-06-16 00:29:12 +053030import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
janani b23ccc312016-07-14 19:35:22 +053031import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf;
32import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList;
Vidyashree Rama07c26bb2016-07-28 17:33:15 +053033import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
Vinod Kumar S427d2932016-04-20 13:02:58 +053034
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053035/*-
36 * Reference RFC 6020.
37 *
38 * The "uses" statement is used to reference a "grouping" definition. It takes
39 * one argument, which is the name of the grouping.
40 *
41 * The effect of a "uses" reference to a grouping is that the nodes defined by
42 * the grouping are copied into the current schema tree, and then updated
43 * according to the "refine" and "augment" statements.
44 *
45 * The identifiers defined in the grouping are not bound to a namespace until
46 * the contents of the grouping are added to the schema tree via a "uses"
47 * statement that does not appear inside a "grouping" statement, at which point
48 * they are bound to the namespace of the current module.
49 *
50 * The uses's sub-statements
51 *
52 * +--------------+---------+-------------+------------------+
53 * | substatement | section | cardinality |data model mapping|
54 * +--------------+---------+-------------+------------------+
55 * | augment | 7.15 | 0..1 | -child nodes |
56 * | description | 7.19.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053057 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053058 * | refine | 7.12.2 | 0..1 | -TODO |
59 * | reference | 7.19.4 | 0..1 | -string |
60 * | status | 7.19.2 | 0..1 | -YangStatus |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053061 * | when | 7.19.5 | 0..1 | -YangWhen |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053062 * +--------------+---------+-------------+------------------+
63 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053064
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053065/**
Bharat saraswald9822e92016-04-05 15:13:44 +053066 * Represents data model node to maintain information defined in YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053067 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053068public class YangUses
69 extends YangNode
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053070 implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
71 YangIfFeatureHolder {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053072
Bharat saraswal96dfef02016-06-16 00:29:12 +053073 private static final long serialVersionUID = 806201617L;
74
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053075 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053076 * YANG node identifier.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053077 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053078 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079
80 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053081 * Referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053082 */
83 private YangGrouping refGroup;
84
85 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053086 * Description of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053087 */
88 private String description;
89
90 /**
91 * YANG reference.
92 */
93 private String reference;
94
95 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053096 * Status of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053097 */
98 private YangStatusType status;
99
100 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530101 * When data of the node.
102 */
103 private YangWhen when;
104
105 /**
106 * List of if-feature.
107 */
108 private List<YangIfFeature> ifFeatureList;
109
110 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530111 * Status of resolution. If completely resolved enum value is "RESOLVED",
112 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
113 * is added to uses/type but it's not resolved value of enum should be
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530114 * "INTRA_FILE_RESOLVED".
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530115 */
116 private ResolvableStatus resolvableStatus;
117
118 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530119 * Effective list of nodes of grouping that needs to replicated at YANG uses.
120 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530121 private List<YangNode> resolvedGroupingNodes;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530122
123 /**
124 * Effective list of leaves of grouping that needs to replicated at YANG uses.
125 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530126 private List<List<YangLeaf>> resolvedGroupingLeaves;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530127
128 /**
129 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
130 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530131 private List<List<YangLeafList>> resolvedGroupingLeafLists;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530132
133 /**
janani b23ccc312016-07-14 19:35:22 +0530134 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
135 */
136 private List<YangEntityToResolveInfoImpl> entityToResolveInfoList;
137
138 /**
139 * Current grouping depth for uses.
140 */
141 private int currentGroupingDepth;
142
143 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530144 * Creates an YANG uses node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530145 */
146 public YangUses() {
147 super(YangNodeType.USES_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530148 nodeIdentifier = new YangNodeIdentifier();
149 resolvableStatus = ResolvableStatus.UNRESOLVED;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530150 resolvedGroupingNodes = new LinkedList<YangNode>();
151 resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
152 resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530153 }
154
155 /**
janani b23ccc312016-07-14 19:35:22 +0530156 * Returns the list of entity to resolve.
157 *
158 * @return the list of entity to resolve
159 */
160 public List<YangEntityToResolveInfoImpl> getEntityToResolveInfoList() {
161 return entityToResolveInfoList;
162 }
163
164 /**
165 * Sets the list of entity to resolve.
166 *
167 * @param entityToResolveInfoList the list of entity to resolve
168 */
169 public void setEntityToResolveInfoList(List<YangEntityToResolveInfoImpl> entityToResolveInfoList) {
170 this.entityToResolveInfoList = entityToResolveInfoList;
171 }
172
173 /**
174 * Adds an entity to resolve in list.
175 *
176 * @param entityToResolve entity to resolved
177 * @throws DataModelException a violation of data model rules
178 */
179 public void addEntityToResolve(YangEntityToResolveInfoImpl entityToResolve)
180 throws DataModelException {
181 if (getEntityToResolveInfoList() == null) {
182 setEntityToResolveInfoList(new LinkedList<YangEntityToResolveInfoImpl>());
183 }
184 getEntityToResolveInfoList().add(entityToResolve);
185 }
186
187 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530188 * Returns the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530189 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530190 * @return the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 */
192 public YangGrouping getRefGroup() {
193 return refGroup;
194 }
195
196 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530197 * Sets the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530198 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530199 * @param refGroup the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530200 */
201 public void setRefGroup(YangGrouping refGroup) {
202 this.refGroup = refGroup;
203 }
204
205 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530206 * Returns the when.
207 *
208 * @return the when
209 */
210 @Override
211 public YangWhen getWhen() {
212 return when;
213 }
214
215 /**
216 * Sets the when.
217 *
218 * @param when the when to set
219 */
220 @Override
221 public void setWhen(YangWhen when) {
222 this.when = when;
223 }
224
225 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530226 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530227 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530228 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530230 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530231 public String getDescription() {
232 return description;
233 }
234
235 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530236 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530238 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530239 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530240 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530241 public void setDescription(String description) {
242 this.description = description;
243 }
244
245 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +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 saraswal594bc6d2016-02-22 22:15:21 +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 saraswal594bc6d2016-02-22 22:15:21 +0530260 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 public void setReference(String reference) {
262 this.reference = reference;
263 }
264
265 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +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 saraswal594bc6d2016-02-22 22:15:21 +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 saraswal594bc6d2016-02-22 22:15:21 +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.
287 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530288 * @return returns USES_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530289 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530290 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530291 public YangConstructType getYangConstructType() {
292 return YangConstructType.USES_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 saraswal594bc6d2016-02-22 22:15:21 +0530300 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530301 public void validateDataOnEntry()
302 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530303 // TODO auto-generated method stub, to be implemented by parser
304 }
305
306 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530307 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530308 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530309 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530310 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530311 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530312 public void validateDataOnExit()
313 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530314 // TODO auto-generated method stub, to be implemented by parser
315 }
316
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530317 @Override
318 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530319 return nodeIdentifier.getName();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530320 }
321
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530322 @Override
323 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530324 nodeIdentifier.setName(name);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530325 }
326
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530327 /**
328 * Returns node identifier.
329 *
330 * @return node identifier
331 */
332 public YangNodeIdentifier getNodeIdentifier() {
333 return nodeIdentifier;
334 }
335
336 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530337 * Sets node identifier.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530338 *
339 * @param nodeIdentifier the node identifier
340 */
341 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
342 this.nodeIdentifier = nodeIdentifier;
343 }
344
345 /**
346 * Returns prefix associated with uses.
347 *
348 * @return prefix associated with uses
349 */
350 public String getPrefix() {
351 return nodeIdentifier.getPrefix();
352 }
353
354 /**
355 * Get prefix associated with uses.
356 *
357 * @param prefix prefix associated with uses
358 */
359 public void setPrefix(String prefix) {
360 nodeIdentifier.setPrefix(prefix);
361 }
362
363 @Override
janani b23ccc312016-07-14 19:35:22 +0530364 public Object resolve()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530365 throws DataModelException {
Vinod Kumar S427d2932016-04-20 13:02:58 +0530366
367 YangGrouping referredGrouping = getRefGroup();
368
369 if (referredGrouping == null) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530370 throw new DataModelException("YANG uses linker error, cannot resolve uses");
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530371 } else {
372 /*
373 * if referredGrouping has uses which is not resolved then set the status
374 * as Intra file resolved and return
375 */
376 if (checkIsUnresolvedRecursiveUsesInGrouping(referredGrouping)) {
377 return null;
378 }
Vinod Kumar S427d2932016-04-20 13:02:58 +0530379 }
380
381 YangNode usesParentNode = getParentNodeInGenCode(this);
Bharat saraswalcad0e652016-05-26 23:48:38 +0530382 if (!(usesParentNode instanceof YangLeavesHolder)
383 || !(usesParentNode instanceof CollisionDetector)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530384 throw new DataModelException("YANG uses holder construct is wrong");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530385 }
386
387 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530388 if (referredGrouping.getListOfLeaf() != null) {
389 for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
390 YangLeaf clonedLeaf = null;
391 try {
392 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
393 YangConstructType.LEAF_DATA);
394 clonedLeaf = leaf.clone();
janani b23ccc312016-07-14 19:35:22 +0530395 if (getCurrentGroupingDepth() == 0) {
396 YangEntityToResolveInfoImpl resolveInfo = resolveLeafrefUnderGroupingForLeaf(clonedLeaf,
397 usesParentLeavesHolder, this);
398 if (resolveInfo != null) {
399 addEntityToResolve(resolveInfo);
400 }
401 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530402 } catch (CloneNotSupportedException | DataModelException e) {
403 throw new DataModelException(e.getMessage());
404 }
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530405
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530406 clonedLeaf.setContainedIn(usesParentLeavesHolder);
407 usesParentLeavesHolder.addLeaf(clonedLeaf);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530408 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530409 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530410 if (referredGrouping.getListOfLeafList() != null) {
411 for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
412 YangLeafList clonedLeafList = null;
413 try {
414 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
415 YangConstructType.LEAF_LIST_DATA);
416 clonedLeafList = leafList.clone();
janani b23ccc312016-07-14 19:35:22 +0530417 if (getCurrentGroupingDepth() == 0) {
418 YangEntityToResolveInfoImpl resolveInfo =
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530419 resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
janani b23ccc312016-07-14 19:35:22 +0530420 if (resolveInfo != null) {
421 addEntityToResolve(resolveInfo);
422 }
423 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530424 } catch (CloneNotSupportedException | DataModelException e) {
425 throw new DataModelException(e.getMessage());
426 }
427
428 clonedLeafList.setContainedIn(usesParentLeavesHolder);
429 usesParentLeavesHolder.addLeafList(clonedLeafList);
430 }
431 }
432
433 try {
janani b23ccc312016-07-14 19:35:22 +0530434 YangNode.cloneSubTree(referredGrouping, usesParentNode, this);
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530435 } catch (DataModelException e) {
436 throw new DataModelException(e.getMessage());
437 }
438 updateClonedLeavesUnionEnumRef(usesParentLeavesHolder);
janani b23ccc312016-07-14 19:35:22 +0530439 return getEntityToResolveInfoList();
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530440 }
441
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530442 /**
Vidyashree Rama07c26bb2016-07-28 17:33:15 +0530443 * Checks if referred grouping has uses which is not resolved then it set the
444 * status of current uses as intra file resolved and returns true.
445 *
446 * @param referredGrouping referred grouping node of uses
447 * @return true if referred grouping has unresolved uses
448 */
449 private boolean checkIsUnresolvedRecursiveUsesInGrouping(YangGrouping referredGrouping) {
450
451 /**
452 * Search the grouping node's children for presence of uses node.
453 */
454 TraversalType curTraversal = ROOT;
455 YangNode curNode = referredGrouping.getChild();
456 while (curNode != null) {
457 if (curNode.getName().equals(referredGrouping.getName())) {
458 // if we have traversed all the child nodes, then exit from loop
459 return false;
460 }
461
462 // if child nodes has uses, then add it to resolution stack
463 if (curNode instanceof YangUses) {
464 if (((YangUses) curNode).getResolvableStatus() != ResolvableStatus.RESOLVED) {
465 setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
466 return true;
467 }
468 }
469
470 // Traversing all the child nodes of grouping
471 if (curTraversal != PARENT && curNode.getChild() != null) {
472 curTraversal = CHILD;
473 curNode = curNode.getChild();
474 } else if (curNode.getNextSibling() != null) {
475 curTraversal = SIBILING;
476 curNode = curNode.getNextSibling();
477 } else {
478 curTraversal = PARENT;
479 curNode = curNode.getParent();
480 }
481 }
482 return false;
483 }
484
485 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530486 * Clone the resolved uses contained in grouping to the uses of grouping.
487 *
488 * @param usesInGrouping resolved uses in grouping
489 * @param usesHolder holder of uses
490 */
491 private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
janani b23ccc312016-07-14 19:35:22 +0530492 YangLeavesHolder usesHolder) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530493 for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530494 addNodeOfGrouping(usesResolvedNode);
495 }
496
Bharat saraswal96dfef02016-06-16 00:29:12 +0530497 for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530498 addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
499 }
500
Bharat saraswal96dfef02016-06-16 00:29:12 +0530501 for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530502 addListOfLeafListOfGrouping(
503 cloneListOfLeafList(listOfLeafLists, usesHolder));
504 }
505 }
506
507 /**
508 * Clone the list of leaves and return the cloned list leaves.
509 *
510 * @param listOfLeaves list of leaves to be cloned
511 * @param usesParentNode parent of the cloned location
512 * @return cloned list of leaves
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530513 * @throws DataModelException a violation in data model rule
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530514 */
515 private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
janani b23ccc312016-07-14 19:35:22 +0530516 YangLeavesHolder usesParentNode) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530517 if (listOfLeaves == null || listOfLeaves.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530518 throw new DataModelException("No leaves to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530519 }
520
521 List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
522 for (YangLeaf leaf : listOfLeaves) {
523 YangLeaf clonedLeaf;
524 try {
525 ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
526 YangConstructType.LEAF_DATA);
527 clonedLeaf = leaf.clone();
528 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530529 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530530 }
531
532 clonedLeaf.setContainedIn(usesParentNode);
533 newLeavesList.add(clonedLeaf);
534 }
535
536 return newLeavesList;
537 }
538
539 /**
540 * Clone the list of leaf list.
541 *
542 * @param listOfLeafList list of leaf list that needs to be cloned
543 * @param usesParentNode parent of uses
544 * @return cloned list of leaf list
545 */
546 private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
janani b23ccc312016-07-14 19:35:22 +0530547 YangLeavesHolder usesParentNode) throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530548 if (listOfLeafList == null || listOfLeafList.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530549 throw new DataModelException("No leaf lists to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530550 }
551
552 List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
553 for (YangLeafList leafList : listOfLeafList) {
554 YangLeafList clonedLeafList;
555 try {
556 ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
557 YangConstructType.LEAF_LIST_DATA);
558 clonedLeafList = leafList.clone();
559 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530560 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530561 }
562
563 clonedLeafList.setContainedIn(usesParentNode);
564 newListOfLeafList.add(clonedLeafList);
565 }
566
567 return newListOfLeafList;
568 }
569
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530570 @Override
571 public ResolvableStatus getResolvableStatus() {
572 return resolvableStatus;
573 }
574
575 @Override
576 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
577 this.resolvableStatus = resolvableStatus;
578 }
janani b4e53f9b2016-04-26 18:49:20 +0530579
580 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530581 public void detectCollidingChild(String identifierName, YangConstructType dataType)
582 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530583 detectCollidingChildUtil(identifierName, dataType, this);
584 }
585
586 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530587 public void detectSelfCollision(String identifierName, YangConstructType dataType)
588 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530589
590 if (getName().equals(identifierName)) {
591 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
592 + getName() + "\"");
593 }
594 }
595
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530596 /**
597 * Adds the node under grouping to the effective uses resolved info.
598 *
599 * @param nodeInGrouping node defined under grouping which needs to be copied in
600 * the context of uses
601 */
602 public void addNodeOfGrouping(YangNode nodeInGrouping) {
603 resolvedGroupingNodes.add(nodeInGrouping);
604 }
605
606 /**
607 * Returns the effective list of nodes added due to uses linking.
608 *
609 * @return effective list of nodes added due to uses linking
610 */
611 public List<YangNode> getUsesResolvedNodeList() {
612 return resolvedGroupingNodes;
613 }
614
615 /**
616 * Adds the leaves under grouping to the effective uses resolved info.
617 *
618 * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
619 * the context of uses
620 */
621 public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
622 resolvedGroupingLeaves.add(leavesInGrouping);
623 }
624
625 /**
626 * Returns the effective list of Leaves added due to uses linking.
627 *
628 * @return effective list of Leaves added due to uses linking
629 */
630 public List<List<YangLeaf>> getUsesResolvedLeavesList() {
631 return resolvedGroupingLeaves;
632 }
633
634 /**
635 * Adds the leaf-lists under grouping to the effective uses resolved info.
636 *
637 * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
638 * the context of uses
639 */
640 public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
641 resolvedGroupingLeafLists.add(leafListsInGrouping);
642 }
643
644 /**
645 * Returns the effective list of Leaves added due to uses linking.
646 *
647 * @return effective list of Leaves added due to uses linking
648 */
649 public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
650 return resolvedGroupingLeafLists;
651 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530652
653 @Override
654 public List<YangIfFeature> getIfFeatureList() {
655 return ifFeatureList;
656 }
657
658 @Override
659 public void addIfFeatureList(YangIfFeature ifFeature) {
660 if (getIfFeatureList() == null) {
661 setIfFeatureList(new LinkedList<>());
662 }
663 getIfFeatureList().add(ifFeature);
664 }
665
666 @Override
667 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
668 this.ifFeatureList = ifFeatureList;
669 }
janani b23ccc312016-07-14 19:35:22 +0530670
671 public void setCurrentGroupingDepth(int currentGroupingDepth) {
672 this.currentGroupingDepth = currentGroupingDepth;
673 }
674
675 public int getCurrentGroupingDepth() {
676 return currentGroupingDepth;
677 }
678
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530679}