blob: 671635e8415565d42750df2a7fab8a504bba9911 [file] [log] [blame]
Vinod Kumar S9f26ae52016-03-23 15:30:27 +05301/*
Brian O'Connor0f7908b2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S9f26ae52016-03-23 15:30:27 +05303 *
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.translator.tojava;
18
19import java.io.IOException;
Bharat saraswal8beac342016-08-04 02:00:03 +053020import java.util.ArrayList;
21import java.util.List;
Bharat saraswale304c252016-08-16 20:56:20 +053022
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
Vidyashree Ramaa89bdd32016-07-08 20:45:41 +053025import org.onosproject.yangutils.datamodel.TraversalType;
Bharat saraswal8beac342016-08-04 02:00:03 +053026import org.onosproject.yangutils.datamodel.YangAugment;
27import org.onosproject.yangutils.datamodel.YangCase;
28import org.onosproject.yangutils.datamodel.YangChoice;
Bharat saraswalaab24b92016-08-02 18:43:16 +053029import org.onosproject.yangutils.datamodel.YangInput;
Bharat saraswale50edca2016-08-05 01:58:25 +053030import org.onosproject.yangutils.datamodel.YangLeaf;
31import org.onosproject.yangutils.datamodel.YangLeafList;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053032import org.onosproject.yangutils.datamodel.YangNode;
Bharat saraswalaab24b92016-08-02 18:43:16 +053033import org.onosproject.yangutils.datamodel.YangNodeType;
34import org.onosproject.yangutils.datamodel.YangOutput;
Bharat saraswal8beac342016-08-04 02:00:03 +053035import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Vidyashree Ramaa89bdd32016-07-08 20:45:41 +053036import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
Bharat saraswal780eca32016-04-05 12:45:45 +053037import org.onosproject.yangutils.translator.exception.TranslatorException;
Gaurav Agrawal9564b552016-08-12 12:00:23 +053038import org.onosproject.yangutils.utils.io.YangPluginConfig;
janani bb3be1332016-08-03 16:40:01 +053039
Vidyashree Ramaa89bdd32016-07-08 20:45:41 +053040import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
41import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
42import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
43import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
Bharat saraswal8beac342016-08-04 02:00:03 +053044import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
45import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
46import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentClassName;
47import static org.onosproject.yangutils.utils.UtilConstants.CASE;
48import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
Bharat saraswal64e7e232016-07-14 23:33:55 +053049import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053050
51/**
Vidyashree Rama02f115f2016-04-18 12:29:39 +053052 * Representation of java code generator based on application schema.
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053053 */
54public final class JavaCodeGeneratorUtil {
55
Bharat saraswale304c252016-08-16 20:56:20 +053056 private static final Log log = LogFactory.getLog(JavaCodeGeneratorUtil.class);
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053057 /**
Bharat saraswal780eca32016-04-05 12:45:45 +053058 * Current YANG node.
59 */
60 private static YangNode curNode;
61
62 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +053063 * Root node.
64 */
65 private static YangNode rootNode;
66
Bharat saraswale50edca2016-08-05 01:58:25 +053067 private static int calls = 0;
68
Bharat saraswal64e7e232016-07-14 23:33:55 +053069 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +053070 * Creates a java code generator utility object.
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053071 */
72 private JavaCodeGeneratorUtil() {
73 }
74
75 /**
Bharat saraswal780eca32016-04-05 12:45:45 +053076 * Returns current YANG node.
77 *
78 * @return current YANG node
79 */
80 public static YangNode getCurNode() {
81 return curNode;
82 }
83
84 /**
85 * Sets current YANG node.
86 *
87 * @param node current YANG node
88 */
Bharat saraswal780eca32016-04-05 12:45:45 +053089 public static void setCurNode(YangNode node) {
90 curNode = node;
91 }
92
93 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +053094 * Generates Java code files corresponding to the YANG schema.
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053095 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053096 * @param rootNode root node of the data model tree
janani b1c6acc42016-04-15 16:18:30 +053097 * @param yangPlugin YANG plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +053098 * @throws TranslatorException when fails to generate java code file the current node
99 * @throws IOException when fails to do IO operations
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530100 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530101 public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
Bharat saraswal64e7e232016-07-14 23:33:55 +0530102 throws TranslatorException, IOException {
Bharat saraswal780eca32016-04-05 12:45:45 +0530103
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530104 YangNode codeGenNode = rootNode;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530105 setRootNode(rootNode);
Bharat saraswal780eca32016-04-05 12:45:45 +0530106 TraversalType curTraversal = ROOT;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530107
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530108 while (codeGenNode != null) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530109 if (codeGenNode instanceof YangAugment) {
110 if (((YangAugment) codeGenNode).getAugmentedNode() instanceof YangChoice) {
111 addCaseNodeToChoiceTarget((YangAugment) codeGenNode);
112 }
113 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530114 if (curTraversal != PARENT) {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530115 if (!(codeGenNode instanceof JavaCodeGenerator)) {
116 throw new TranslatorException("Unsupported node to generate code");
117 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530118 setCurNode(codeGenNode);
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530119 try {
120 generateCodeEntry(codeGenNode, yangPlugin);
Gaurav Agrawal9564b552016-08-12 12:00:23 +0530121 codeGenNode.setNameSpaceAndAddToParentSchemaMap();
Vidyashree Ramaa89bdd32016-07-08 20:45:41 +0530122 } catch (InvalidNodeForTranslatorException e) {
123 if (codeGenNode.getNextSibling() != null) {
124 curTraversal = SIBILING;
125 codeGenNode = codeGenNode.getNextSibling();
126 } else {
127 curTraversal = PARENT;
128 codeGenNode = codeGenNode.getParent();
129 }
130 continue;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530131 } catch (Exception e) {
Bharat saraswale304c252016-08-16 20:56:20 +0530132 if (log.isDebugEnabled()) {
133 e.printStackTrace();
134 }
Bharat saraswal64e7e232016-07-14 23:33:55 +0530135 close(codeGenNode, yangPlugin);
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530136 throw new TranslatorException(e.getMessage());
137 }
138
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530139 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530140 if (curTraversal != PARENT && codeGenNode.getChild() != null) {
Bharat saraswal780eca32016-04-05 12:45:45 +0530141 curTraversal = CHILD;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530142 codeGenNode = codeGenNode.getChild();
143 } else if (codeGenNode.getNextSibling() != null) {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530144 try {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530145 generateCodeExit(codeGenNode, yangPlugin);
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530146 } catch (Exception e) {
Bharat saraswale304c252016-08-16 20:56:20 +0530147 if (log.isDebugEnabled()) {
148 e.printStackTrace();
149 }
Bharat saraswal64e7e232016-07-14 23:33:55 +0530150 close(codeGenNode, yangPlugin);
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530151 throw new TranslatorException(e.getMessage());
152 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530153 curTraversal = SIBILING;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530154 codeGenNode = codeGenNode.getNextSibling();
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530155 } else {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530156 try {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530157 generateCodeExit(codeGenNode, yangPlugin);
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530158 } catch (Exception e) {
Bharat saraswale304c252016-08-16 20:56:20 +0530159 if (log.isDebugEnabled()) {
160 e.printStackTrace();
161 }
Bharat saraswale50edca2016-08-05 01:58:25 +0530162 close(codeGenNode, yangPlugin);
163 throw new TranslatorException(e.getMessage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530164 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530165 curTraversal = PARENT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530166 codeGenNode = codeGenNode.getParent();
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530167 }
168 }
169 }
170
171 /**
172 * Generates the current nodes code snippet.
173 *
Bharat saraswal64e7e232016-07-14 23:33:55 +0530174 * @param codeGenNode current data model node for which the code needs to be generated
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530175 * @param yangPlugin YANG plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +0530176 * @throws TranslatorException when fails to generate java code file the current node
177 * @throws IOException when fails to do IO operations
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530178 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530179 private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
Bharat saraswal64e7e232016-07-14 23:33:55 +0530180 throws TranslatorException, IOException {
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530181
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530182 if (codeGenNode instanceof JavaCodeGenerator) {
183 ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530184 } else {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530185 close(codeGenNode, yangPlugin);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530186 throw new TranslatorException(
Bharat saraswal780eca32016-04-05 12:45:45 +0530187 "Generated data model node cannot be translated to target language code");
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530188 }
189 }
190
191 /**
192 * Generates the current nodes code target code from the snippet.
193 *
Bharat saraswal64e7e232016-07-14 23:33:55 +0530194 * @param codeGenNode current data model node for which the code needs to be generated
195 * @param pluginConfig plugin configurations
196 * @throws TranslatorException when fails to generate java code file the current node
197 * @throws IOException when fails to do IO operations
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530198 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530199 private static void generateCodeExit(YangNode codeGenNode, YangPluginConfig pluginConfig)
200 throws TranslatorException, IOException {
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530201
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530202 if (codeGenNode instanceof JavaCodeGenerator) {
203 ((JavaCodeGenerator) codeGenNode).generateCodeExit();
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530204 } else {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530205 close(codeGenNode, pluginConfig);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530206 throw new TranslatorException(
Bharat saraswal780eca32016-04-05 12:45:45 +0530207 "Generated data model node cannot be translated to target language code");
208 }
209 }
210
211 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530212 * Free other YANG nodes of data-model tree when error occurs while file generation of current node.
Bharat saraswal780eca32016-04-05 12:45:45 +0530213 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530214 private static void freeRestResources() {
Bharat saraswal780eca32016-04-05 12:45:45 +0530215
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530216 YangNode freedNode = getCurNode();
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530217 if (getCurNode() != null) {
218 YangNode tempNode = freedNode;
219 TraversalType curTraversal = ROOT;
Bharat saraswal780eca32016-04-05 12:45:45 +0530220
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530221 while (freedNode != tempNode.getParent()) {
Bharat saraswal780eca32016-04-05 12:45:45 +0530222
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530223 if (curTraversal != PARENT && freedNode.getChild() != null) {
224 curTraversal = CHILD;
225 freedNode = freedNode.getChild();
226 } else if (freedNode.getNextSibling() != null) {
227 curTraversal = SIBILING;
228 if (freedNode != tempNode) {
229 free(freedNode);
230 }
231 freedNode = freedNode.getNextSibling();
232 } else {
233 curTraversal = PARENT;
234 if (freedNode != tempNode) {
235 free(freedNode);
236 }
237 freedNode = freedNode.getParent();
Bharat saraswal780eca32016-04-05 12:45:45 +0530238 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530239 }
240 }
241 }
242
243 /**
244 * Free the current node.
245 *
246 * @param node YANG node
Bharat saraswal780eca32016-04-05 12:45:45 +0530247 */
Vidyashree Rama02f115f2016-04-18 12:29:39 +0530248 private static void free(YangNode node) {
Bharat saraswal780eca32016-04-05 12:45:45 +0530249
250 YangNode parent = node.getParent();
251 parent.setChild(null);
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530252
Bharat saraswal780eca32016-04-05 12:45:45 +0530253 if (node.getNextSibling() != null) {
254 parent.setChild(node.getNextSibling());
255 } else if (node.getPreviousSibling() != null) {
256 parent.setChild(node.getPreviousSibling());
257 }
258 node = null;
259 }
260
261 /**
262 * Delete Java code files corresponding to the YANG schema.
263 *
Bharat saraswal64e7e232016-07-14 23:33:55 +0530264 * @param rootNode root node of data-model tree
265 * @param yangPluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530266 * @throws IOException when fails to delete java code file the current node
Bharat saraswal780eca32016-04-05 12:45:45 +0530267 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530268 public static void translatorErrorHandler(YangNode rootNode, YangPluginConfig yangPluginConfig)
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530269 throws IOException {
Bharat saraswal780eca32016-04-05 12:45:45 +0530270
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530271 if (rootNode != null) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530272 //Free other resources where translator has failed.
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530273 freeRestResources();
Bharat saraswal780eca32016-04-05 12:45:45 +0530274
Bharat saraswal64e7e232016-07-14 23:33:55 +0530275 // Start removing all open files.
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530276 YangNode tempNode = rootNode;
277 setCurNode(tempNode.getChild());
278 TraversalType curTraversal = ROOT;
Bharat saraswal780eca32016-04-05 12:45:45 +0530279
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530280 while (tempNode != null) {
Bharat saraswal780eca32016-04-05 12:45:45 +0530281
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530282 if (curTraversal != PARENT) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530283 close(tempNode, yangPluginConfig);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530284 }
285 if (curTraversal != PARENT && tempNode.getChild() != null) {
286 curTraversal = CHILD;
287 tempNode = tempNode.getChild();
288 } else if (tempNode.getNextSibling() != null) {
289 curTraversal = SIBILING;
290 tempNode = tempNode.getNextSibling();
291 } else {
292 curTraversal = PARENT;
293 tempNode = tempNode.getParent();
294 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530295 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530296
297 freeRestResources();
Bharat saraswal780eca32016-04-05 12:45:45 +0530298 }
Bharat saraswal780eca32016-04-05 12:45:45 +0530299 }
300
301 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530302 * Closes all the current open file handles of node and delete all generated files.
Bharat saraswal780eca32016-04-05 12:45:45 +0530303 *
Bharat saraswal64e7e232016-07-14 23:33:55 +0530304 * @param node current YANG node
305 * @param yangPlugin plugin configurations
Bharat saraswal780eca32016-04-05 12:45:45 +0530306 * @throws IOException when fails to do IO operations
307 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530308 private static void close(YangNode node, YangPluginConfig yangPlugin)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530309 throws IOException {
Vidyashree Rama5daea742016-05-20 16:29:25 +0530310 if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
311 .getTempJavaCodeFragmentFiles() != null) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530312 ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530313 } else {
314
janani bb3be1332016-08-03 16:40:01 +0530315 if (getRootNode() != null) {
Bharat saraswale50edca2016-08-05 01:58:25 +0530316 JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) getRootNode()).getJavaFileInfo();
janani bb3be1332016-08-03 16:40:01 +0530317 if (javaFileInfo != null) {
318 searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() +
319 javaFileInfo.getPackageFilePath());
320 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +0530321 searchAndDeleteTempDir(yangPlugin.getCodeGenDir());
janani bb3be1332016-08-03 16:40:01 +0530322 }
Bharat saraswal64e7e232016-07-14 23:33:55 +0530323 }
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530324 }
325 }
Bharat saraswal64e7e232016-07-14 23:33:55 +0530326
327 /**
328 * Returns root node.
329 *
330 * @return root node
331 */
332 private static YangNode getRootNode() {
333 return rootNode;
334 }
335
336 /**
337 * Sets root node.
338 *
339 * @param rootNode root node
340 */
341 private static void setRootNode(YangNode rootNode) {
342 JavaCodeGeneratorUtil.rootNode = rootNode;
343 }
Bharat saraswalaab24b92016-08-02 18:43:16 +0530344
345 /**
346 * Searches child node in data model tree.
347 *
348 * @param parentNode parent node
349 * @param nodeType node type
350 * @param nodeName node name
351 * @return child node
352 */
353 public static YangNode searchYangNode(YangNode parentNode, YangNodeType nodeType, String nodeName) {
354 YangNode child = parentNode.getChild();
355 TraversalType curTraversal = ROOT;
356 if (child == null) {
janani bb3be1332016-08-03 16:40:01 +0530357 throw new IllegalArgumentException("Given parent node does not contain any child nodes");
Bharat saraswalaab24b92016-08-02 18:43:16 +0530358 }
359
360 while (child != null) {
361 if (curTraversal != PARENT) {
362 if (child instanceof YangInput || child instanceof YangOutput) {
363 if (child.getNodeType().equals(nodeType)) {
364 return child;
365 }
366 } else if (child.getName().equals(nodeName) && child.getNodeType().equals(nodeType)) {
367 return child;
368 }
369 }
370 if (curTraversal != PARENT && child.getChild() != null) {
371 curTraversal = CHILD;
372 child = child.getChild();
373 } else if (child.getNextSibling() != null) {
374 curTraversal = SIBILING;
375 child = child.getNextSibling();
376 } else {
377 curTraversal = PARENT;
378 child = child.getParent();
379 }
380 }
381 return null;
382 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530383
384 /**
385 * Adds a case node in augment when augmenting a choice node.
386 *
387 * @param augment augment node
388 */
389 private static void addCaseNodeToChoiceTarget(YangAugment augment) {
Bharat saraswale50edca2016-08-05 01:58:25 +0530390 calls++;
391 if (calls == 1) {
392 YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
Bharat saraswal8beac342016-08-04 02:00:03 +0530393
Bharat saraswale50edca2016-08-05 01:58:25 +0530394 YangPluginConfig pluginConfig = new YangPluginConfig();
395 javaCase.setName(getAugmentClassName(augment, pluginConfig) + getCapitalCase(CASE));
Bharat saraswal8beac342016-08-04 02:00:03 +0530396
Bharat saraswale50edca2016-08-05 01:58:25 +0530397 if (augment.getListOfLeaf() != null) {
398 for (YangLeaf leaf : augment.getListOfLeaf()) {
399 javaCase.addLeaf(leaf);
400 }
401 augment.getListOfLeaf().clear();
Bharat saraswal8beac342016-08-04 02:00:03 +0530402 }
Bharat saraswale50edca2016-08-05 01:58:25 +0530403 if (augment.getListOfLeafList() != null) {
404 for (YangLeafList leafList : augment.getListOfLeafList()) {
405 javaCase.addLeafList(leafList);
406 }
407 augment.getListOfLeafList().clear();
408 }
409 YangNode child = augment.getChild();
410 List<YangNode> childNodes = new ArrayList<>();
411 while (child != null) {
412 child.setParent(javaCase);
413 childNodes.add(child);
414 child = child.getNextSibling();
415 }
416 augment.setChild(null);
417 try {
418 augment.addChild(javaCase);
419 for (YangNode node : childNodes) {
420 node.setNextSibling(null);
421 node.setPreviousSibling(null);
422 javaCase.addChild(node);
423 }
424 } catch (DataModelException e) {
425 throw new TranslatorException("Failed to add child nodes to case node of augment " + augment.getName());
426 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530427 }
428 }
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530429}