blob: 51cd310f8a8642400f84c3a331b248b1b6589d4e [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;
Vinod Kumar S427d2932016-04-20 13:02:58 +053029
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053030/*-
31 * Reference RFC 6020.
32 *
33 * The "uses" statement is used to reference a "grouping" definition. It takes
34 * one argument, which is the name of the grouping.
35 *
36 * The effect of a "uses" reference to a grouping is that the nodes defined by
37 * the grouping are copied into the current schema tree, and then updated
38 * according to the "refine" and "augment" statements.
39 *
40 * The identifiers defined in the grouping are not bound to a namespace until
41 * the contents of the grouping are added to the schema tree via a "uses"
42 * statement that does not appear inside a "grouping" statement, at which point
43 * they are bound to the namespace of the current module.
44 *
45 * The uses's sub-statements
46 *
47 * +--------------+---------+-------------+------------------+
48 * | substatement | section | cardinality |data model mapping|
49 * +--------------+---------+-------------+------------------+
50 * | augment | 7.15 | 0..1 | -child nodes |
51 * | description | 7.19.3 | 0..1 | -string |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053052 * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053053 * | refine | 7.12.2 | 0..1 | -TODO |
54 * | reference | 7.19.4 | 0..1 | -string |
55 * | status | 7.19.2 | 0..1 | -YangStatus |
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053056 * | when | 7.19.5 | 0..1 | -YangWhen |
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053057 * +--------------+---------+-------------+------------------+
58 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053059
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053060/**
Bharat saraswald9822e92016-04-05 15:13:44 +053061 * Represents data model node to maintain information defined in YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053062 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053063public class YangUses
64 extends YangNode
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053065 implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
66 YangIfFeatureHolder {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053067
Bharat saraswal96dfef02016-06-16 00:29:12 +053068 private static final long serialVersionUID = 806201617L;
69
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053070 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053071 * YANG node identifier.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053072 */
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053073 private YangNodeIdentifier nodeIdentifier;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053074
75 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053076 * Referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053077 */
78 private YangGrouping refGroup;
79
80 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053081 * Description of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053082 */
83 private String description;
84
85 /**
86 * YANG reference.
87 */
88 private String reference;
89
90 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +053091 * Status of YANG uses.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092 */
93 private YangStatusType status;
94
95 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053096 * When data of the node.
97 */
98 private YangWhen when;
99
100 /**
101 * List of if-feature.
102 */
103 private List<YangIfFeature> ifFeatureList;
104
105 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530106 * Status of resolution. If completely resolved enum value is "RESOLVED",
107 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
108 * is added to uses/type but it's not resolved value of enum should be
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530109 * "INTRA_FILE_RESOLVED".
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530110 */
111 private ResolvableStatus resolvableStatus;
112
113 /**
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530114 * Effective list of nodes of grouping that needs to replicated at YANG uses.
115 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530116 private List<YangNode> resolvedGroupingNodes;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530117
118 /**
119 * Effective list of leaves of grouping that needs to replicated at YANG uses.
120 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530121 private List<List<YangLeaf>> resolvedGroupingLeaves;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530122
123 /**
124 * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
125 */
Bharat saraswal96dfef02016-06-16 00:29:12 +0530126 private List<List<YangLeafList>> resolvedGroupingLeafLists;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530127
128 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * Creates an YANG uses node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 */
131 public YangUses() {
132 super(YangNodeType.USES_NODE);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530133 nodeIdentifier = new YangNodeIdentifier();
134 resolvableStatus = ResolvableStatus.UNRESOLVED;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530135 resolvedGroupingNodes = new LinkedList<YangNode>();
136 resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
137 resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 }
139
140 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530141 * Returns the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530142 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530143 * @return the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530144 */
145 public YangGrouping getRefGroup() {
146 return refGroup;
147 }
148
149 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530150 * Sets the referred group.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530151 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530152 * @param refGroup the referred group
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530153 */
154 public void setRefGroup(YangGrouping refGroup) {
155 this.refGroup = refGroup;
156 }
157
158 /**
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530159 * Returns the when.
160 *
161 * @return the when
162 */
163 @Override
164 public YangWhen getWhen() {
165 return when;
166 }
167
168 /**
169 * Sets the when.
170 *
171 * @param when the when to set
172 */
173 @Override
174 public void setWhen(YangWhen when) {
175 this.when = when;
176 }
177
178 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530179 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530180 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530181 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530182 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530183 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 public String getDescription() {
185 return description;
186 }
187
188 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530189 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530190 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530191 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530192 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530193 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530194 public void setDescription(String description) {
195 this.description = description;
196 }
197
198 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530199 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530200 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530201 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530202 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530203 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530204 public String getReference() {
205 return reference;
206 }
207
208 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530209 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530210 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530211 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530212 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530213 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 public void setReference(String reference) {
215 this.reference = reference;
216 }
217
218 /**
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530219 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530220 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530221 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530222 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530223 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530224 public YangStatusType getStatus() {
225 return status;
226 }
227
228 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530229 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530230 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530231 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530232 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530233 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530234 public void setStatus(YangStatusType status) {
235 this.status = status;
236 }
237
238 /**
239 * Returns the type of the data.
240 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530241 * @return returns USES_DATA
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530242 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530243 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530244 public YangConstructType getYangConstructType() {
245 return YangConstructType.USES_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530246 }
247
248 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530249 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530250 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530251 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530252 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530253 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530254 public void validateDataOnEntry()
255 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530256 // TODO auto-generated method stub, to be implemented by parser
257 }
258
259 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530260 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530262 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530263 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530264 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530265 public void validateDataOnExit()
266 throws DataModelException {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530267 // TODO auto-generated method stub, to be implemented by parser
268 }
269
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530270 @Override
271 public String getName() {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530272 return nodeIdentifier.getName();
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530273 }
274
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530275 @Override
276 public void setName(String name) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530277 nodeIdentifier.setName(name);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530278 }
279
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530280 /**
281 * Returns node identifier.
282 *
283 * @return node identifier
284 */
285 public YangNodeIdentifier getNodeIdentifier() {
286 return nodeIdentifier;
287 }
288
289 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530290 * Sets node identifier.
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530291 *
292 * @param nodeIdentifier the node identifier
293 */
294 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
295 this.nodeIdentifier = nodeIdentifier;
296 }
297
298 /**
299 * Returns prefix associated with uses.
300 *
301 * @return prefix associated with uses
302 */
303 public String getPrefix() {
304 return nodeIdentifier.getPrefix();
305 }
306
307 /**
308 * Get prefix associated with uses.
309 *
310 * @param prefix prefix associated with uses
311 */
312 public void setPrefix(String prefix) {
313 nodeIdentifier.setPrefix(prefix);
314 }
315
316 @Override
Vinod Kumar S427d2932016-04-20 13:02:58 +0530317 public void resolve()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530318 throws DataModelException {
Vinod Kumar S427d2932016-04-20 13:02:58 +0530319
320 YangGrouping referredGrouping = getRefGroup();
321
322 if (referredGrouping == null) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530323 throw new DataModelException("YANG uses linker error, cannot resolve uses");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530324 }
325
326 YangNode usesParentNode = getParentNodeInGenCode(this);
Bharat saraswalcad0e652016-05-26 23:48:38 +0530327 if (!(usesParentNode instanceof YangLeavesHolder)
328 || !(usesParentNode instanceof CollisionDetector)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530329 throw new DataModelException("YANG uses holder construct is wrong");
Vinod Kumar S427d2932016-04-20 13:02:58 +0530330 }
331
332 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530333 if (referredGrouping.getListOfLeaf() != null) {
334 for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
335 YangLeaf clonedLeaf = null;
336 try {
337 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
338 YangConstructType.LEAF_DATA);
339 clonedLeaf = leaf.clone();
Vinod Kumar S427d2932016-04-20 13:02:58 +0530340
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530341 } catch (CloneNotSupportedException | DataModelException e) {
342 throw new DataModelException(e.getMessage());
343 }
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530344
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530345 clonedLeaf.setContainedIn(usesParentLeavesHolder);
346 usesParentLeavesHolder.addLeaf(clonedLeaf);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530347 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530348 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530349 if (referredGrouping.getListOfLeafList() != null) {
350 for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
351 YangLeafList clonedLeafList = null;
352 try {
353 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
354 YangConstructType.LEAF_LIST_DATA);
355 clonedLeafList = leafList.clone();
356
357 } catch (CloneNotSupportedException | DataModelException e) {
358 throw new DataModelException(e.getMessage());
359 }
360
361 clonedLeafList.setContainedIn(usesParentLeavesHolder);
362 usesParentLeavesHolder.addLeafList(clonedLeafList);
363 }
364 }
365
366 try {
367 YangNode.cloneSubTree(referredGrouping, usesParentNode);
368 } catch (DataModelException e) {
369 throw new DataModelException(e.getMessage());
370 }
371 updateClonedLeavesUnionEnumRef(usesParentLeavesHolder);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530372 }
373
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530374 /**
375 * Clone the resolved uses contained in grouping to the uses of grouping.
376 *
377 * @param usesInGrouping resolved uses in grouping
378 * @param usesHolder holder of uses
379 */
380 private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530381 YangLeavesHolder usesHolder) throws DataModelException {
382 for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530383 addNodeOfGrouping(usesResolvedNode);
384 }
385
Bharat saraswal96dfef02016-06-16 00:29:12 +0530386 for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530387 addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
388 }
389
Bharat saraswal96dfef02016-06-16 00:29:12 +0530390 for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530391 addListOfLeafListOfGrouping(
392 cloneListOfLeafList(listOfLeafLists, usesHolder));
393 }
394 }
395
396 /**
397 * Clone the list of leaves and return the cloned list leaves.
398 *
399 * @param listOfLeaves list of leaves to be cloned
400 * @param usesParentNode parent of the cloned location
401 * @return cloned list of leaves
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530402 * @throws DataModelException a violation in data model rule
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530403 */
404 private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530405 YangLeavesHolder usesParentNode) throws DataModelException {
406 if (listOfLeaves == null || listOfLeaves.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530407 throw new DataModelException("No leaves to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530408 }
409
410 List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
411 for (YangLeaf leaf : listOfLeaves) {
412 YangLeaf clonedLeaf;
413 try {
414 ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
415 YangConstructType.LEAF_DATA);
416 clonedLeaf = leaf.clone();
417 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530418 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530419 }
420
421 clonedLeaf.setContainedIn(usesParentNode);
422 newLeavesList.add(clonedLeaf);
423 }
424
425 return newLeavesList;
426 }
427
428 /**
429 * Clone the list of leaf list.
430 *
431 * @param listOfLeafList list of leaf list that needs to be cloned
432 * @param usesParentNode parent of uses
433 * @return cloned list of leaf list
434 */
435 private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530436 YangLeavesHolder usesParentNode) throws DataModelException {
437 if (listOfLeafList == null || listOfLeafList.size() == 0) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530438 throw new DataModelException("No leaf lists to clone");
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530439 }
440
441 List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
442 for (YangLeafList leafList : listOfLeafList) {
443 YangLeafList clonedLeafList;
444 try {
445 ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
446 YangConstructType.LEAF_LIST_DATA);
447 clonedLeafList = leafList.clone();
448 } catch (CloneNotSupportedException | DataModelException e) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530449 throw new DataModelException(e.getMessage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530450 }
451
452 clonedLeafList.setContainedIn(usesParentNode);
453 newListOfLeafList.add(clonedLeafList);
454 }
455
456 return newListOfLeafList;
457 }
458
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530459 @Override
460 public ResolvableStatus getResolvableStatus() {
461 return resolvableStatus;
462 }
463
464 @Override
465 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
466 this.resolvableStatus = resolvableStatus;
467 }
janani b4e53f9b2016-04-26 18:49:20 +0530468
469 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530470 public void detectCollidingChild(String identifierName, YangConstructType dataType)
471 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530472 detectCollidingChildUtil(identifierName, dataType, this);
473 }
474
475 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530476 public void detectSelfCollision(String identifierName, YangConstructType dataType)
477 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +0530478
479 if (getName().equals(identifierName)) {
480 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
481 + getName() + "\"");
482 }
483 }
484
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530485 /**
486 * Adds the node under grouping to the effective uses resolved info.
487 *
488 * @param nodeInGrouping node defined under grouping which needs to be copied in
489 * the context of uses
490 */
491 public void addNodeOfGrouping(YangNode nodeInGrouping) {
492 resolvedGroupingNodes.add(nodeInGrouping);
493 }
494
495 /**
496 * Returns the effective list of nodes added due to uses linking.
497 *
498 * @return effective list of nodes added due to uses linking
499 */
500 public List<YangNode> getUsesResolvedNodeList() {
501 return resolvedGroupingNodes;
502 }
503
504 /**
505 * Adds the leaves under grouping to the effective uses resolved info.
506 *
507 * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
508 * the context of uses
509 */
510 public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
511 resolvedGroupingLeaves.add(leavesInGrouping);
512 }
513
514 /**
515 * Returns the effective list of Leaves added due to uses linking.
516 *
517 * @return effective list of Leaves added due to uses linking
518 */
519 public List<List<YangLeaf>> getUsesResolvedLeavesList() {
520 return resolvedGroupingLeaves;
521 }
522
523 /**
524 * Adds the leaf-lists under grouping to the effective uses resolved info.
525 *
526 * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
527 * the context of uses
528 */
529 public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
530 resolvedGroupingLeafLists.add(leafListsInGrouping);
531 }
532
533 /**
534 * Returns the effective list of Leaves added due to uses linking.
535 *
536 * @return effective list of Leaves added due to uses linking
537 */
538 public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
539 return resolvedGroupingLeafLists;
540 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530541
542 @Override
543 public List<YangIfFeature> getIfFeatureList() {
544 return ifFeatureList;
545 }
546
547 @Override
548 public void addIfFeatureList(YangIfFeature ifFeature) {
549 if (getIfFeatureList() == null) {
550 setIfFeatureList(new LinkedList<>());
551 }
552 getIfFeatureList().add(ifFeature);
553 }
554
555 @Override
556 public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
557 this.ifFeatureList = ifFeatureList;
558 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530559}