Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +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 | package org.onosproject.yangutils.datamodel; |
| 17 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 20 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 23 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
| 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 25 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef; |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 29 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf; |
| 30 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList; |
Vinod Kumar S | 427d293 | 2016-04-20 13:02:58 +0530 | [diff] [blame] | 31 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 32 | /*- |
| 33 | * Reference RFC 6020. |
| 34 | * |
| 35 | * The "uses" statement is used to reference a "grouping" definition. It takes |
| 36 | * one argument, which is the name of the grouping. |
| 37 | * |
| 38 | * The effect of a "uses" reference to a grouping is that the nodes defined by |
| 39 | * the grouping are copied into the current schema tree, and then updated |
| 40 | * according to the "refine" and "augment" statements. |
| 41 | * |
| 42 | * The identifiers defined in the grouping are not bound to a namespace until |
| 43 | * the contents of the grouping are added to the schema tree via a "uses" |
| 44 | * statement that does not appear inside a "grouping" statement, at which point |
| 45 | * they are bound to the namespace of the current module. |
| 46 | * |
| 47 | * The uses's sub-statements |
| 48 | * |
| 49 | * +--------------+---------+-------------+------------------+ |
| 50 | * | substatement | section | cardinality |data model mapping| |
| 51 | * +--------------+---------+-------------+------------------+ |
| 52 | * | augment | 7.15 | 0..1 | -child nodes | |
| 53 | * | description | 7.19.3 | 0..1 | -string | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 54 | * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 55 | * | refine | 7.12.2 | 0..1 | -TODO | |
| 56 | * | reference | 7.19.4 | 0..1 | -string | |
| 57 | * | status | 7.19.2 | 0..1 | -YangStatus | |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 58 | * | when | 7.19.5 | 0..1 | -YangWhen | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 59 | * +--------------+---------+-------------+------------------+ |
| 60 | */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 61 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 62 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 63 | * Represents data model node to maintain information defined in YANG uses. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 64 | */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 65 | public class YangUses |
| 66 | extends YangNode |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 67 | implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder, |
| 68 | YangIfFeatureHolder { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 69 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 70 | private static final long serialVersionUID = 806201617L; |
| 71 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 72 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 73 | * YANG node identifier. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 74 | */ |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 75 | private YangNodeIdentifier nodeIdentifier; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 76 | |
| 77 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 78 | * Referred group. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 79 | */ |
| 80 | private YangGrouping refGroup; |
| 81 | |
| 82 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 83 | * Description of YANG uses. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 84 | */ |
| 85 | private String description; |
| 86 | |
| 87 | /** |
| 88 | * YANG reference. |
| 89 | */ |
| 90 | private String reference; |
| 91 | |
| 92 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 93 | * Status of YANG uses. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 94 | */ |
| 95 | private YangStatusType status; |
| 96 | |
| 97 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 98 | * When data of the node. |
| 99 | */ |
| 100 | private YangWhen when; |
| 101 | |
| 102 | /** |
| 103 | * List of if-feature. |
| 104 | */ |
| 105 | private List<YangIfFeature> ifFeatureList; |
| 106 | |
| 107 | /** |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 108 | * Status of resolution. If completely resolved enum value is "RESOLVED", |
| 109 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef |
| 110 | * is added to uses/type but it's not resolved value of enum should be |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 111 | * "INTRA_FILE_RESOLVED". |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 112 | */ |
| 113 | private ResolvableStatus resolvableStatus; |
| 114 | |
| 115 | /** |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 116 | * Effective list of nodes of grouping that needs to replicated at YANG uses. |
| 117 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 118 | private List<YangNode> resolvedGroupingNodes; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Effective list of leaves of grouping that needs to replicated at YANG uses. |
| 122 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 123 | private List<List<YangLeaf>> resolvedGroupingLeaves; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Effective list of leaf lists of grouping that needs to replicated at YANG uses. |
| 127 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 128 | private List<List<YangLeafList>> resolvedGroupingLeafLists; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 129 | |
| 130 | /** |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 131 | * Effective list of leaf lists of grouping that needs to replicated at YANG uses. |
| 132 | */ |
| 133 | private List<YangEntityToResolveInfoImpl> entityToResolveInfoList; |
| 134 | |
| 135 | /** |
| 136 | * Current grouping depth for uses. |
| 137 | */ |
| 138 | private int currentGroupingDepth; |
| 139 | |
| 140 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 141 | * Creates an YANG uses node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 142 | */ |
| 143 | public YangUses() { |
| 144 | super(YangNodeType.USES_NODE); |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 145 | nodeIdentifier = new YangNodeIdentifier(); |
| 146 | resolvableStatus = ResolvableStatus.UNRESOLVED; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 147 | resolvedGroupingNodes = new LinkedList<YangNode>(); |
| 148 | resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>(); |
| 149 | resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>(); |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 153 | * Returns the list of entity to resolve. |
| 154 | * |
| 155 | * @return the list of entity to resolve |
| 156 | */ |
| 157 | public List<YangEntityToResolveInfoImpl> getEntityToResolveInfoList() { |
| 158 | return entityToResolveInfoList; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Sets the list of entity to resolve. |
| 163 | * |
| 164 | * @param entityToResolveInfoList the list of entity to resolve |
| 165 | */ |
| 166 | public void setEntityToResolveInfoList(List<YangEntityToResolveInfoImpl> entityToResolveInfoList) { |
| 167 | this.entityToResolveInfoList = entityToResolveInfoList; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Adds an entity to resolve in list. |
| 172 | * |
| 173 | * @param entityToResolve entity to resolved |
| 174 | * @throws DataModelException a violation of data model rules |
| 175 | */ |
| 176 | public void addEntityToResolve(YangEntityToResolveInfoImpl entityToResolve) |
| 177 | throws DataModelException { |
| 178 | if (getEntityToResolveInfoList() == null) { |
| 179 | setEntityToResolveInfoList(new LinkedList<YangEntityToResolveInfoImpl>()); |
| 180 | } |
| 181 | getEntityToResolveInfoList().add(entityToResolve); |
| 182 | } |
| 183 | |
| 184 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 185 | * Returns the referred group. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 186 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 187 | * @return the referred group |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 188 | */ |
| 189 | public YangGrouping getRefGroup() { |
| 190 | return refGroup; |
| 191 | } |
| 192 | |
| 193 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 194 | * Sets the referred group. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 195 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 196 | * @param refGroup the referred group |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 197 | */ |
| 198 | public void setRefGroup(YangGrouping refGroup) { |
| 199 | this.refGroup = refGroup; |
| 200 | } |
| 201 | |
| 202 | /** |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 203 | * Returns the when. |
| 204 | * |
| 205 | * @return the when |
| 206 | */ |
| 207 | @Override |
| 208 | public YangWhen getWhen() { |
| 209 | return when; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Sets the when. |
| 214 | * |
| 215 | * @param when the when to set |
| 216 | */ |
| 217 | @Override |
| 218 | public void setWhen(YangWhen when) { |
| 219 | this.when = when; |
| 220 | } |
| 221 | |
| 222 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 223 | * Returns the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 224 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 225 | * @return the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 226 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 227 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 228 | public String getDescription() { |
| 229 | return description; |
| 230 | } |
| 231 | |
| 232 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 233 | * Sets the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 234 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 235 | * @param description set the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 236 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 237 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 238 | public void setDescription(String description) { |
| 239 | this.description = description; |
| 240 | } |
| 241 | |
| 242 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 243 | * Returns the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 244 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 245 | * @return the reference |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 246 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 247 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 248 | public String getReference() { |
| 249 | return reference; |
| 250 | } |
| 251 | |
| 252 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 253 | * Sets the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 254 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 255 | * @param reference the reference to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 256 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 257 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 258 | public void setReference(String reference) { |
| 259 | this.reference = reference; |
| 260 | } |
| 261 | |
| 262 | /** |
Gaurav Agrawal | bd80447 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 263 | * Returns the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 264 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 265 | * @return the status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 266 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 267 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 268 | public YangStatusType getStatus() { |
| 269 | return status; |
| 270 | } |
| 271 | |
| 272 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 273 | * Sets the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 274 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 275 | * @param status the status to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 276 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 277 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 278 | public void setStatus(YangStatusType status) { |
| 279 | this.status = status; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Returns the type of the data. |
| 284 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 285 | * @return returns USES_DATA |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 286 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 287 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 288 | public YangConstructType getYangConstructType() { |
| 289 | return YangConstructType.USES_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 293 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 294 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 295 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 296 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 297 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 298 | public void validateDataOnEntry() |
| 299 | throws DataModelException { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 300 | // TODO auto-generated method stub, to be implemented by parser |
| 301 | } |
| 302 | |
| 303 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 304 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 305 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 306 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 307 | */ |
Bharat saraswal | 594bc6d | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 308 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 309 | public void validateDataOnExit() |
| 310 | throws DataModelException { |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 311 | // TODO auto-generated method stub, to be implemented by parser |
| 312 | } |
| 313 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 314 | @Override |
| 315 | public String getName() { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 316 | return nodeIdentifier.getName(); |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 317 | } |
| 318 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 319 | @Override |
| 320 | public void setName(String name) { |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 321 | nodeIdentifier.setName(name); |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 322 | } |
| 323 | |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 324 | /** |
| 325 | * Returns node identifier. |
| 326 | * |
| 327 | * @return node identifier |
| 328 | */ |
| 329 | public YangNodeIdentifier getNodeIdentifier() { |
| 330 | return nodeIdentifier; |
| 331 | } |
| 332 | |
| 333 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 334 | * Sets node identifier. |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 335 | * |
| 336 | * @param nodeIdentifier the node identifier |
| 337 | */ |
| 338 | public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) { |
| 339 | this.nodeIdentifier = nodeIdentifier; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Returns prefix associated with uses. |
| 344 | * |
| 345 | * @return prefix associated with uses |
| 346 | */ |
| 347 | public String getPrefix() { |
| 348 | return nodeIdentifier.getPrefix(); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Get prefix associated with uses. |
| 353 | * |
| 354 | * @param prefix prefix associated with uses |
| 355 | */ |
| 356 | public void setPrefix(String prefix) { |
| 357 | nodeIdentifier.setPrefix(prefix); |
| 358 | } |
| 359 | |
| 360 | @Override |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 361 | public Object resolve() |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 362 | throws DataModelException { |
Vinod Kumar S | 427d293 | 2016-04-20 13:02:58 +0530 | [diff] [blame] | 363 | |
| 364 | YangGrouping referredGrouping = getRefGroup(); |
| 365 | |
| 366 | if (referredGrouping == null) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 367 | throw new DataModelException("YANG uses linker error, cannot resolve uses"); |
Vinod Kumar S | 427d293 | 2016-04-20 13:02:58 +0530 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | YangNode usesParentNode = getParentNodeInGenCode(this); |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 371 | if (!(usesParentNode instanceof YangLeavesHolder) |
| 372 | || !(usesParentNode instanceof CollisionDetector)) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 373 | throw new DataModelException("YANG uses holder construct is wrong"); |
Vinod Kumar S | 427d293 | 2016-04-20 13:02:58 +0530 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 377 | if (referredGrouping.getListOfLeaf() != null) { |
| 378 | for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { |
| 379 | YangLeaf clonedLeaf = null; |
| 380 | try { |
| 381 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(), |
| 382 | YangConstructType.LEAF_DATA); |
| 383 | clonedLeaf = leaf.clone(); |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 384 | if (getCurrentGroupingDepth() == 0) { |
| 385 | YangEntityToResolveInfoImpl resolveInfo = resolveLeafrefUnderGroupingForLeaf(clonedLeaf, |
| 386 | usesParentLeavesHolder, this); |
| 387 | if (resolveInfo != null) { |
| 388 | addEntityToResolve(resolveInfo); |
| 389 | } |
| 390 | } |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 391 | } catch (CloneNotSupportedException | DataModelException e) { |
| 392 | throw new DataModelException(e.getMessage()); |
| 393 | } |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 394 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 395 | clonedLeaf.setContainedIn(usesParentLeavesHolder); |
| 396 | usesParentLeavesHolder.addLeaf(clonedLeaf); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 397 | } |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 398 | } |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 399 | if (referredGrouping.getListOfLeafList() != null) { |
| 400 | for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { |
| 401 | YangLeafList clonedLeafList = null; |
| 402 | try { |
| 403 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(), |
| 404 | YangConstructType.LEAF_LIST_DATA); |
| 405 | clonedLeafList = leafList.clone(); |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 406 | if (getCurrentGroupingDepth() == 0) { |
| 407 | YangEntityToResolveInfoImpl resolveInfo = |
| 408 | resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder); |
| 409 | if (resolveInfo != null) { |
| 410 | addEntityToResolve(resolveInfo); |
| 411 | } |
| 412 | } |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 413 | } catch (CloneNotSupportedException | DataModelException e) { |
| 414 | throw new DataModelException(e.getMessage()); |
| 415 | } |
| 416 | |
| 417 | clonedLeafList.setContainedIn(usesParentLeavesHolder); |
| 418 | usesParentLeavesHolder.addLeafList(clonedLeafList); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | try { |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 423 | YangNode.cloneSubTree(referredGrouping, usesParentNode, this); |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame] | 424 | } catch (DataModelException e) { |
| 425 | throw new DataModelException(e.getMessage()); |
| 426 | } |
| 427 | updateClonedLeavesUnionEnumRef(usesParentLeavesHolder); |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 428 | return getEntityToResolveInfoList(); |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 429 | } |
| 430 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 431 | /** |
| 432 | * Clone the resolved uses contained in grouping to the uses of grouping. |
| 433 | * |
| 434 | * @param usesInGrouping resolved uses in grouping |
| 435 | * @param usesHolder holder of uses |
| 436 | */ |
| 437 | private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping, |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 438 | YangLeavesHolder usesHolder) throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 439 | for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 440 | addNodeOfGrouping(usesResolvedNode); |
| 441 | } |
| 442 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 443 | for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 444 | addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder)); |
| 445 | } |
| 446 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 447 | for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 448 | addListOfLeafListOfGrouping( |
| 449 | cloneListOfLeafList(listOfLeafLists, usesHolder)); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Clone the list of leaves and return the cloned list leaves. |
| 455 | * |
| 456 | * @param listOfLeaves list of leaves to be cloned |
| 457 | * @param usesParentNode parent of the cloned location |
| 458 | * @return cloned list of leaves |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 459 | * @throws DataModelException a violation in data model rule |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 460 | */ |
| 461 | private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves, |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 462 | YangLeavesHolder usesParentNode) throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 463 | if (listOfLeaves == null || listOfLeaves.size() == 0) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 464 | throw new DataModelException("No leaves to clone"); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>(); |
| 468 | for (YangLeaf leaf : listOfLeaves) { |
| 469 | YangLeaf clonedLeaf; |
| 470 | try { |
| 471 | ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(), |
| 472 | YangConstructType.LEAF_DATA); |
| 473 | clonedLeaf = leaf.clone(); |
| 474 | } catch (CloneNotSupportedException | DataModelException e) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 475 | throw new DataModelException(e.getMessage()); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | clonedLeaf.setContainedIn(usesParentNode); |
| 479 | newLeavesList.add(clonedLeaf); |
| 480 | } |
| 481 | |
| 482 | return newLeavesList; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Clone the list of leaf list. |
| 487 | * |
| 488 | * @param listOfLeafList list of leaf list that needs to be cloned |
| 489 | * @param usesParentNode parent of uses |
| 490 | * @return cloned list of leaf list |
| 491 | */ |
| 492 | private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList, |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 493 | YangLeavesHolder usesParentNode) throws DataModelException { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 494 | if (listOfLeafList == null || listOfLeafList.size() == 0) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 495 | throw new DataModelException("No leaf lists to clone"); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>(); |
| 499 | for (YangLeafList leafList : listOfLeafList) { |
| 500 | YangLeafList clonedLeafList; |
| 501 | try { |
| 502 | ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(), |
| 503 | YangConstructType.LEAF_LIST_DATA); |
| 504 | clonedLeafList = leafList.clone(); |
| 505 | } catch (CloneNotSupportedException | DataModelException e) { |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 506 | throw new DataModelException(e.getMessage()); |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | clonedLeafList.setContainedIn(usesParentNode); |
| 510 | newListOfLeafList.add(clonedLeafList); |
| 511 | } |
| 512 | |
| 513 | return newListOfLeafList; |
| 514 | } |
| 515 | |
Gaurav Agrawal | d9d6cc8 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 516 | @Override |
| 517 | public ResolvableStatus getResolvableStatus() { |
| 518 | return resolvableStatus; |
| 519 | } |
| 520 | |
| 521 | @Override |
| 522 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
| 523 | this.resolvableStatus = resolvableStatus; |
| 524 | } |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 525 | |
| 526 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 527 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 528 | throws DataModelException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 529 | detectCollidingChildUtil(identifierName, dataType, this); |
| 530 | } |
| 531 | |
| 532 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 533 | public void detectSelfCollision(String identifierName, YangConstructType dataType) |
| 534 | throws DataModelException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 535 | |
| 536 | if (getName().equals(identifierName)) { |
| 537 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \"" |
| 538 | + getName() + "\""); |
| 539 | } |
| 540 | } |
| 541 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 542 | /** |
| 543 | * Adds the node under grouping to the effective uses resolved info. |
| 544 | * |
| 545 | * @param nodeInGrouping node defined under grouping which needs to be copied in |
| 546 | * the context of uses |
| 547 | */ |
| 548 | public void addNodeOfGrouping(YangNode nodeInGrouping) { |
| 549 | resolvedGroupingNodes.add(nodeInGrouping); |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Returns the effective list of nodes added due to uses linking. |
| 554 | * |
| 555 | * @return effective list of nodes added due to uses linking |
| 556 | */ |
| 557 | public List<YangNode> getUsesResolvedNodeList() { |
| 558 | return resolvedGroupingNodes; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Adds the leaves under grouping to the effective uses resolved info. |
| 563 | * |
| 564 | * @param leavesInGrouping Leaves defined under grouping which needs to be copied in |
| 565 | * the context of uses |
| 566 | */ |
| 567 | public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) { |
| 568 | resolvedGroupingLeaves.add(leavesInGrouping); |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Returns the effective list of Leaves added due to uses linking. |
| 573 | * |
| 574 | * @return effective list of Leaves added due to uses linking |
| 575 | */ |
| 576 | public List<List<YangLeaf>> getUsesResolvedLeavesList() { |
| 577 | return resolvedGroupingLeaves; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Adds the leaf-lists under grouping to the effective uses resolved info. |
| 582 | * |
| 583 | * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in |
| 584 | * the context of uses |
| 585 | */ |
| 586 | public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) { |
| 587 | resolvedGroupingLeafLists.add(leafListsInGrouping); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Returns the effective list of Leaves added due to uses linking. |
| 592 | * |
| 593 | * @return effective list of Leaves added due to uses linking |
| 594 | */ |
| 595 | public List<List<YangLeafList>> getUsesResolvedListOfLeafList() { |
| 596 | return resolvedGroupingLeafLists; |
| 597 | } |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 598 | |
| 599 | @Override |
| 600 | public List<YangIfFeature> getIfFeatureList() { |
| 601 | return ifFeatureList; |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 606 | if (getIfFeatureList() == null) { |
| 607 | setIfFeatureList(new LinkedList<>()); |
| 608 | } |
| 609 | getIfFeatureList().add(ifFeature); |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 614 | this.ifFeatureList = ifFeatureList; |
| 615 | } |
janani b | 23ccc31 | 2016-07-14 19:35:22 +0530 | [diff] [blame^] | 616 | |
| 617 | public void setCurrentGroupingDepth(int currentGroupingDepth) { |
| 618 | this.currentGroupingDepth = currentGroupingDepth; |
| 619 | } |
| 620 | |
| 621 | public int getCurrentGroupingDepth() { |
| 622 | return currentGroupingDepth; |
| 623 | } |
| 624 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 625 | } |