blob: c3bd23ab1a7067f82f7d9ccb49124648ed126373 [file] [log] [blame]
Vidyashree Rama6a72b792016-03-29 12:00:42 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vidyashree Rama6a72b792016-03-29 12:00:42 +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.javamodel;
18
19import java.io.IOException;
Bharat saraswalcad0e652016-05-26 23:48:38 +053020import java.util.List;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053021
22import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
Gaurav Agrawal56527662016-04-20 15:49:17 +053023import org.onosproject.yangutils.datamodel.YangInput;
Bharat saraswalcad0e652016-05-26 23:48:38 +053024import org.onosproject.yangutils.datamodel.YangLeaf;
25import org.onosproject.yangutils.datamodel.YangLeafList;
26import org.onosproject.yangutils.datamodel.YangLeavesHolder;
Gaurav Agrawal56527662016-04-20 15:49:17 +053027import org.onosproject.yangutils.datamodel.YangNode;
28import org.onosproject.yangutils.datamodel.YangOutput;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053029import org.onosproject.yangutils.datamodel.YangRpc;
Bharat saraswalcad0e652016-05-26 23:48:38 +053030import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal4ca63712016-05-28 17:50:57 +053031import org.onosproject.yangutils.datamodel.YangUses;
Gaurav Agrawal56527662016-04-20 15:49:17 +053032import org.onosproject.yangutils.translator.exception.TranslatorException;
Gaurav Agrawal56527662016-04-20 15:49:17 +053033import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053034import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
Gaurav Agrawal56527662016-04-20 15:49:17 +053035import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053036import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053037import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053038import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053039import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
40import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
janani bde4ffab2016-04-15 16:18:30 +053041import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
Vidyashree Rama6a72b792016-03-29 12:00:42 +053042
Bharat saraswalcad0e652016-05-26 23:48:38 +053043import static org.onosproject.yangutils.datamodel.YangNodeType.LIST_NODE;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053044import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
45import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
Bharat saraswalcad0e652016-05-26 23:48:38 +053046import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.resolveGroupingsQuailifiedInfo;
47import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType;
48import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
49import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
50import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
janani b4a6711a2016-05-17 13:12:22 +053051import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
Bharat saraswal4ca63712016-05-28 17:50:57 +053052import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
Gaurav Agrawal56527662016-04-20 15:49:17 +053053import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
54import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
Bharat saraswal4ca63712016-05-28 17:50:57 +053055import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
Gaurav Agrawal56527662016-04-20 15:49:17 +053056
Vidyashree Rama6a72b792016-03-29 12:00:42 +053057/**
Bharat saraswald9822e92016-04-05 15:13:44 +053058 * Represents rpc information extended to support java code generation.
Vidyashree Rama6a72b792016-03-29 12:00:42 +053059 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053060public class YangJavaRpc
61 extends YangRpc
62 implements JavaCodeGenerator, JavaCodeGeneratorInfo {
Vidyashree Rama6a72b792016-03-29 12:00:42 +053063
64 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +053065 * Contains the information of the java file being generated.
66 */
67 private JavaFileInfo javaFileInfo;
68
69 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053070 * Temproary file for code generation.
71 */
72 private TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
73
Bharat saraswalcad0e652016-05-26 23:48:38 +053074 private boolean isInputLeafHolder;
75 private boolean isOutputLeafHolder;
76 private boolean isInputSingleChildHolder;
77 private boolean isOutputSingleChildHolder;
78
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053079 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +053080 * Creates an instance of YANG java rpc.
Vidyashree Rama6a72b792016-03-29 12:00:42 +053081 */
82 public YangJavaRpc() {
Gaurav Agrawal56527662016-04-20 15:49:17 +053083 super();
84 setJavaFileInfo(new JavaFileInfo());
Vidyashree Rama6a72b792016-03-29 12:00:42 +053085 }
86
87 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +053088 * Returns the generated java file information.
89 *
90 * @return generated java file information
91 */
92 @Override
93 public JavaFileInfo getJavaFileInfo() {
94
95 if (javaFileInfo == null) {
96 throw new TranslatorException("missing java info in java datamodel node");
97 }
98 return javaFileInfo;
99 }
100
101 /**
102 * Sets the java file info object.
103 *
104 * @param javaInfo java file info object
105 */
106 @Override
107 public void setJavaFileInfo(JavaFileInfo javaInfo) {
108 javaFileInfo = javaInfo;
Vidyashree Rama6a72b792016-03-29 12:00:42 +0530109 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530110
111 @Override
112 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
113 return tempJavaCodeFragmentFiles;
114 }
115
116 @Override
117 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
118 tempJavaCodeFragmentFiles = fileHandle;
119 }
Gaurav Agrawal56527662016-04-20 15:49:17 +0530120
Bharat saraswalcad0e652016-05-26 23:48:38 +0530121 /**
122 * Prepares the information for java code generation corresponding to YANG
123 * RPC info.
124 *
125 * @param yangPlugin YANG plugin config
126 * @throws TranslatorException translator operations fails
127 */
128 @Override
129 public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
130
131 if (!(this instanceof JavaCodeGeneratorInfo)) {
132 // TODO:throw exception
133 }
134
135 // Add package information for rpc and create corresponding folder.
136 try {
137 updatePackageInfo(this, yangPlugin);
138 if (this.getChild() != null) {
139 processNodeEntry(this.getChild(), yangPlugin);
140 if (this.getChild().getNextSibling() != null) {
141 processNodeEntry(this.getChild().getNextSibling(), yangPlugin);
142 }
143 }
144 } catch (IOException e) {
145 throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName());
146 }
147 }
148
149 /**
150 * Creates a java file using the YANG RPC info.
151 *
152 * @throws TranslatorException translator operations fails
153 */
154 @Override
155 public void generateCodeExit() throws TranslatorException {
156 // Get the parent module/sub-module.
157 YangNode parent = getParentNodeInGenCode(this);
158
159 // Parent should be holder of rpc or notification.
160 if (!(parent instanceof RpcNotificationContainer)) {
161 throw new TranslatorException("parent node of rpc can only be module or sub-module");
162 }
163
164 /*
165 * Create attribute info for input and output of rpc and add it to the
166 * parent import list.
167 */
168
169 JavaAttributeInfo javaAttributeInfoOfInput = null;
170 JavaAttributeInfo javaAttributeInfoOfOutput = null;
171
172 // Get the child input and output node and obtain create java attribute
173 // info.
174 YangNode yangNode = this.getChild();
175 while (yangNode != null) {
176 if (yangNode instanceof YangInput) {
177 javaAttributeInfoOfInput = processNodeExit(yangNode, getJavaFileInfo().getPluginConfig());
178
179 } else if (yangNode instanceof YangOutput) {
180 javaAttributeInfoOfOutput = processNodeExit(yangNode, getJavaFileInfo().getPluginConfig());
181 } else {
182 // TODO throw exception
183 }
184 yangNode = yangNode.getNextSibling();
185 }
186
187 if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
188 throw new TranslatorException("missing parent temp file handle");
189 }
190
191 /*
192 * Add the rpc information to the parent's service temp file.
193 */
194 try {
Bharat saraswal4ca63712016-05-28 17:50:57 +0530195 String rpcsChildNodePkg = getPackageDirPathFromJavaJPackage(getJavaFileInfo().getBaseCodeGenPath() +
196 (getJavaFileInfo().getPackage() + "." + getJavaFileInfo().getJavaName()).toLowerCase());
197
Bharat saraswalcad0e652016-05-26 23:48:38 +0530198 ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
199 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
200 ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(),
201 ((YangNode) this).getName(), isInputLeafHolder(), isOutputLeafHolder(),
202 isInputSingleChildHolder(), isOutputSingleChildHolder());
Bharat saraswal4ca63712016-05-28 17:50:57 +0530203
204 if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput != null
205 && isInputLeafHolder() && isOutputLeafHolder()) {
206 deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
207 } else if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput == null
208 && isInputLeafHolder()) {
209 deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
210 } else if (javaAttributeInfoOfInput == null && javaAttributeInfoOfOutput != null
211 && isOutputLeafHolder()) {
212 deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
213 } else {
214 YangNode node = this.getChild();
215 while (node != null) {
216 YangNode tempNode = node.getChild();
217 while (tempNode != null) {
218 if (tempNode instanceof YangUses) {
219 deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
220 }
221 tempNode = tempNode.getNextSibling();
222 }
223 node = node.getNextSibling();
224 }
225 }
Bharat saraswalcad0e652016-05-26 23:48:38 +0530226 } catch (IOException e) {
227 throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
228 }
229 // No file will be generated during RPC exit.
230 }
231
232 /**
Bharat saraswal4ca63712016-05-28 17:50:57 +0530233 * When there is no file generation for input output node we should delete the directory generated
234 * for RPC.
235 *
236 * @param emptyPkg empty package
237 * @throws IOException when fails to do IO operations
238 */
239 private void deleteDirectoryWhenNoFileIsGeneratedForInputOutput(String emptyPkg) throws IOException {
240 deleteDirectory(emptyPkg);
241 }
242
243 /**
Bharat saraswalcad0e652016-05-26 23:48:38 +0530244 * Creates an attribute info object corresponding to a data model node and
245 * return it.
246 *
247 * @param childNode child data model node(input / output) for which the java code generation
248 * is being handled
249 * @param currentNode parent node (module / sub-module) in which the child node is an attribute
250 * @return AttributeInfo attribute details required to add in temporary
251 * files
252 */
253 public JavaAttributeInfo getChildNodeAsAttributeInParentService(
254 YangNode childNode, YangNode currentNode) {
255
256 YangNode parentNode = getParentNodeInGenCode(currentNode);
257
258 String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
259 /*
260 * Get the import info corresponding to the attribute for import in
261 * generated java files or qualified access
262 */
263 JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(currentNode,
264 getCapitalCase(childNodeName));
265 if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
266 throw new TranslatorException("Parent node does not have file info");
267 }
268
269 TempJavaFragmentFiles tempJavaFragmentFiles;
270 tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
271 .getTempJavaCodeFragmentFiles()
272 .getServiceTempFiles();
273
274 if (tempJavaFragmentFiles == null) {
275 throw new TranslatorException("Parent node does not have service file info");
276 }
277 boolean isQualified = addImportToService(qualifiedTypeInfo);
278 return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
279 }
280
281 /**
282 * Process input/output nodes.
283 *
284 * @param node YANG node
285 * @param yangPluginConfig plugin configurations
286 */
287 private void processNodeEntry(YangNode node, YangPluginConfig yangPluginConfig) {
288 YangLeavesHolder holder = (YangLeavesHolder) node;
289 if (node.getChild() == null) {
290 if (holder.getListOfLeaf() != null && holder.getListOfLeafList().isEmpty()
291 && holder.getListOfLeaf().size() == 1) {
292 setCodeGenFlagForNode(node, false);
293 } else if (holder.getListOfLeaf().isEmpty() && holder.getListOfLeafList() != null
294 && holder.getListOfLeafList().size() == 1) {
295 setCodeGenFlagForNode(node, false);
296 } else {
297 setCodeGenFlagForNode(node, true);
298 }
299 } else if (node.getChild() != null && holder.getListOfLeaf().isEmpty()
300 && holder.getListOfLeafList().isEmpty()) {
301 if (getNumberOfChildNodes(node) == 1) {
302 setCodeGenFlagForNode(node, false);
303 } else {
304 setCodeGenFlagForNode(node, true);
305 }
306 } else {
307 setCodeGenFlagForNode(node, true);
308 }
309 }
310
311 /**
312 * Process input/output nodes.
313 *
314 * @param node YANG node
315 * @param yangPluginConfig plugin configurations
316 * @return java attribute info
317 */
318 private JavaAttributeInfo processNodeExit(YangNode node, YangPluginConfig yangPluginConfig) {
319 YangLeavesHolder holder = (YangLeavesHolder) node;
320 if (node.getChild() == null) {
321 if (holder.getListOfLeaf() != null && holder.getListOfLeafList().isEmpty()
322 && holder.getListOfLeaf().size() == 1) {
323 return processNodeWhenOnlyOneLeafIsPresent(node, yangPluginConfig);
324
325 } else if (holder.getListOfLeaf().isEmpty() && holder.getListOfLeafList() != null
326 && holder.getListOfLeafList().size() == 1) {
327 return processNodeWhenOnlyOneLeafListIsPresent(node, yangPluginConfig);
328 } else {
329 return processNodeWhenMultipleContaintsArePresent(node);
330 }
331 } else if (node.getChild() != null && holder.getListOfLeaf().isEmpty()
332 && holder.getListOfLeafList().isEmpty()) {
333 if (getNumberOfChildNodes(node) == 1) {
334 return processNodeWhenOnlyOneChildNodeIsPresent(node, yangPluginConfig);
335 } else {
336 return processNodeWhenMultipleContaintsArePresent(node);
337 }
338 } else {
339 return processNodeWhenMultipleContaintsArePresent(node);
340 }
341 }
342
343 /**
344 * Process input/output node when one leaf is present.
345 *
346 * @param node input/output node
347 * @param yangPluginConfig plugin configurations
348 * @return java attribute for node
349 */
350 private JavaAttributeInfo processNodeWhenOnlyOneLeafIsPresent(YangNode node,
351 YangPluginConfig yangPluginConfig) {
352
353 YangLeavesHolder holder = (YangLeavesHolder) node;
354 List<YangLeaf> listOfLeaves = holder.getListOfLeaf();
355
356 for (YangLeaf leaf : listOfLeaves) {
357 if (!(leaf instanceof JavaLeafInfoContainer)) {
358 throw new TranslatorException("Leaf does not have java information");
359 }
360 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
361 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
362 javaLeaf.updateJavaQualifiedInfo();
363 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
364 javaLeaf.getJavaQualifiedInfo(),
365 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
366 javaLeaf.getDataType(),
367 addTypeImport(javaLeaf.getDataType(), false, yangPluginConfig), false);
368 setLeafHolderFlag(node, true);
369 return javaAttributeInfo;
370 }
371 return null;
372 }
373
374 /**
375 * Process input/output node when one leaf list is present.
376 *
377 * @param node input/output node
378 * @param yangPluginConfig plugin configurations
379 * @return java attribute for node
380 */
381 private JavaAttributeInfo processNodeWhenOnlyOneLeafListIsPresent(YangNode node,
382 YangPluginConfig yangPluginConfig) {
383
384 YangLeavesHolder holder = (YangLeavesHolder) node;
385 List<YangLeafList> listOfLeafList = holder.getListOfLeafList();
386
387 for (YangLeafList leafList : listOfLeafList) {
388 if (!(leafList instanceof JavaLeafInfoContainer)) {
389 throw new TranslatorException("Leaf-list does not have java information");
390 }
391 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
392 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
393 javaLeaf.updateJavaQualifiedInfo();
394 ((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
395 .getServiceTempFiles().getJavaImportData().setIfListImported(true);
396 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
397 javaLeaf.getJavaQualifiedInfo(),
398 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
399 javaLeaf.getDataType(),
400 addTypeImport(javaLeaf.getDataType(), true, yangPluginConfig),
401 true);
402 setLeafHolderFlag(node, true);
403 return javaAttributeInfo;
404 }
405 return null;
406 }
407
408 /**
409 * Process input/output node when one child node is present.
410 *
411 * @param node input/output node
412 * @param yangPluginConfig plugin configurations
413 * @return java attribute for node
414 */
415 private JavaAttributeInfo processNodeWhenOnlyOneChildNodeIsPresent(YangNode node,
416 YangPluginConfig yangPluginConfig) {
417 JavaFileInfo rpcInfo = getJavaFileInfo();
418 String clsInfo = "";
419 JavaQualifiedTypeInfo childInfo = new JavaQualifiedTypeInfo();
420 if (node.getChild() instanceof YangJavaUses) {
421 childInfo = resolveGroupingsQuailifiedInfo(((YangJavaUses) node.getChild()).getRefGroup(),
422 yangPluginConfig);
423 clsInfo = getCapitalCase(getCamelCase(((YangJavaUses) node.getChild()).getRefGroup().getName(),
424 yangPluginConfig.getConflictResolver()));
425 } else {
426 String pkg = (rpcInfo.getPackage() + "." + rpcInfo.getJavaName() + "."
427 + getCamelCase(node.getName(), yangPluginConfig.getConflictResolver())).toLowerCase();
428 clsInfo = getCapitalCase(
429 getCamelCase(node.getChild().getName(), yangPluginConfig.getConflictResolver()));
430 childInfo.setPkgInfo(pkg);
431 childInfo.setClassInfo(clsInfo);
432 }
433 boolean isList = false;
434 if (node.getChild().getNodeType().equals(LIST_NODE)) {
435 isList = true;
436 }
437 boolean isQualified = addImportToService(childInfo);
438
439 JavaAttributeInfo javaAttributeInfo =
440 getAttributeInfoForTheData(childInfo, clsInfo, null, isQualified, isList);
441
442 setLeafHolderFlag(node, false);
443 setSingleChildHolderFlag(node, true);
444 return javaAttributeInfo;
445 }
446
447 /**
448 * Process input/output node when multiple leaf and child nodes are present.
449 *
450 * @param node input/output node
451 * @return java attribute for node
452 */
453 private JavaAttributeInfo processNodeWhenMultipleContaintsArePresent(YangNode node) {
454
455 setLeafHolderFlag(node, false);
456 setSingleChildHolderFlag(node, false);
457 return getChildNodeAsAttributeInParentService(node, this);
458 }
459
460 /**
461 * Adds type import to the RPC import list.
462 *
463 * @param type YANG type
464 * @param isList is list attribute
465 * @param pluginConfig plugin configurations
466 * @return type import to the RPC import list
467 */
468 private boolean addTypeImport(YangType<?> type, boolean isList, YangPluginConfig pluginConfig) {
469
470 String classInfo = getJavaImportClass(type, isList, pluginConfig.getConflictResolver());
471 if (classInfo == null) {
472 classInfo = getJavaDataType(type);
473 return false;
474 } else {
475 classInfo = getJavaImportClass(type, isList, pluginConfig.getConflictResolver());
476 String pkgInfo = getJavaImportPackage(type, isList, pluginConfig.getConflictResolver());
477 JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
478 importInfo.setPkgInfo(pkgInfo);
479 importInfo.setClassInfo(classInfo);
480 if (!((JavaFileInfoContainer) this.getParent()).getJavaFileInfo().getJavaName().equals(classInfo)) {
481 return addImportToService(importInfo);
482 } else {
483 return true;
484 }
485 }
486 }
487
488 /**
489 * Adds to service class import list.
490 *
491 * @param importInfo import info
492 * @return true or false
493 */
494 private boolean addImportToService(JavaQualifiedTypeInfo importInfo) {
495 if (((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
496 .getServiceTempFiles().getJavaImportData().addImportInfo(importInfo)) {
497 return !((TempJavaCodeFragmentFilesContainer) this.getParent()).getTempJavaCodeFragmentFiles()
498 .getServiceTempFiles().getJavaImportData().getImportSet().contains(importInfo);
499 } else {
500 return true;
501 }
502 }
503
504 /**
505 * Sets leaf holder flag for input/output.
506 *
507 * @param node input/output node
508 * @param flag true or false
509 */
510 private void setLeafHolderFlag(YangNode node, boolean flag) {
511 if (node instanceof YangJavaInput) {
512 setInputLeafHolder(flag);
513 } else {
514 setOutputLeafHolder(flag);
515 }
516 }
517
518 /**
519 * Sets sing child holder flag for input/output.
520 *
521 * @param node input/output node
522 * @param flag true or false
523 */
524 private void setSingleChildHolderFlag(YangNode node, boolean flag) {
525 if (node instanceof YangJavaInput) {
526 setInputSingleChildHolder(flag);
527 } else {
528 setOutputSingleChildHolder(flag);
529 }
530 }
531
532 /**
533 * Sets code generator flag for input and output.
534 *
535 * @param node YANG node
536 * @param flag cod generator flag
537 */
538 private void setCodeGenFlagForNode(YangNode node, boolean flag) {
539 if (node instanceof YangJavaInput) {
540 ((YangJavaInput) node).setCodeGenFlag(flag);
541 } else {
542 ((YangJavaOutput) node).setCodeGenFlag(flag);
543 }
544
545 }
546
547 /**
548 * Counts the number of child nodes of a YANG node.
549 *
550 * @param node YANG node
551 * @return count of children
552 */
553 private int getNumberOfChildNodes(YangNode node) {
554 YangNode tempNode = node.getChild();
555 int count = 0;
556 if (tempNode != null) {
557 count = 1;
558 }
559 while (tempNode != null) {
560
561 tempNode = tempNode.getNextSibling();
562 if (tempNode != null) {
563 count++;
564 }
565 }
566 return count;
567 }
568
569 /**
570 * Returns true if input is a leaf holder.
571 *
572 * @return true if input is a leaf holder
573 */
574 public boolean isInputLeafHolder() {
575 return isInputLeafHolder;
576 }
577
578 /**
579 * Sets true if input is a leaf holder.
580 *
581 * @param isInputLeafHolder true if input is a leaf holder
582 */
583 public void setInputLeafHolder(boolean isInputLeafHolder) {
584 this.isInputLeafHolder = isInputLeafHolder;
585 }
586
587 /**
588 * Returns true if output is a leaf holder.
589 *
590 * @return true if output is a leaf holder
591 */
592 public boolean isOutputLeafHolder() {
593 return isOutputLeafHolder;
594 }
595
596 /**
597 * Sets true if output is a leaf holder.
598 *
599 * @param isOutputLeafHolder true if output is a leaf holder
600 */
601 public void setOutputLeafHolder(boolean isOutputLeafHolder) {
602 this.isOutputLeafHolder = isOutputLeafHolder;
603 }
604
605 /**
606 * Returns true if input is single child holder.
607 *
608 * @return true if input is single child holder
609 */
610 public boolean isInputSingleChildHolder() {
611 return isInputSingleChildHolder;
612 }
613
614 /**
615 * Sets true if input is single child holder.
616 *
617 * @param isInputSingleChildHolder true if input is single child holder
618 */
619 public void setInputSingleChildHolder(boolean isInputSingleChildHolder) {
620 this.isInputSingleChildHolder = isInputSingleChildHolder;
621 }
622
623 /**
624 * Returns true if output is single child holder.
625 *
626 * @return true if output is single child holder
627 */
628 public boolean isOutputSingleChildHolder() {
629 return isOutputSingleChildHolder;
630 }
631
632 /**
633 * Sets true if output is single child holder.
634 *
635 * @param isOutputSingleChildHolder true if output is single child holder
636 */
637 public void setOutputSingleChildHolder(boolean isOutputSingleChildHolder) {
638 this.isOutputSingleChildHolder = isOutputSingleChildHolder;
639 }
640
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530641}