blob: 3a9757179ce0f220573bc44d0ce3dbe3516adf97 [file] [log] [blame]
Vinod Kumar S67e7be62016-02-11 20:13:28 +05301/*
2 * Copyright 2016 Open Networking Laboratory
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
17package org.onosproject.yangutils.datamodel;
18
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053019import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20
Bharat saraswal870c56f2016-02-20 21:57:16 +053021import java.io.IOException;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053022import java.util.LinkedList;
23import java.util.List;
24
25import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
26import org.onosproject.yangutils.parser.Parsable;
Bharat saraswal870c56f2016-02-20 21:57:16 +053027import org.onosproject.yangutils.translator.CachedFileHandle;
28import org.onosproject.yangutils.translator.GeneratedFileType;
29import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
Bharat saraswal4bf8b152016-02-25 02:26:43 +053030import org.onosproject.yangutils.utils.UtilConstants;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053031import org.onosproject.yangutils.utils.YangConstructType;
Bharat saraswal870c56f2016-02-20 21:57:16 +053032import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
Vinod Kumar S67e7be62016-02-11 20:13:28 +053033/*-
34 * Reference RFC 6020.
35 *
36 * The "container" statement is used to define an interior data node in the
37 * schema tree. It takes one argument, which is an identifier, followed by a
38 * block of sub-statements that holds detailed container information.
39 *
40 * A container node does not have a value, but it has a list of child nodes in
41 * the data tree. The child nodes are defined in the container's sub-statements.
42 *
43 * Containers with Presence
44 *
45 * YANG supports two styles of containers, those that exist only for organizing
46 * the hierarchy of data nodes, and those whose presence in the configuration
47 * has an explicit meaning.
48 *
49 * In the first style, the container has no meaning of its own, existing only to
50 * contain child nodes. This is the default style.
51 *
52 * For example, the set of scrambling options for Synchronous Optical Network
53 * (SONET) interfaces may be placed inside a "scrambling" container to enhance
54 * the organization of the configuration hierarchy, and to keep these nodes
55 * together. The "scrambling" node itself has no meaning, so removing the node
56 * when it becomes empty relieves the user from performing this task.
57 *
58 * In the second style, the presence of the container itself is configuration
59 * data, representing a single bit of configuration data. The container acts as
60 * both a configuration knob and a means of organizing related configuration.
61 * These containers are explicitly created and deleted.
62 *
63 * YANG calls this style a "presence container" and it is indicated using the
64 * "presence" statement, which takes as its argument a text string indicating
65 * what the presence of the node means.
66 *
67 * The container's Substatements
68 *
69 * +--------------+---------+-------------+------------------+
70 * | substatement | section | cardinality |data model mapping|
71 * +--------------+---------+-------------+------------------+
72 * | anyxml | 7.10 | 0..n | -not supported |
73 * | choice | 7.9 | 0..n | -child nodes |
74 * | config | 7.19.1 | 0..1 | -boolean |
75 * | container | 7.5 | 0..n | -child nodes |
76 * | description | 7.19.3 | 0..1 | -string |
77 * | grouping | 7.11 | 0..n | -child nodes |
78 * | if-feature | 7.18.2 | 0..n | -TODO |
79 * | leaf | 7.6 | 0..n | -YangLeaf |
80 * | leaf-list | 7.7 | 0..n | -YangLeafList |
81 * | list | 7.8 | 0..n | -child nodes |
82 * | must | 7.5.3 | 0..n | -TODO |
83 * | presence | 7.5.5 | 0..1 | -boolean |
84 * | reference | 7.19.4 | 0..1 | -string |
85 * | status | 7.19.2 | 0..1 | -YangStatus |
86 * | typedef | 7.3 | 0..n | -child nodes |
87 * | uses | 7.12 | 0..n | -child nodes |
88 * | when | 7.19.5 | 0..1 | -TODO |
89 * +--------------+---------+-------------+------------------+
90 */
91
92/**
93 * Data model node to maintain information defined in YANG container.
94 */
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053095public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
Vinod Kumar S67e7be62016-02-11 20:13:28 +053096
97 /**
98 * Name of the container.
99 */
100 private String name;
101
102 /**
103 * If container maintains config data.
104 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530105 private Boolean isConfig;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530106
107 /**
108 * Description of container.
109 */
110 private String description;
111
112 /**
113 * List of leaves contained.
114 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530115 private List<YangLeaf> listOfLeaf;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530116
117 /**
118 * List of leaf-lists contained.
119 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530120 private List<YangLeafList> listOfLeafList;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530121
122 /**
123 * If it is a presence container, then the textual documentation of presence
124 * usage.
125 */
126 private String presence;
127
128 /**
129 * Reference of the module.
130 */
131 private String reference;
132
133 /**
134 * Status of the node.
135 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530136 private YangStatusType status = YangStatusType.CURRENT;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530137
138 /**
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530139 * Package of the generated java code.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530140 */
141 private String pkg;
142
143 /**
144 * Cached Java File Handle.
145 */
146 private CachedFileHandle fileHandle;
147
148 /**
149 * Create a container node.
150 */
151 public YangContainer() {
152 super(YangNodeType.CONTAINER_NODE);
153 }
154
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530155 /**
156 * Get the YANG name of container.
157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @return the name of container as defined in YANG file
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530159 */
160 @Override
161 public String getName() {
162 return name;
163 }
164
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530165 /**
166 * Set the YANG name of container.
167 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530168 * @param name the name of container as defined in YANG file
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530169 */
170 @Override
171 public void setName(String name) {
172 this.name = name;
173 }
174
175 /**
176 * Get the config flag.
177 *
178 * @return the isConfig
179 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530180 public Boolean isConfig() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530181 return isConfig;
182 }
183
184 /**
185 * Set the config flag.
186 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530187 * @param isCfg the config flag
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530188 */
189 public void setConfig(boolean isCfg) {
190 isConfig = isCfg;
191 }
192
193 /**
194 * Get the description.
195 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530196 * @return the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530197 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530198 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530199 public String getDescription() {
200 return description;
201 }
202
203 /**
204 * Set the description.
205 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530206 * @param description set the description
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530207 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530208 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530209 public void setDescription(String description) {
210 this.description = description;
211 }
212
213 /**
214 * Get the list of leaves.
215 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530216 * @return the list of leaves
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530217 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530218 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530219 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530220 return listOfLeaf;
221 }
222
223 /**
224 * Set the list of leaves.
225 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530226 * @param leafsList the list of leaf to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530227 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530228 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530229 listOfLeaf = leafsList;
230 }
231
232 /**
233 * Add a leaf.
234 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530235 * @param leaf the leaf to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530236 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530237 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530238 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530239 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530240 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530241 }
242
243 getListOfLeaf().add(leaf);
244 }
245
246 /**
247 * Get the list of leaf-list.
248 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530249 * @return the list of leaf-list
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530250 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530251 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530252 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530253 return listOfLeafList;
254 }
255
256 /**
257 * Set the list of leaf-list.
258 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530259 * @param listOfLeafList the list of leaf-list to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530260 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530261 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530262 this.listOfLeafList = listOfLeafList;
263 }
264
265 /**
266 * Add a leaf-list.
267 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530268 * @param leafList the leaf-list to be added
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530271 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530272 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530273 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530274 }
275
276 getListOfLeafList().add(leafList);
277 }
278
279 /**
280 * Get the presence string if present.
281 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530282 * @return the presence
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530283 */
284 public String getPresence() {
285 return presence;
286 }
287
288 /**
289 * Set the presence string.
290 *
291 * @param presence the presence flag
292 */
293 public void setPresence(String presence) {
294 this.presence = presence;
295 }
296
297 /**
298 * Get the textual reference.
299 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530300 * @return the reference
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530301 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530302 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530303 public String getReference() {
304 return reference;
305 }
306
307 /**
308 * Set the textual reference.
309 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530310 * @param reference the reference to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530311 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530312 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530313 public void setReference(String reference) {
314 this.reference = reference;
315 }
316
317 /**
318 * Get the status.
319 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530320 * @return the status
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530321 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530322 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530323 public YangStatusType getStatus() {
324 return status;
325 }
326
327 /**
328 * Set the status.
329 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530330 * @param status the status to set
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530331 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530332 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530333 public void setStatus(YangStatusType status) {
334 this.status = status;
335 }
336
337 /**
338 * Get the cached file handle.
339 *
340 * @return the fileHandle
341 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530342 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530343 public CachedFileHandle getFileHandle() {
344 return fileHandle;
345 }
346
347 /**
348 * Set the cached file handle.
349 *
350 * @param handle the fileHandle to set
351 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530352 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530353 public void setFileHandle(CachedFileHandle handle) {
354 fileHandle = handle;
355 }
356
357 /**
358 * Returns the type of the data.
359 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530360 * @return returns CONTAINER_DATA
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530361 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530362 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530363 public YangConstructType getYangConstructType() {
364 return YangConstructType.CONTAINER_DATA;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530365 }
366
367 /**
368 * Validate the data on entering the corresponding parse tree node.
369 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530370 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530371 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530372 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530373 public void validateDataOnEntry() throws DataModelException {
374 // TODO auto-generated method stub, to be implemented by parser
375 }
376
377 /**
378 * Validate the data on exiting the corresponding parse tree node.
379 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530380 * @throws DataModelException a violation of data model rules
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530381 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530382 @Override
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530383 public void validateDataOnExit() throws DataModelException {
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530384 List<YangLeaf> leaves = getListOfLeaf();
385 List<YangLeafList> leafLists = getListOfLeafList();
386
387 setDefaultConfigValueToChild(leaves, leafLists);
388 validateConfig(leaves, leafLists);
389 }
390
391 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530392 * Sets the config's value to all leaf if leaf's config statement is not
393 * specified.
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530394 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530395 * @param leaves list of leaf attributes of container
396 * @param leafLists list of leaf-list attributes of container
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530397 */
398 private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
399
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530400 /*
401 * If "config" is not specified, the default is the same as the parent
402 * schema node's "config" value.
403 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530404 if (leaves != null) {
405 for (YangLeaf leaf : leaves) {
406 if (leaf.isConfig() == null) {
407 leaf.setConfig(isConfig);
408 }
409 }
410 }
411
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530412 /*
413 * If "config" is not specified, the default is the same as the parent
414 * schema node's "config" value.
415 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530416 if (leafLists != null) {
417 for (YangLeafList leafList : leafLists) {
418 if (leafList.isConfig() == null) {
419 leafList.setConfig(isConfig);
420 }
421 }
422 }
423 }
424
425 /**
426 * Validates config statement of container.
427 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530428 * @param leaves list of leaf attributes of container
429 * @param leafLists list of leaf-list attributes of container
430 * @throws DataModelException a violation of data model rules
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530431 */
432 private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
433
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530434 /*
435 * If a node has "config" set to "false", no node underneath it can have
436 * "config" set to "true".
437 */
Vidyashree Ramaf4c617c2016-02-24 12:28:22 +0530438 if ((!isConfig) && (leaves != null)) {
439 for (YangLeaf leaf : leaves) {
440 if (leaf.isConfig()) {
441 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
442 "it can have \"config\" set to \"true\".");
443 }
444 }
445 }
446
447 if ((!isConfig) && (leafLists != null)) {
448 for (YangLeafList leafList : leafLists) {
449 if (leafList.isConfig()) {
450 throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
451 "it can have \"config\" set to \"true\".");
452 }
453 }
454 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530455 }
456
457 /**
458 * Get the mapped java package.
459 *
460 * @return the java package
461 */
462 @Override
463 public String getPackage() {
464 return pkg;
465 }
466
467 /**
468 * Set the mapped java package.
469 *
470 * @param pcg the package to set
471 */
472 @Override
473 public void setPackage(String pcg) {
474 pkg = pcg;
475 }
476
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530477 /**
478 * Generate the java code corresponding to YANG container.
479 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530480 * @param codeGenDir code generation directory
481 * @throws IOException when fails to generate the source files.
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530482 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530483 @Override
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530484 public void generateJavaCodeEntry(String codeGenDir) throws IOException {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530485 YangNode parent = getParent();
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530486 String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName());
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530487
488 contPkg = JavaIdentifierSyntax.getCamelCase(contPkg).toLowerCase();
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530489 setPackage(contPkg);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530490
491 CachedFileHandle handle = null;
492 try {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530493 FileSystemUtil.createPackage(codeGenDir + getPackage(), parent.getName() + UtilConstants.CHILDREN);
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530494 handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
495 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530496 handle.setRelativeFilePath(getPackage().replace(".", "/"));
497 handle.setCodeGenFilePath(codeGenDir);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530498 } catch (IOException e) {
499 throw new IOException("Failed to create the source files.");
500 }
501 setFileHandle(handle);
Bharat saraswal4bf8b152016-02-25 02:26:43 +0530502
503 addLeavesAttributes();
504 addLeafListAttributes();
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530505 addAttributeInParent();
506 }
507
508 /**
509 * Adds current node attribute to parent file.
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530510 */
511 private void addAttributeInParent() {
512 if (getParent() != null) {
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530513 getParent().getFileHandle().addAttributeInfo(null, getName(), false);
514 }
515 }
516
517 @Override
518 public void generateJavaCodeExit() throws IOException {
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530519 getFileHandle().close();
520 return;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530521 }
522
523 /**
524 * Adds leaf attributes in generated files.
525 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530526 private void addLeavesAttributes() {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530527
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530528 List<YangLeaf> leaves = getListOfLeaf();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530529 if (leaves != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530530 for (YangLeaf leaf : leaves) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530531 getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
532 }
533 }
534 }
535
536 /**
537 * Adds leaf list's attributes in generated files.
538 */
539 private void addLeafListAttributes() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530540 List<YangLeafList> leavesList = getListOfLeafList();
Bharat saraswal870c56f2016-02-20 21:57:16 +0530541 if (leavesList != null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530542 for (YangLeafList leafList : leavesList) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530543 getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
544 }
545 }
546 return;
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530547 }
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530548
549 @Override
550 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
551 // Asks helper to detect colliding child.
552 detectCollidingChildUtil(identifierName, dataType, this);
553 }
554
555 @Override
556 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
557 if (this.getName().equals(identifierName)) {
558 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
559 + this.getName() + "\"");
560 }
561 }
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530562}