blob: 6f7137dd15fec76b4e217d41e2a480f92fd89882 [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;
Vinod Kumar S427d2932016-04-20 13:02:58 +053028
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053029/*-
30 * Reference RFC 6020.
31 *
32 * The "uses" statement is used to reference a "grouping" definition. It takes
33 * one argument, which is the name of the grouping.
34 *
35 * The effect of a "uses" reference to a grouping is that the nodes defined by
36 * the grouping are copied into the current schema tree, and then updated
37 * according to the "refine" and "augment" statements.
38 *
39 * The identifiers defined in the grouping are not bound to a namespace until
40 * the contents of the grouping are added to the schema tree via a "uses"
41 * statement that does not appear inside a "grouping" statement, at which point
42 * they are bound to the namespace of the current module.
43 *
44 * The uses's sub-statements
45 *
46 * +--------------+---------+-------------+------------------+
47 * | substatement | section | cardinality |data model mapping|
48 * +--------------+---------+-------------+------------------+
49 * | augment | 7.15 | 0..1 | -child nodes |
50 * | description | 7.19.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053051 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053052 * | refine | 7.12.2 | 0..1 | -TODO |
53 * | reference | 7.19.4 | 0..1 | -string |
54 * | status | 7.19.2 | 0..1 | -YangStatus |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053055 * | when | 7.19.5 | 0..1 | -YangWhen |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056 * +--------------+---------+-------------+------------------+
57 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053058
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053059/**
Bharat saraswald9822e92016-04-05 15:13:44 +053060 * Represents data model node to maintain information defined in YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053061 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053062public class YangUses
63 extends YangNode
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053064 implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
65 YangIfFeatureHolder {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053066
Bharat saraswal96dfef02016-06-16 00:29:12 +053067 private static final long serialVersionUID = 806201617L;
68
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053069 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053070 * YANG node identifier.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053071 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053072 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053073
74 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053075 * Referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053076 */
77 private YangGrouping refGroup;
78
79 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053080 * Description of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053081 */
82 private String description;
83
84 /**
85 * YANG reference.
86 */
87 private String reference;
88
89 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053090 * Status of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053091 */
92 private YangStatusType status;
93
94 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053095 * When data of the node.
96 */
97 private YangWhen when;
98
99 /**
100 * List of if-feature.
101 */
102 private List<YangIfFeature> ifFeatureList;
103
104 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530105 * Status of resolution. If completely resolved enum value is "RESOLVED",
106 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
107 * is added to uses/type but it's not resolved value of enum should be
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530108 * "INTRA_FILE_RESOLVED".
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530109 */
110 private ResolvableStatus resolvableStatus;
111
112 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530113 * Effective list of nodes of grouping that needs to replicated at YANG uses.
114 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530115 private List<YangNode> resolvedGroupingNodes;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530116
117 /**
118 * Effective list of leaves of grouping that needs to replicated at YANG uses.
119 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530120 private List<List<YangLeaf>> resolvedGroupingLeaves;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530121
122 /**
123 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
124 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530125 private List<List<YangLeafList>> resolvedGroupingLeafLists;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Creates an YANG uses node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 */
130 public YangUses() {
131 super(YangNodeType.USES_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530132 nodeIdentifier = new YangNodeIdentifier();
133 resolvableStatus = ResolvableStatus.UNRESOLVED;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530134 resolvedGroupingNodes = new LinkedList<YangNode>();
135 resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
136 resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530137 }
138
139 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530140 * Returns the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530141 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530142 * @return the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143 */
144 public YangGrouping getRefGroup() {
145 return refGroup;
146 }
147
148 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530149 * Sets the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530151 * @param refGroup the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152 */
153 public void setRefGroup(YangGrouping refGroup) {
154 this.refGroup = refGroup;
155 }
156
157 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530158 * Returns the when.
159 *
160 * @return the when
161 */
162 @Override
163 public YangWhen getWhen() {
164 return when;
165 }
166
167 /**
168 * Sets the when.
169 *
170 * @param when the when to set
171 */
172 @Override
173 public void setWhen(YangWhen when) {
174 this.when = when;
175 }
176
177 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530178 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530180 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530181 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530182 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530183 public String getDescription() {
184 return description;
185 }
186
187 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530188 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530189 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530190 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530192 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530193 public void setDescription(String description) {
194 this.description = description;
195 }
196
197 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530198 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530199 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530200 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530201 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530202 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530203 public String getReference() {
204 return reference;
205 }
206
207 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530208 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530209 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530210 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530211 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530212 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 public void setReference(String reference) {
214 this.reference = reference;
215 }
216
217 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530218 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530220 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530221 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530222 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530223 public YangStatusType getStatus() {
224 return status;
225 }
226
227 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530228 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530230 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530231 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530232 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530233 public void setStatus(YangStatusType status) {
234 this.status = status;
235 }
236
237 /**
238 * Returns the type of the data.
239 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530240 * @return returns USES_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530241 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530242 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530243 public YangConstructType getYangConstructType() {
244 return YangConstructType.USES_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530245 }
246
247 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530248 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530249 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530250 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530251 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530252 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530253 public void validateDataOnEntry()
254 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530255 // TODO auto-generated method stub, to be implemented by parser
256 }
257
258 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530259 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530260 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530261 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530262 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530263 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530264 public void validateDataOnExit()
265 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530266 // TODO auto-generated method stub, to be implemented by parser
267 }
268
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530269 @Override
270 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530271 return nodeIdentifier.getName();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530272 }
273
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530274 @Override
275 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530276 nodeIdentifier.setName(name);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530277 }
278
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530279 /**
280 * Returns node identifier.
281 *
282 * @return node identifier
283 */
284 public YangNodeIdentifier getNodeIdentifier() {
285 return nodeIdentifier;
286 }
287
288 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530289 * Sets node identifier.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530290 *
291 * @param nodeIdentifier the node identifier
292 */
293 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
294 this.nodeIdentifier = nodeIdentifier;
295 }
296
297 /**
298 * Returns prefix associated with uses.
299 *
300 * @return prefix associated with uses
301 */
302 public String getPrefix() {
303 return nodeIdentifier.getPrefix();
304 }
305
306 /**
307 * Get prefix associated with uses.
308 *
309 * @param prefix prefix associated with uses
310 */
311 public void setPrefix(String prefix) {
312 nodeIdentifier.setPrefix(prefix);
313 }
314
315 @Override
Vinod Kumar S427d2932016-04-20 13:02:58 +0530316 public void resolve()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530317 throws DataModelException {
Vinod Kumar S427d2932016-04-20 13:02:58 +0530318
319 YangGrouping referredGrouping = getRefGroup();
320
321 if (referredGrouping == null) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530322 throw new DataModelException("YANG uses linker error, cannot resolve uses");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530323 }
324
325 YangNode usesParentNode = getParentNodeInGenCode(this);
Bharat saraswalcad0e652016-05-26 23:48:38 +0530326 if (!(usesParentNode instanceof YangLeavesHolder)
327 || !(usesParentNode instanceof CollisionDetector)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530328 throw new DataModelException("YANG uses holder construct is wrong");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530329 }
330
331 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530332 if (referredGrouping.getListOfLeaf() != null
333 && referredGrouping.getListOfLeaf().size() != 0) {
334 addLeavesOfGrouping(
335 cloneLeavesList(referredGrouping.getListOfLeaf(),
336 usesParentLeavesHolder));
Vinod Kumar S427d2932016-04-20 13:02:58 +0530337 }
338
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530339 if (referredGrouping.getListOfLeafList() != null
340 && referredGrouping.getListOfLeafList().size() != 0) {
341 addListOfLeafListOfGrouping(
342 cloneListOfLeafList(referredGrouping.getListOfLeafList(),
343 usesParentLeavesHolder));
344 }
345
346 YangNode childInGrouping = referredGrouping.getChild();
347
348 while (childInGrouping != null) {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530349 if (childInGrouping instanceof YangEnumeration
350 || childInGrouping instanceof YangUnion
351 || childInGrouping instanceof YangTypeDef) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530352
353 /*
Bharat saraswal96dfef02016-06-16 00:29:12 +0530354 * No need to copy the leaves, union / enum class, as these will
355 * be generated in the scope of grouping
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530356 */
357 childInGrouping = childInGrouping.getNextSibling();
358 continue;
Bharat saraswal96dfef02016-06-16 00:29:12 +0530359 } else if (childInGrouping instanceof YangUses) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530360 addResolvedUsesInfoOfGrouping((YangUses) childInGrouping,
361 usesParentLeavesHolder);
362 } else {
363 addNodeOfGrouping(childInGrouping);
364 }
365
366 childInGrouping = childInGrouping.getNextSibling();
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530367 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530368 }
369
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530370 /**
371 * Clone the resolved uses contained in grouping to the uses of grouping.
372 *
373 * @param usesInGrouping resolved uses in grouping
374 * @param usesHolder holder of uses
375 */
376 private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530377 YangLeavesHolder usesHolder) throws DataModelException {
378 for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530379 addNodeOfGrouping(usesResolvedNode);
380 }
381
Bharat saraswal96dfef02016-06-16 00:29:12 +0530382 for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530383 addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
384 }
385
Bharat saraswal96dfef02016-06-16 00:29:12 +0530386 for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530387 addListOfLeafListOfGrouping(
388 cloneListOfLeafList(listOfLeafLists, usesHolder));
389 }
390 }
391
392 /**
393 * Clone the list of leaves and return the cloned list leaves.
394 *
395 * @param listOfLeaves list of leaves to be cloned
396 * @param usesParentNode parent of the cloned location
397 * @return cloned list of leaves
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530398 * @throws DataModelException a violation in data model rule
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530399 */
400 private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530401 YangLeavesHolder usesParentNode) throws DataModelException {
402 if (listOfLeaves == null || listOfLeaves.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530403 throw new DataModelException("No leaves to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530404 }
405
406 List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
407 for (YangLeaf leaf : listOfLeaves) {
408 YangLeaf clonedLeaf;
409 try {
410 ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
411 YangConstructType.LEAF_DATA);
412 clonedLeaf = leaf.clone();
413 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530414 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530415 }
416
417 clonedLeaf.setContainedIn(usesParentNode);
418 newLeavesList.add(clonedLeaf);
419 }
420
421 return newLeavesList;
422 }
423
424 /**
425 * Clone the list of leaf list.
426 *
427 * @param listOfLeafList list of leaf list that needs to be cloned
428 * @param usesParentNode parent of uses
429 * @return cloned list of leaf list
430 */
431 private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530432 YangLeavesHolder usesParentNode) throws DataModelException {
433 if (listOfLeafList == null || listOfLeafList.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530434 throw new DataModelException("No leaf lists to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530435 }
436
437 List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
438 for (YangLeafList leafList : listOfLeafList) {
439 YangLeafList clonedLeafList;
440 try {
441 ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
442 YangConstructType.LEAF_LIST_DATA);
443 clonedLeafList = leafList.clone();
444 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530445 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530446 }
447
448 clonedLeafList.setContainedIn(usesParentNode);
449 newListOfLeafList.add(clonedLeafList);
450 }
451
452 return newListOfLeafList;
453 }
454
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530455 @Override
456 public ResolvableStatus getResolvableStatus() {
457 return resolvableStatus;
458 }
459
460 @Override
461 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
462 this.resolvableStatus = resolvableStatus;
463 }
janani b4e53f9b2016-04-26 18:49:20 +0530464
465 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530466 public void detectCollidingChild(String identifierName, YangConstructType dataType)
467 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530468 detectCollidingChildUtil(identifierName, dataType, this);
469 }
470
471 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530472 public void detectSelfCollision(String identifierName, YangConstructType dataType)
473 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530474
475 if (getName().equals(identifierName)) {
476 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
477 + getName() + "\"");
478 }
479 }
480
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530481 /**
482 * Adds the node under grouping to the effective uses resolved info.
483 *
484 * @param nodeInGrouping node defined under grouping which needs to be copied in
485 * the context of uses
486 */
487 public void addNodeOfGrouping(YangNode nodeInGrouping) {
488 resolvedGroupingNodes.add(nodeInGrouping);
489 }
490
491 /**
492 * Returns the effective list of nodes added due to uses linking.
493 *
494 * @return effective list of nodes added due to uses linking
495 */
496 public List<YangNode> getUsesResolvedNodeList() {
497 return resolvedGroupingNodes;
498 }
499
500 /**
501 * Adds the leaves under grouping to the effective uses resolved info.
502 *
503 * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
504 * the context of uses
505 */
506 public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
507 resolvedGroupingLeaves.add(leavesInGrouping);
508 }
509
510 /**
511 * Returns the effective list of Leaves added due to uses linking.
512 *
513 * @return effective list of Leaves added due to uses linking
514 */
515 public List<List<YangLeaf>> getUsesResolvedLeavesList() {
516 return resolvedGroupingLeaves;
517 }
518
519 /**
520 * Adds the leaf-lists under grouping to the effective uses resolved info.
521 *
522 * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
523 * the context of uses
524 */
525 public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
526 resolvedGroupingLeafLists.add(leafListsInGrouping);
527 }
528
529 /**
530 * Returns the effective list of Leaves added due to uses linking.
531 *
532 * @return effective list of Leaves added due to uses linking
533 */
534 public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
535 return resolvedGroupingLeafLists;
536 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530537
538 @Override
539 public List<YangIfFeature> getIfFeatureList() {
540 return ifFeatureList;
541 }
542
543 @Override
544 public void addIfFeatureList(YangIfFeature ifFeature) {
545 if (getIfFeatureList() == null) {
546 setIfFeatureList(new LinkedList<>());
547 }
548 getIfFeatureList().add(ifFeature);
549 }
550
551 @Override
552 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
553 this.ifFeatureList = ifFeatureList;
554 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530555}