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