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