blob: 64f2c78e271cd0d8534c1d42472e86dcb5f6d0d4 [file] [log] [blame]
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +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 */
16
17package org.onosproject.yangutils.datamodel.utils;
18
Bharat saraswalb1170bd2016-07-14 13:26:18 +053019import java.io.FileInputStream;
20import java.io.IOException;
21import java.io.ObjectInputStream;
22import java.util.ArrayList;
Vidyashree Rama405d2e62016-07-08 20:45:41 +053023import java.util.LinkedList;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053024import java.util.List;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053025import java.util.Set;
Bharat saraswal96dfef02016-06-16 00:29:12 +053026
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053027import org.onosproject.yangutils.datamodel.CollisionDetector;
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053028import org.onosproject.yangutils.datamodel.ResolvableType;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053029import org.onosproject.yangutils.datamodel.YangIfFeature;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053030import org.onosproject.yangutils.datamodel.YangAugment;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053031import org.onosproject.yangutils.datamodel.YangBase;
Vidyashree Rama405d2e62016-07-08 20:45:41 +053032import org.onosproject.yangutils.datamodel.YangEnumeration;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053033import org.onosproject.yangutils.datamodel.YangIdentityRef;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053034import org.onosproject.yangutils.datamodel.YangLeaf;
35import org.onosproject.yangutils.datamodel.YangLeafList;
janani be18b5342016-07-13 21:06:41 +053036import org.onosproject.yangutils.datamodel.YangLeafRef;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053037import org.onosproject.yangutils.datamodel.YangLeavesHolder;
38import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053039import org.onosproject.yangutils.datamodel.YangReferenceResolver;
40import org.onosproject.yangutils.datamodel.YangResolutionInfo;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053041import org.onosproject.yangutils.datamodel.YangRpc;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053042import org.onosproject.yangutils.datamodel.YangType;
Vidyashree Rama405d2e62016-07-08 20:45:41 +053043import org.onosproject.yangutils.datamodel.YangUnion;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053044import org.onosproject.yangutils.datamodel.YangUses;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053045import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Vidyashree Rama405d2e62016-07-08 20:45:41 +053046import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053047
48/**
Bharat saraswald9822e92016-04-05 15:13:44 +053049 * Represents utilities for data model tree.
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053050 */
51public final class DataModelUtils {
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053052
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053053 /**
54 * Creates a new data model tree utility.
55 */
56 private DataModelUtils() {
57 }
58
59 /**
60 * Detects the colliding identifier name in a given YANG node and its child.
61 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053062 * @param identifierName name for which collision detection is to be checked
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053063 * @param dataType type of YANG node asking for detecting collision
64 * @param node instance of calling node
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053065 * @throws DataModelException a violation of data model rules
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053066 */
67 public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
68 throws DataModelException {
janani b4e53f9b2016-04-26 18:49:20 +053069 if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) {
70 detectCollidingForUsesGrouping(identifierName, dataType, node);
71 } else {
72 if (node instanceof YangLeavesHolder) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053073 YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
janani b4e53f9b2016-04-26 18:49:20 +053074 detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName);
75 detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName);
76 }
77 node = node.getChild();
78 while (node != null) {
79 Parsable parsable = (Parsable) node;
80 if (node instanceof CollisionDetector
Bharat saraswal33dfa012016-05-17 19:59:16 +053081 && parsable.getYangConstructType() != YangConstructType.USES_DATA
82 && parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) {
janani b4e53f9b2016-04-26 18:49:20 +053083 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
84 }
85 node = node.getNextSibling();
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053086 }
87 }
janani b4e53f9b2016-04-26 18:49:20 +053088 }
89
90 /**
91 * Detects colliding of uses and grouping only with uses and grouping respectively.
92 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053093 * @param identifierName name for which collision detection is to be checked
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053094 * @param dataType type of YANG node asking for detecting collision
95 * @param node node instance of calling node
janani b4e53f9b2016-04-26 18:49:20 +053096 * @throws DataModelException a violation of data model rules
97 */
98 public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
99 throws DataModelException {
100
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530101 node = node.getChild();
Vinod Kumar S38046502016-03-23 15:30:27 +0530102 while (node != null) {
janani b4e53f9b2016-04-26 18:49:20 +0530103 Parsable parsable = (Parsable) node;
104 if (node instanceof CollisionDetector
Bharat saraswal33dfa012016-05-17 19:59:16 +0530105 && parsable.getYangConstructType() == dataType) {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530106 ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
107 }
108 node = node.getNextSibling();
109 }
110 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530111
112 /**
113 * Detects the colliding identifier name in a given leaf node.
114 *
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530115 * @param listOfLeaf List of leaves to detect collision
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530116 * @param identifierName name for which collision detection is to be checked
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530117 * @throws DataModelException a violation of data model rules
118 */
janani b4e53f9b2016-04-26 18:49:20 +0530119 private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
Bharat saraswald9822e92016-04-05 15:13:44 +0530120 throws DataModelException {
121
janani b4e53f9b2016-04-26 18:49:20 +0530122 if (listOfLeaf == null) {
123 return;
124 }
125 for (YangLeaf leaf : listOfLeaf) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530126 if (leaf.getName().equals(identifierName)) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530127 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530128 + leaf.getName() + "\"");
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530129 }
130 }
131 }
132
133 /**
134 * Detects the colliding identifier name in a given leaf-list node.
135 *
janani b4e53f9b2016-04-26 18:49:20 +0530136 * @param listOfLeafList list of leaf-lists to detect collision
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530137 * @param identifierName name for which collision detection is to be checked
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530138 * @throws DataModelException a violation of data model rules
139 */
janani b4e53f9b2016-04-26 18:49:20 +0530140 private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
Bharat saraswald9822e92016-04-05 15:13:44 +0530141 throws DataModelException {
142
janani b4e53f9b2016-04-26 18:49:20 +0530143 if (listOfLeafList == null) {
144 return;
145 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530146 for (YangLeafList leafList : listOfLeafList) {
147 if (leafList.getName().equals(identifierName)) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530148 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530149 "list \"" + leafList.getName() + "\"");
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530150 }
151 }
152 }
153
154 /**
155 * Add a resolution information.
156 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530157 * @param resolutionInfo information about the YANG construct which has to be resolved
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530158 * @throws DataModelException a violation of data model rules
159 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530160 public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
161 throws DataModelException {
162
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530163 /* get the module node to add maintain the list of nested reference */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530164 YangNode curNode = resolutionInfo.getEntityToResolveInfo()
165 .getHolderOfEntityToResolve();
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530166 while (!(curNode instanceof YangReferenceResolver)) {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530167 curNode = curNode.getParent();
168 if (curNode == null) {
169 throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
170 }
171 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530172 YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530173
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530174 if (resolutionInfo.getEntityToResolveInfo()
175 .getEntityToResolve() instanceof YangType) {
176 resolutionNode.addToResolutionList(resolutionInfo,
177 ResolvableType.YANG_DERIVED_DATA_TYPE);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530178 } else if (resolutionInfo.getEntityToResolveInfo()
179 .getEntityToResolve() instanceof YangUses) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530180 resolutionNode.addToResolutionList(resolutionInfo,
181 ResolvableType.YANG_USES);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530182 } else if (resolutionInfo.getEntityToResolveInfo()
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530183 .getEntityToResolve() instanceof YangAugment) {
184 resolutionNode.addToResolutionList(resolutionInfo,
185 ResolvableType.YANG_AUGMENT);
186 } else if (resolutionInfo.getEntityToResolveInfo()
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530187 .getEntityToResolve() instanceof YangIfFeature) {
188 resolutionNode.addToResolutionList(resolutionInfo,
189 ResolvableType.YANG_IF_FEATURE);
janani be18b5342016-07-13 21:06:41 +0530190 } else if (resolutionInfo.getEntityToResolveInfo()
191 .getEntityToResolve() instanceof YangLeafRef) {
192 resolutionNode.addToResolutionList(resolutionInfo,
193 ResolvableType.YANG_LEAFREF);
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530194 } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
195 resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
196 } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
197 resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530198 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530199 }
200
janani b4e53f9b2016-04-26 18:49:20 +0530201 /**
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530202 * Resolve linking for a resolution list.
203 *
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530204 * @param resolutionList resolution list for which linking to be done
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530205 * @param dataModelRootNode module/sub-module node
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530206 * @throws DataModelException a violation of data model rules
207 */
208 public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530209 YangReferenceResolver dataModelRootNode)
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530210 throws DataModelException {
Bharat saraswald9822e92016-04-05 15:13:44 +0530211
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530212 for (YangResolutionInfo resolutionInfo : resolutionList) {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530213 resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode);
214 }
215 }
216
217 /**
218 * Links type/uses referring to typedef/uses of inter YANG file.
219 *
220 * @param resolutionList resolution list for which linking to be done
221 * @param dataModelRootNode module/sub-module node
222 * @throws DataModelException a violation of data model rules
223 */
224 public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
Bharat saraswal96dfef02016-06-16 00:29:12 +0530225 YangReferenceResolver dataModelRootNode)
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530226 throws DataModelException {
227 /*
Bharat saraswal96dfef02016-06-16 00:29:12 +0530228 * Run through the resolution list, find type/uses referring to inter
229 * file typedef/grouping, ask for linking.
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530230 */
231 for (YangResolutionInfo resolutionInfo : resolutionList) {
232 resolutionInfo.linkInterFile(dataModelRootNode);
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530233 }
234 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530235
236 /**
237 * Checks if there is any rpc defined in the module or sub-module.
238 *
239 * @param rootNode root node of the data model
240 * @return status of rpc's existence
241 */
242 public static boolean isRpcChildNodePresent(YangNode rootNode) {
243 YangNode childNode = rootNode.getChild();
244 while (childNode != null) {
245 if (childNode instanceof YangRpc) {
246 return true;
247 }
248 childNode = childNode.getNextSibling();
249 }
250 return false;
251 }
Vidyashree Rama1db15562016-05-17 16:16:15 +0530252
253 /**
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530254 * Returns referred node in a given set.
Vidyashree Rama1db15562016-05-17 16:16:15 +0530255 *
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530256 * @param yangNodeSet YANG node set
257 * @param refNodeName name of the node which is referred
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530258 * @return referred node's reference
Vidyashree Rama1db15562016-05-17 16:16:15 +0530259 */
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530260 public static YangNode findReferredNode(Set<YangNode> yangNodeSet, String refNodeName) {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530261 /*
262 * Run through the YANG files to see which YANG file matches the
263 * referred node name.
264 */
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530265 for (YangNode yangNode : yangNodeSet) {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530266 if (yangNode.getName().equals(refNodeName)) {
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530267 return yangNode;
Vidyashree Rama1db15562016-05-17 16:16:15 +0530268 }
269 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530270 return null;
Vidyashree Rama1db15562016-05-17 16:16:15 +0530271 }
Bharat saraswal96dfef02016-06-16 00:29:12 +0530272
273 /**
274 * Returns the contained data model parent node.
275 *
276 * @param currentNode current node which parent contained node is required
277 * @return parent node in which the current node is an attribute
278 */
279 public static YangNode getParentNodeInGenCode(YangNode currentNode) {
280
281 /*
282 * TODO: recursive parent lookup to support choice/augment/uses. TODO:
283 * need to check if this needs to be updated for
284 * choice/case/augment/grouping
285 */
286 return currentNode.getParent();
287 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530288
289 /**
290 * Returns de-serializes YANG data-model nodes.
291 *
292 * @param serializableInfoSet YANG file info set
293 * @return de-serializes YANG data-model nodes
294 * @throws IOException when fails do IO operations
295 */
296 public static List<YangNode> deSerializeDataModel(List<String> serializableInfoSet) throws IOException {
297
298 List<YangNode> nodes = new ArrayList<>();
299 for (String fileInfo : serializableInfoSet) {
300 YangNode node = null;
301 try {
302 FileInputStream fileInputStream = new FileInputStream(fileInfo);
303 ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
304 node = (YangNode) objectInputStream.readObject();
305 nodes.add(node);
306 objectInputStream.close();
307 fileInputStream.close();
308 } catch (IOException | ClassNotFoundException e) {
309 throw new IOException(fileInfo + " not found.");
310 }
311 }
312 return nodes;
313 }
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530314
315 /**
316 * Clones the list of leaves and list of leaf list in the leaves holder.
317 *
318 * @param leavesHolder YANG node potentially containing leaves or leaf lists
319 * @throws CloneNotSupportedException clone is not supported
320 * @throws DataModelException data model error
321 */
322 public static void cloneLeaves(YangLeavesHolder leavesHolder)
323 throws CloneNotSupportedException, DataModelException {
324 List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
325 if (currentListOfLeaves != null) {
326 List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>();
327 for (YangLeaf leaf : currentListOfLeaves) {
328 YangLeaf clonedLeaf = leaf.clone();
329 clonedLeaf.setContainedIn(leavesHolder);
330 clonedLeavesList.add(clonedLeaf);
331 }
332 leavesHolder.setListOfLeaf(clonedLeavesList);
333 }
334
335 List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
336 if (currentListOfLeafList != null) {
337 List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>();
338 for (YangLeafList leafList : currentListOfLeafList) {
339 YangLeafList clonedLeafList = leafList.clone();
340 clonedLeafList.setContainedIn(leavesHolder);
341 clonedListOfLeafList.add(clonedLeafList);
342 }
343 leavesHolder.setListOfLeafList(clonedListOfLeafList);
344 }
345 }
346
347 /**
348 * Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding
349 * type info needs to be updated to the cloned new type node.
350 *
351 * @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
Bharat saraswalb551aae2016-07-14 15:18:20 +0530352 * @throws DataModelException when fails to do data model operations
Vidyashree Rama405d2e62016-07-08 20:45:41 +0530353 */
354 public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder) throws DataModelException {
355 List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
356 if (currentListOfLeaves != null) {
357 for (YangLeaf leaf : currentListOfLeaves) {
358 if (leaf.getDataType().getDataType() == YangDataTypes.ENUMERATION
359 || leaf.getDataType().getDataType() == YangDataTypes.UNION) {
360 try {
361 updateClonedTypeRef(leaf.getDataType(), leavesHolder);
362 } catch (DataModelException e) {
363 throw e;
364 }
365 }
366 }
367
368 }
369
370 List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
371 if (currentListOfLeafList != null) {
372 for (YangLeafList leafList : currentListOfLeafList) {
373 if (leafList.getDataType().getDataType() == YangDataTypes.ENUMERATION
374 || leafList.getDataType().getDataType() == YangDataTypes.UNION) {
375 try {
376 updateClonedTypeRef(leafList.getDataType(), leavesHolder);
377 } catch (DataModelException e) {
378 throw e;
379 }
380 }
381 }
382 }
383 }
384
385 /**
386 * Updates the types extended info pointer to point to the cloned type node.
387 *
388 * @param dataType data type, whose extended info needs to be pointed to the cloned type
389 * @param leavesHolder the leaves holder having the cloned type
390 */
391 private static void updateClonedTypeRef(YangType dataType, YangLeavesHolder leavesHolder)
392 throws DataModelException {
393 if (!(leavesHolder instanceof YangNode)) {
394 throw new DataModelException("Data model error: cloned leaves holder is not a node");
395 }
396 YangNode potentialTypeNode = ((YangNode) leavesHolder).getChild();
397 while (potentialTypeNode != null) {
398 String dataTypeName = null;
399 if (dataType.getDataType() == YangDataTypes.ENUMERATION) {
400 YangEnumeration enumNode = (YangEnumeration) dataType.getDataTypeExtendedInfo();
401 dataTypeName = enumNode.getName();
402 } else if (dataType.getDataType() == YangDataTypes.UNION) {
403 YangUnion unionNode = (YangUnion) dataType.getDataTypeExtendedInfo();
404 dataTypeName = unionNode.getName();
405 }
406 if (potentialTypeNode.getName().contentEquals(dataTypeName)) {
407 dataType.setDataTypeExtendedInfo((Object) potentialTypeNode);
408 return;
409 }
410 potentialTypeNode = potentialTypeNode.getNextSibling();
411 }
412
413 throw new DataModelException("Data model error: cloned leaves type is not found");
414 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530415}