Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.yangutils.datamodel.utils; |
| 18 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 19 | import java.io.FileInputStream; |
| 20 | import java.io.IOException; |
| 21 | import java.io.ObjectInputStream; |
| 22 | import java.util.ArrayList; |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 23 | import java.util.List; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 24 | import java.util.Set; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 25 | |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.CollisionDetector; |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.ResolvableType; |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangIfFeature; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangAugment; |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangBase; |
| 31 | import org.onosproject.yangutils.datamodel.YangIdentityRef; |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 33 | import org.onosproject.yangutils.datamodel.YangLeafList; |
janani b | e18b534 | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.datamodel.YangLeafRef; |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 36 | import org.onosproject.yangutils.datamodel.YangNode; |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
| 38 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.datamodel.YangRpc; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 40 | import org.onosproject.yangutils.datamodel.YangType; |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 41 | import org.onosproject.yangutils.datamodel.YangUses; |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 42 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 43 | |
| 44 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 45 | * Represents utilities for data model tree. |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 46 | */ |
| 47 | public final class DataModelUtils { |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 48 | |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 49 | /** |
| 50 | * Creates a new data model tree utility. |
| 51 | */ |
| 52 | private DataModelUtils() { |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Detects the colliding identifier name in a given YANG node and its child. |
| 57 | * |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 58 | * @param identifierName name for which collision detection is to be checked |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 59 | * @param dataType type of YANG node asking for detecting collision |
| 60 | * @param node instance of calling node |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 61 | * @throws DataModelException a violation of data model rules |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 62 | */ |
| 63 | public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) |
| 64 | throws DataModelException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 65 | if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) { |
| 66 | detectCollidingForUsesGrouping(identifierName, dataType, node); |
| 67 | } else { |
| 68 | if (node instanceof YangLeavesHolder) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 69 | YangLeavesHolder leavesHolder = (YangLeavesHolder) node; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 70 | detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName); |
| 71 | detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName); |
| 72 | } |
| 73 | node = node.getChild(); |
| 74 | while (node != null) { |
| 75 | Parsable parsable = (Parsable) node; |
| 76 | if (node instanceof CollisionDetector |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 77 | && parsable.getYangConstructType() != YangConstructType.USES_DATA |
| 78 | && parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 79 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
| 80 | } |
| 81 | node = node.getNextSibling(); |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 82 | } |
| 83 | } |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Detects colliding of uses and grouping only with uses and grouping respectively. |
| 88 | * |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 89 | * @param identifierName name for which collision detection is to be checked |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 90 | * @param dataType type of YANG node asking for detecting collision |
| 91 | * @param node node instance of calling node |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 92 | * @throws DataModelException a violation of data model rules |
| 93 | */ |
| 94 | public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node) |
| 95 | throws DataModelException { |
| 96 | |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 97 | node = node.getChild(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 98 | while (node != null) { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 99 | Parsable parsable = (Parsable) node; |
| 100 | if (node instanceof CollisionDetector |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 101 | && parsable.getYangConstructType() == dataType) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 102 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
| 103 | } |
| 104 | node = node.getNextSibling(); |
| 105 | } |
| 106 | } |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Detects the colliding identifier name in a given leaf node. |
| 110 | * |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 111 | * @param listOfLeaf List of leaves to detect collision |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 112 | * @param identifierName name for which collision detection is to be checked |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 113 | * @throws DataModelException a violation of data model rules |
| 114 | */ |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 115 | private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName) |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 116 | throws DataModelException { |
| 117 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 118 | if (listOfLeaf == null) { |
| 119 | return; |
| 120 | } |
| 121 | for (YangLeaf leaf : listOfLeaf) { |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 122 | if (leaf.getName().equals(identifierName)) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 123 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 124 | + leaf.getName() + "\""); |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Detects the colliding identifier name in a given leaf-list node. |
| 131 | * |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 132 | * @param listOfLeafList list of leaf-lists to detect collision |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 133 | * @param identifierName name for which collision detection is to be checked |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 134 | * @throws DataModelException a violation of data model rules |
| 135 | */ |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 136 | private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName) |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 137 | throws DataModelException { |
| 138 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 139 | if (listOfLeafList == null) { |
| 140 | return; |
| 141 | } |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 142 | for (YangLeafList leafList : listOfLeafList) { |
| 143 | if (leafList.getName().equals(identifierName)) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 144 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 145 | "list \"" + leafList.getName() + "\""); |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Add a resolution information. |
| 152 | * |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 153 | * @param resolutionInfo information about the YANG construct which has to be resolved |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 154 | * @throws DataModelException a violation of data model rules |
| 155 | */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 156 | public static void addResolutionInfo(YangResolutionInfo resolutionInfo) |
| 157 | throws DataModelException { |
| 158 | |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 159 | /* get the module node to add maintain the list of nested reference */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 160 | YangNode curNode = resolutionInfo.getEntityToResolveInfo() |
| 161 | .getHolderOfEntityToResolve(); |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 162 | while (!(curNode instanceof YangReferenceResolver)) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 163 | curNode = curNode.getParent(); |
| 164 | if (curNode == null) { |
| 165 | throw new DataModelException("Internal datamodel error: Datamodel tree is not correct"); |
| 166 | } |
| 167 | } |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 168 | YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode; |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 169 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 170 | if (resolutionInfo.getEntityToResolveInfo() |
| 171 | .getEntityToResolve() instanceof YangType) { |
| 172 | resolutionNode.addToResolutionList(resolutionInfo, |
| 173 | ResolvableType.YANG_DERIVED_DATA_TYPE); |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 174 | } else if (resolutionInfo.getEntityToResolveInfo() |
| 175 | .getEntityToResolve() instanceof YangUses) { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 176 | resolutionNode.addToResolutionList(resolutionInfo, |
| 177 | ResolvableType.YANG_USES); |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 178 | } else if (resolutionInfo.getEntityToResolveInfo() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 179 | .getEntityToResolve() instanceof YangAugment) { |
| 180 | resolutionNode.addToResolutionList(resolutionInfo, |
| 181 | ResolvableType.YANG_AUGMENT); |
| 182 | } else if (resolutionInfo.getEntityToResolveInfo() |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 183 | .getEntityToResolve() instanceof YangIfFeature) { |
| 184 | resolutionNode.addToResolutionList(resolutionInfo, |
| 185 | ResolvableType.YANG_IF_FEATURE); |
janani b | e18b534 | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 186 | } else if (resolutionInfo.getEntityToResolveInfo() |
| 187 | .getEntityToResolve() instanceof YangLeafRef) { |
| 188 | resolutionNode.addToResolutionList(resolutionInfo, |
| 189 | ResolvableType.YANG_LEAFREF); |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 190 | } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) { |
| 191 | resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE); |
| 192 | } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) { |
| 193 | resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 194 | } |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 195 | } |
| 196 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 197 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 198 | * Resolve linking for a resolution list. |
| 199 | * |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 200 | * @param resolutionList resolution list for which linking to be done |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 201 | * @param dataModelRootNode module/sub-module node |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 202 | * @throws DataModelException a violation of data model rules |
| 203 | */ |
| 204 | public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList, |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 205 | YangReferenceResolver dataModelRootNode) |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 206 | throws DataModelException { |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 207 | |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 208 | for (YangResolutionInfo resolutionInfo : resolutionList) { |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 209 | resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Links type/uses referring to typedef/uses of inter YANG file. |
| 215 | * |
| 216 | * @param resolutionList resolution list for which linking to be done |
| 217 | * @param dataModelRootNode module/sub-module node |
| 218 | * @throws DataModelException a violation of data model rules |
| 219 | */ |
| 220 | public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList, |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 221 | YangReferenceResolver dataModelRootNode) |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 222 | throws DataModelException { |
| 223 | /* |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 224 | * Run through the resolution list, find type/uses referring to inter |
| 225 | * file typedef/grouping, ask for linking. |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 226 | */ |
| 227 | for (YangResolutionInfo resolutionInfo : resolutionList) { |
| 228 | resolutionInfo.linkInterFile(dataModelRootNode); |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 229 | } |
| 230 | } |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * Checks if there is any rpc defined in the module or sub-module. |
| 234 | * |
| 235 | * @param rootNode root node of the data model |
| 236 | * @return status of rpc's existence |
| 237 | */ |
| 238 | public static boolean isRpcChildNodePresent(YangNode rootNode) { |
| 239 | YangNode childNode = rootNode.getChild(); |
| 240 | while (childNode != null) { |
| 241 | if (childNode instanceof YangRpc) { |
| 242 | return true; |
| 243 | } |
| 244 | childNode = childNode.getNextSibling(); |
| 245 | } |
| 246 | return false; |
| 247 | } |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 248 | |
| 249 | /** |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 250 | * Returns referred node in a given set. |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 251 | * |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 252 | * @param yangNodeSet YANG node set |
| 253 | * @param refNodeName name of the node which is referred |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 254 | * @return referred node's reference |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 255 | */ |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 256 | public static YangNode findReferredNode(Set<YangNode> yangNodeSet, String refNodeName) { |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 257 | /* |
| 258 | * Run through the YANG files to see which YANG file matches the |
| 259 | * referred node name. |
| 260 | */ |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 261 | for (YangNode yangNode : yangNodeSet) { |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 262 | if (yangNode.getName().equals(refNodeName)) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 263 | return yangNode; |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 264 | } |
| 265 | } |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 266 | return null; |
Vidyashree Rama | 1db1556 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 267 | } |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * Returns the contained data model parent node. |
| 271 | * |
| 272 | * @param currentNode current node which parent contained node is required |
| 273 | * @return parent node in which the current node is an attribute |
| 274 | */ |
| 275 | public static YangNode getParentNodeInGenCode(YangNode currentNode) { |
| 276 | |
| 277 | /* |
| 278 | * TODO: recursive parent lookup to support choice/augment/uses. TODO: |
| 279 | * need to check if this needs to be updated for |
| 280 | * choice/case/augment/grouping |
| 281 | */ |
| 282 | return currentNode.getParent(); |
| 283 | } |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * Returns de-serializes YANG data-model nodes. |
| 287 | * |
| 288 | * @param serializableInfoSet YANG file info set |
| 289 | * @return de-serializes YANG data-model nodes |
| 290 | * @throws IOException when fails do IO operations |
| 291 | */ |
| 292 | public static List<YangNode> deSerializeDataModel(List<String> serializableInfoSet) throws IOException { |
| 293 | |
| 294 | List<YangNode> nodes = new ArrayList<>(); |
| 295 | for (String fileInfo : serializableInfoSet) { |
| 296 | YangNode node = null; |
| 297 | try { |
| 298 | FileInputStream fileInputStream = new FileInputStream(fileInfo); |
| 299 | ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); |
| 300 | node = (YangNode) objectInputStream.readObject(); |
| 301 | nodes.add(node); |
| 302 | objectInputStream.close(); |
| 303 | fileInputStream.close(); |
| 304 | } catch (IOException | ClassNotFoundException e) { |
| 305 | throw new IOException(fileInfo + " not found."); |
| 306 | } |
| 307 | } |
| 308 | return nodes; |
| 309 | } |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 310 | } |