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