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