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