Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | package org.onosproject.yangutils.translator.tojava; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.IOException; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | import java.util.List; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 21 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangCase; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 25 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangModule; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangSubModule; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo; |
| 31 | import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 33 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 36 | |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK; |
| 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 58 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString; |
| 60 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; |
| 63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
| 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 70 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 71 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl; |
| 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
| 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 79 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 80 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 83 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 84 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 85 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 86 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 87 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 88 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 90 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 91 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 92 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 93 | import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 94 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 95 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 98 | import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 99 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 101 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 102 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 104 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 105 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 106 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 107 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 109 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 110 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 111 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 112 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 113 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 114 | |
| 115 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 116 | * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for |
| 117 | * Java file(s) generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 118 | */ |
| 119 | public class TempJavaFragmentFiles { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 120 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 121 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 122 | * File type extension for java classes. |
| 123 | */ |
| 124 | private static final String JAVA_FILE_EXTENSION = ".java"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 125 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 126 | /** |
| 127 | * File type extension for temporary classes. |
| 128 | */ |
| 129 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 130 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 131 | /** |
| 132 | * Folder suffix for temporary files folder. |
| 133 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 134 | private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 135 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 136 | /** |
| 137 | * File name for getter method. |
| 138 | */ |
| 139 | private static final String GETTER_METHOD_FILE_NAME = "GetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 140 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 141 | /** |
| 142 | * File name for setter method. |
| 143 | */ |
| 144 | private static final String SETTER_METHOD_FILE_NAME = "SetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * File name for getter method implementation. |
| 148 | */ |
| 149 | private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl"; |
| 150 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 151 | /** |
| 152 | * File name for setter method implementation. |
| 153 | */ |
| 154 | private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 155 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 156 | /** |
| 157 | * File name for attributes. |
| 158 | */ |
| 159 | private static final String ATTRIBUTE_FILE_NAME = "Attributes"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 160 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 161 | /** |
| 162 | * File name for to string method. |
| 163 | */ |
| 164 | private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 165 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 166 | /** |
| 167 | * File name for hash code method. |
| 168 | */ |
| 169 | private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 170 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 171 | /** |
| 172 | * File name for equals method. |
| 173 | */ |
| 174 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 175 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 176 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 177 | * File name for from string method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 178 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 179 | private static final String FROM_STRING_METHOD_FILE_NAME = "FromString"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 180 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 181 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 182 | * File name for from add to list interface method. |
| 183 | */ |
| 184 | private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList"; |
| 185 | |
| 186 | /** |
| 187 | * File name for from add to list impl method. |
| 188 | */ |
| 189 | private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl"; |
| 190 | |
| 191 | /** |
| 192 | * File name for from leaf identifier attributes. |
| 193 | */ |
| 194 | private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr"; |
| 195 | |
| 196 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 197 | * File name for interface java file name suffix. |
| 198 | */ |
| 199 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 200 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 201 | /** |
| 202 | * File name for builder interface file name suffix. |
| 203 | */ |
| 204 | private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 205 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 206 | /** |
| 207 | * File name for builder class file name suffix. |
| 208 | */ |
| 209 | private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 210 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 211 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 212 | * Information about the java files being generated. |
| 213 | */ |
| 214 | private JavaFileInfo javaFileInfo; |
| 215 | |
| 216 | /** |
| 217 | * Imported class info. |
| 218 | */ |
| 219 | private JavaImportData javaImportData; |
| 220 | |
| 221 | /** |
| 222 | * The variable which guides the types of temporary files generated using the temporary generated file types mask. |
| 223 | */ |
| 224 | private int generatedTempFiles; |
| 225 | |
| 226 | /** |
| 227 | * Absolute path where the target java file needs to be generated. |
| 228 | */ |
| 229 | private String absoluteDirPath; |
| 230 | |
| 231 | /** |
| 232 | * Contains all the interface(s)/class name which will be extended by generated files. |
| 233 | */ |
| 234 | private JavaExtendsListHolder javaExtendsListHolder; |
| 235 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 236 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 237 | * Java file handle for interface file. |
| 238 | */ |
| 239 | private File interfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 240 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 241 | /** |
| 242 | * Java file handle for builder interface file. |
| 243 | */ |
| 244 | private File builderInterfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 245 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 246 | /** |
| 247 | * Java file handle for builder class file. |
| 248 | */ |
| 249 | private File builderClassJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 250 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 251 | /** |
| 252 | * Java file handle for impl class file. |
| 253 | */ |
| 254 | private File implClassJavaFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 255 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 256 | /** |
| 257 | * Temporary file handle for attribute. |
| 258 | */ |
| 259 | private File attributesTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 260 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 261 | /** |
| 262 | * Temporary file handle for getter of interface. |
| 263 | */ |
| 264 | private File getterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 265 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 266 | /** |
| 267 | * Temporary file handle for setter of interface. |
| 268 | */ |
| 269 | private File setterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Temporary file handle for getter of class. |
| 273 | */ |
| 274 | private File getterImplTempFileHandle; |
| 275 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 276 | /** |
| 277 | * Temporary file handle for setter of class. |
| 278 | */ |
| 279 | private File setterImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 280 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 281 | /** |
| 282 | * Temporary file handle for hash code method of class. |
| 283 | */ |
| 284 | private File hashCodeImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 285 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 286 | /** |
| 287 | * Temporary file handle for equals method of class. |
| 288 | */ |
| 289 | private File equalsImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 290 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 291 | /** |
| 292 | * Temporary file handle for to string method of class. |
| 293 | */ |
| 294 | private File toStringImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 295 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 296 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 297 | * Temporary file handle for from string method of class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 298 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 299 | private File fromStringImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 300 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 301 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 302 | * Temporary file handle for add to list interface method of class. |
| 303 | */ |
| 304 | private File addToListInterfaceTempFileHandle; |
| 305 | |
| 306 | /** |
| 307 | * Temporary file handle for add to list impl method of class. |
| 308 | */ |
| 309 | private File addToListImplTempFileHandle; |
| 310 | |
| 311 | /** |
| 312 | * Temporary file handle for leaf id attributes of enum. |
| 313 | */ |
| 314 | private File leafIdAttributeTempFileHandle; |
| 315 | |
| 316 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 317 | * Import info for case. |
| 318 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 319 | private JavaQualifiedTypeInfoTranslator caseImportInfo; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 320 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 321 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 322 | * Leaf count. |
| 323 | */ |
| 324 | private int leafCount = 0; |
| 325 | |
| 326 | /** |
| 327 | * If current node is root node. |
| 328 | */ |
| 329 | private boolean isRooNode; |
| 330 | |
| 331 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 332 | * Is attribute added. |
| 333 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 334 | private boolean isAttributePresent; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 335 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 336 | TempJavaFragmentFiles() { |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Creates an instance of temporary java code fragment. |
| 341 | * |
| 342 | * @param javaFileInfo generated java file information |
| 343 | * @throws IOException when fails to create new file handle |
| 344 | */ |
| 345 | TempJavaFragmentFiles(JavaFileInfo javaFileInfo) |
| 346 | throws IOException { |
| 347 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
| 348 | setJavaImportData(new JavaImportData()); |
| 349 | setJavaFileInfo(javaFileInfo); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 350 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 351 | getJavaFileInfo().getPackageFilePath())); |
| 352 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 353 | /* |
| 354 | * Initialize getter when generation file type matches to interface |
| 355 | * mask. |
| 356 | */ |
| 357 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 358 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 359 | addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK); |
| 360 | addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* |
| 364 | * Initialize getter and setter when generation file type matches to |
| 365 | * builder interface mask. |
| 366 | */ |
| 367 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 368 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 369 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Initialize getterImpl, setterImpl and attributes when generation file |
| 374 | * type matches to builder class mask. |
| 375 | */ |
| 376 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 377 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 378 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 379 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 384 | * to strings when generation file type matches to impl class mask. |
| 385 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 386 | if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 387 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 388 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 389 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 390 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 391 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 392 | addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Initialize temp files to generate type class. |
| 397 | */ |
| 398 | if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) { |
| 399 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 400 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 401 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 402 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 403 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
| 404 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Initialize temp files to generate enum class. |
| 409 | */ |
| 410 | if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) { |
| 411 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Set temporary file handles. |
| 416 | */ |
| 417 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 418 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
| 419 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 420 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 421 | setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME)); |
| 422 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 423 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 424 | setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME)); |
| 425 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 426 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 427 | setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME)); |
| 428 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 429 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 430 | setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME)); |
| 431 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 432 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 433 | setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME)); |
| 434 | } |
| 435 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 436 | setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME)); |
| 437 | } |
| 438 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 439 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
| 440 | } |
| 441 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 442 | setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME)); |
| 443 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 444 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) { |
| 445 | setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME)); |
| 446 | } |
| 447 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) { |
| 448 | setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME)); |
| 449 | } |
| 450 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) { |
| 451 | setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME)); |
| 452 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Adds current node info as and attribute to the parent generated file. |
| 457 | * |
| 458 | * @param curNode current node which needs to be added as an attribute in the parent generated code |
| 459 | * @param isList is list construct |
| 460 | * @param pluginConfig plugin configurations |
| 461 | * @throws IOException IO operation exception |
| 462 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 463 | static void addCurNodeInfoInParentTempFile(YangNode curNode, |
| 464 | boolean isList, YangPluginConfig pluginConfig) |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 465 | throws IOException { |
| 466 | YangNode parent = getParentNodeInGenCode(curNode); |
| 467 | if (!(parent instanceof JavaCodeGenerator)) { |
| 468 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 469 | } |
| 470 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 471 | if (parent instanceof YangJavaGroupingTranslator) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 472 | /* |
| 473 | * In case of grouping, there is no need to add the information, it |
| 474 | * will be taken care in uses |
| 475 | */ |
| 476 | return; |
| 477 | } |
| 478 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent) |
| 479 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 480 | |
| 481 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode, |
| 482 | parent, isList, tempJavaBeanFragmentFiles); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 483 | tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Creates an attribute info object corresponding to a data model node and return it. |
| 488 | * |
| 489 | * @param curNode current data model node for which the java code generation is being handled |
| 490 | * @param targetNode target node in which the current node is an attribute |
| 491 | * @param isListNode is the current added attribute needs to be a list |
| 492 | * @param tempJavaFragmentFiles temp java fragment files |
| 493 | * @return AttributeInfo attribute details required to add in temporary files |
| 494 | */ |
| 495 | public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode, |
| 496 | YangNode targetNode, boolean isListNode, |
| 497 | TempJavaFragmentFiles tempJavaFragmentFiles) { |
| 498 | String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 499 | if (curNodeName == null) { |
| 500 | updateJavaFileInfo(curNode, null); |
| 501 | curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | * Get the import info corresponding to the attribute for import in |
| 506 | * generated java files or qualified access |
| 507 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 508 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 509 | getCapitalCase(curNodeName)); |
| 510 | if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) { |
| 511 | throw new TranslatorException("Parent node does not have file info"); |
| 512 | } |
| 513 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); |
| 514 | JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo(); |
| 515 | |
| 516 | boolean isQualified; |
Bharat saraswal | aab24b9 | 2016-08-02 18:43:16 +0530 | [diff] [blame] | 517 | if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 518 | && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)) |
| 519 | || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 520 | |
| 521 | isQualified = true; |
| 522 | } else { |
| 523 | String className; |
Bharat saraswal | aab24b9 | 2016-08-02 18:43:16 +0530 | [diff] [blame] | 524 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 525 | className = getCapitalCase(fileInfo.getJavaName()) + SERVICE; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 526 | } else { |
| 527 | className = getCapitalCase(fileInfo.getJavaName()); |
| 528 | } |
| 529 | |
| 530 | isQualified = parentImportData.addImportInfo(qualifiedTypeInfo, |
| 531 | className, fileInfo.getPackage()); |
| 532 | } |
| 533 | |
| 534 | if (isListNode) { |
| 535 | parentImportData.setIfListImported(true); |
| 536 | } |
| 537 | |
| 538 | return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode); |
| 539 | } |
| 540 | |
| 541 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 542 | * Returns java attribute for leaf. |
| 543 | * |
| 544 | * @param tempJavaFragmentFiles temporary generated file |
| 545 | * @param leaf YANG leaf |
| 546 | * @param yangPluginConfig plugin configurations |
| 547 | * @return java attribute for leaf |
| 548 | */ |
| 549 | public static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf, |
| 550 | YangPluginConfig yangPluginConfig) { |
| 551 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; |
| 552 | javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); |
| 553 | javaLeaf.updateJavaQualifiedInfo(); |
| 554 | return getAttributeInfoForTheData( |
| 555 | javaLeaf.getJavaQualifiedInfo(), |
| 556 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 557 | javaLeaf.getDataType(), |
| 558 | tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 559 | false); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Returns java attribute for leaf-list. |
| 564 | * |
| 565 | * @param tempJavaFragmentFiles temporary generated file |
| 566 | * @param leafList YANG leaf-list |
| 567 | * @param yangPluginConfig plugin configurations |
| 568 | * @return java attribute for leaf-list |
| 569 | */ |
| 570 | public static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles, |
| 571 | YangLeafList leafList, |
| 572 | YangPluginConfig yangPluginConfig) { |
| 573 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; |
| 574 | javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); |
| 575 | javaLeaf.updateJavaQualifiedInfo(); |
| 576 | tempJavaFragmentFiles.getJavaImportData().setIfListImported(true); |
| 577 | return getAttributeInfoForTheData( |
| 578 | javaLeaf.getJavaQualifiedInfo(), |
| 579 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 580 | javaLeaf.getDataType(), |
| 581 | tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 582 | true); |
| 583 | } |
| 584 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 585 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 586 | * Retrieves the absolute path where the file needs to be generated. |
| 587 | * |
| 588 | * @return absolute path where the file needs to be generated |
| 589 | */ |
| 590 | private String getAbsoluteDirPath() { |
| 591 | return absoluteDirPath; |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Sets absolute path where the file needs to be generated. |
| 596 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 597 | * @param absoluteDirPath absolute path where the file needs to be generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 598 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 599 | void setAbsoluteDirPath(String absoluteDirPath) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 600 | this.absoluteDirPath = absoluteDirPath; |
| 601 | } |
| 602 | |
| 603 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 604 | * Retrieves the generated java file information. |
| 605 | * |
| 606 | * @return generated java file information |
| 607 | */ |
| 608 | public JavaFileInfo getJavaFileInfo() { |
| 609 | return javaFileInfo; |
| 610 | } |
| 611 | |
| 612 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 613 | * Sets the generated java file information. |
| 614 | * |
| 615 | * @param javaFileInfo generated java file information |
| 616 | */ |
| 617 | public void setJavaFileInfo(JavaFileInfo javaFileInfo) { |
| 618 | this.javaFileInfo = javaFileInfo; |
| 619 | } |
| 620 | |
| 621 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 622 | * Retrieves the generated temp files. |
| 623 | * |
| 624 | * @return generated temp files |
| 625 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 626 | int getGeneratedTempFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 627 | return generatedTempFiles; |
| 628 | } |
| 629 | |
| 630 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 631 | * Sets generated file files. |
| 632 | * |
| 633 | * @param fileType generated file type |
| 634 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 635 | private void setGeneratedTempFiles(int fileType) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 636 | generatedTempFiles = fileType; |
| 637 | } |
| 638 | |
| 639 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 640 | * Adds to generated temporary files. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 641 | * |
| 642 | * @param generatedTempFile generated file |
| 643 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 644 | void addGeneratedTempFile(int generatedTempFile) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 645 | generatedTempFiles |= generatedTempFile; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 646 | setGeneratedTempFiles(generatedTempFiles); |
| 647 | } |
| 648 | |
| 649 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 650 | * Retrieves the generated Java files. |
| 651 | * |
| 652 | * @return generated Java files |
| 653 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 654 | int getGeneratedJavaFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 655 | return getJavaFileInfo().getGeneratedFileTypes(); |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Retrieves the mapped Java class name. |
| 660 | * |
| 661 | * @return mapped Java class name |
| 662 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 663 | String getGeneratedJavaClassName() { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 664 | return getCapitalCase(getJavaFileInfo().getJavaName()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Retrieves the import data for the generated Java file. |
| 669 | * |
| 670 | * @return import data for the generated Java file |
| 671 | */ |
| 672 | public JavaImportData getJavaImportData() { |
| 673 | return javaImportData; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Sets import data for the generated Java file. |
| 678 | * |
| 679 | * @param javaImportData import data for the generated Java file |
| 680 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 681 | void setJavaImportData(JavaImportData javaImportData) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 682 | this.javaImportData = javaImportData; |
| 683 | } |
| 684 | |
| 685 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 686 | * Retrieves the status of any attributes added. |
| 687 | * |
| 688 | * @return status of any attributes added |
| 689 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 690 | boolean isAttributePresent() { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 691 | return isAttributePresent; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Sets status of any attributes added. |
| 696 | * |
| 697 | * @param attributePresent status of any attributes added |
| 698 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 699 | private void setAttributePresent(boolean attributePresent) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 700 | isAttributePresent = attributePresent; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Returns getter methods's temporary file handle. |
| 705 | * |
| 706 | * @return temporary file handle |
| 707 | */ |
| 708 | public File getGetterInterfaceTempFileHandle() { |
| 709 | return getterInterfaceTempFileHandle; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Sets to getter method's temporary file handle. |
| 714 | * |
| 715 | * @param getterForInterface file handle for to getter method |
| 716 | */ |
| 717 | private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
| 718 | getterInterfaceTempFileHandle = getterForInterface; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Returns setter method's temporary file handle. |
| 723 | * |
| 724 | * @return temporary file handle |
| 725 | */ |
| 726 | public File getSetterInterfaceTempFileHandle() { |
| 727 | return setterInterfaceTempFileHandle; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Sets to setter method's temporary file handle. |
| 732 | * |
| 733 | * @param setterForInterface file handle for to setter method |
| 734 | */ |
| 735 | private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
| 736 | setterInterfaceTempFileHandle = setterForInterface; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Returns setter method's impl's temporary file handle. |
| 741 | * |
| 742 | * @return temporary file handle |
| 743 | */ |
| 744 | public File getSetterImplTempFileHandle() { |
| 745 | return setterImplTempFileHandle; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Sets to setter method's impl's temporary file handle. |
| 750 | * |
| 751 | * @param setterImpl file handle for to setter method's implementation class |
| 752 | */ |
| 753 | private void setSetterImplTempFileHandle(File setterImpl) { |
| 754 | setterImplTempFileHandle = setterImpl; |
| 755 | } |
| 756 | |
| 757 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 758 | * Returns from string method's temporary file handle. |
| 759 | * |
| 760 | * @return from string method's temporary file handle |
| 761 | */ |
| 762 | public File getFromStringImplTempFileHandle() { |
| 763 | return fromStringImplTempFileHandle; |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Sets from string method's temporary file handle. |
| 768 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 769 | * @param fromStringImplTempFileHandle from string method's temporary file handle |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 770 | */ |
| 771 | private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) { |
| 772 | this.fromStringImplTempFileHandle = fromStringImplTempFileHandle; |
| 773 | } |
| 774 | |
| 775 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 776 | * Returns java file handle for interface file. |
| 777 | * |
| 778 | * @return java file handle for interface file |
| 779 | */ |
| 780 | private File getInterfaceJavaFileHandle() { |
| 781 | return interfaceJavaFileHandle; |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * Sets the java file handle for interface file. |
| 786 | * |
| 787 | * @param interfaceJavaFileHandle java file handle |
| 788 | */ |
| 789 | private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
| 790 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Returns java file handle for builder interface file. |
| 795 | * |
| 796 | * @return java file handle for builder interface file |
| 797 | */ |
| 798 | private File getBuilderInterfaceJavaFileHandle() { |
| 799 | return builderInterfaceJavaFileHandle; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Sets the java file handle for builder interface file. |
| 804 | * |
| 805 | * @param builderInterfaceJavaFileHandle java file handle |
| 806 | */ |
| 807 | private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
| 808 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * Returns java file handle for builder class file. |
| 813 | * |
| 814 | * @return java file handle for builder class file |
| 815 | */ |
| 816 | private File getBuilderClassJavaFileHandle() { |
| 817 | return builderClassJavaFileHandle; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Sets the java file handle for builder class file. |
| 822 | * |
| 823 | * @param builderClassJavaFileHandle java file handle |
| 824 | */ |
| 825 | private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
| 826 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Returns java file handle for impl class file. |
| 831 | * |
| 832 | * @return java file handle for impl class file |
| 833 | */ |
| 834 | private File getImplClassJavaFileHandle() { |
| 835 | return implClassJavaFileHandle; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Sets the java file handle for impl class file. |
| 840 | * |
| 841 | * @param implClassJavaFileHandle java file handle |
| 842 | */ |
| 843 | private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
| 844 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
| 845 | } |
| 846 | |
| 847 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 848 | * Returns attribute's temporary file handle. |
| 849 | * |
| 850 | * @return temporary file handle |
| 851 | */ |
| 852 | public File getAttributesTempFileHandle() { |
| 853 | return attributesTempFileHandle; |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Sets attribute's temporary file handle. |
| 858 | * |
| 859 | * @param attributeForClass file handle for attribute |
| 860 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 861 | private void setAttributesTempFileHandle(File attributeForClass) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 862 | attributesTempFileHandle = attributeForClass; |
| 863 | } |
| 864 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 865 | /** |
| 866 | * Returns getter method's impl's temporary file handle. |
| 867 | * |
| 868 | * @return temporary file handle |
| 869 | */ |
| 870 | public File getGetterImplTempFileHandle() { |
| 871 | return getterImplTempFileHandle; |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Sets to getter method's impl's temporary file handle. |
| 876 | * |
| 877 | * @param getterImpl file handle for to getter method's impl |
| 878 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 879 | private void setGetterImplTempFileHandle(File getterImpl) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 880 | getterImplTempFileHandle = getterImpl; |
| 881 | } |
| 882 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 883 | /** |
| 884 | * Returns hash code method's temporary file handle. |
| 885 | * |
| 886 | * @return temporary file handle |
| 887 | */ |
| 888 | public File getHashCodeImplTempFileHandle() { |
| 889 | return hashCodeImplTempFileHandle; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Sets hash code method's temporary file handle. |
| 894 | * |
| 895 | * @param hashCodeMethod file handle for hash code method |
| 896 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 897 | private void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 898 | hashCodeImplTempFileHandle = hashCodeMethod; |
| 899 | } |
| 900 | |
| 901 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 902 | * Returns equals method's temporary file handle. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 903 | * |
| 904 | * @return temporary file handle |
| 905 | */ |
| 906 | public File getEqualsImplTempFileHandle() { |
| 907 | return equalsImplTempFileHandle; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Sets equals method's temporary file handle. |
| 912 | * |
| 913 | * @param equalsMethod file handle for to equals method |
| 914 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 915 | private void setEqualsImplTempFileHandle(File equalsMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 916 | equalsImplTempFileHandle = equalsMethod; |
| 917 | } |
| 918 | |
| 919 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 920 | * Returns to string method's temporary file handle. |
| 921 | * |
| 922 | * @return temporary file handle |
| 923 | */ |
| 924 | public File getToStringImplTempFileHandle() { |
| 925 | return toStringImplTempFileHandle; |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * Sets to string method's temporary file handle. |
| 930 | * |
| 931 | * @param toStringMethod file handle for to string method |
| 932 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 933 | private void setToStringImplTempFileHandle(File toStringMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 934 | toStringImplTempFileHandle = toStringMethod; |
| 935 | } |
| 936 | |
| 937 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 938 | * Returns java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 939 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 940 | * @return java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 941 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 942 | public JavaExtendsListHolder getJavaExtendsListHolder() { |
| 943 | return javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 947 | * Sets java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 948 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 949 | * @param javaExtendsListHolder java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 950 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 951 | void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 952 | this.javaExtendsListHolder = javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 956 | * Adds attribute for class. |
| 957 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 958 | * @param attr attribute info |
| 959 | * @param yangPluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 960 | * @throws IOException when fails to append to temporary file |
| 961 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 962 | private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 963 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 964 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig) |
| 965 | + FOUR_SPACE_INDENTATION); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
| 969 | * Adds getter for interface. |
| 970 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 971 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 972 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 973 | * @throws IOException when fails to append to temporary file |
| 974 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 975 | private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 976 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 977 | appendToFile(getGetterInterfaceTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 978 | getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Adds setter for interface. |
| 983 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 984 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 985 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 986 | * @throws IOException when fails to append to temporary file |
| 987 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 988 | private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 989 | throws IOException { |
| 990 | appendToFile(getSetterInterfaceTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 991 | getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig) |
| 992 | + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /** |
| 996 | * Adds setter's implementation for class. |
| 997 | * |
| 998 | * @param attr attribute info |
| 999 | * @throws IOException when fails to append to temporary file |
| 1000 | */ |
| 1001 | private void addSetterImpl(JavaAttributeInfo attr) |
| 1002 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1003 | if (isRooNode()) { |
| 1004 | appendToFile(getSetterImplTempFileHandle(), |
| 1005 | getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) |
| 1006 | + NEW_LINE); |
| 1007 | } else { |
| 1008 | appendToFile(getSetterImplTempFileHandle(), getOverRideString() + |
| 1009 | getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) |
| 1010 | + NEW_LINE); |
| 1011 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Adds getter method's impl for class. |
| 1016 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1017 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1018 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1019 | * @throws IOException when fails to append to temporary file |
| 1020 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1021 | void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1022 | throws IOException { |
| 1023 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 |
| 1024 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1025 | if (!isRooNode()) { |
| 1026 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr, |
| 1027 | getGeneratedJavaFiles()) + NEW_LINE); |
| 1028 | } else { |
| 1029 | appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr, |
| 1030 | getGeneratedJavaFiles()) + NEW_LINE); |
| 1031 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1032 | } else { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1033 | appendToFile(getGetterImplTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1034 | getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1035 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1036 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1040 | * Adds add to list interface method. |
| 1041 | * |
| 1042 | * @param attr attribute |
| 1043 | * @param pluginConfig plugin configurations |
| 1044 | * @throws IOException when fails to do IO operations |
| 1045 | */ |
| 1046 | private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException { |
| 1047 | appendToFile(getAddToListInterfaceTempFileHandle(), |
| 1048 | getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
| 1049 | + getAddToListMethodInterface(attr) + NEW_LINE); |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * Adds add to list interface method. |
| 1054 | * |
| 1055 | * @param attr attribute |
| 1056 | * @throws IOException when fails to do IO operations |
| 1057 | */ |
| 1058 | private void addAddToListImpl(JavaAttributeInfo attr) throws IOException { |
| 1059 | appendToFile(getAddToListImplTempFileHandle(), |
| 1060 | getAddToListMethodImpl(attr) + NEW_LINE); |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * Adds leaf identifier enum attributes. |
| 1065 | * |
| 1066 | * @param attr attribute |
| 1067 | * @param value value |
| 1068 | * @param yangPluginConfig plugin config |
| 1069 | * @throws IOException when fails to do IO operations |
| 1070 | */ |
| 1071 | private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig) |
| 1072 | throws IOException { |
| 1073 | appendToFile(getLeafIdAttributeTempFileHandle(), |
| 1074 | FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(), |
| 1075 | value, yangPluginConfig)); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1079 | * Adds build method for interface. |
| 1080 | * |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1081 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1082 | * @return build method for interface |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1083 | * @throws IOException when fails to append to temporary file |
| 1084 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1085 | String addBuildMethodForInterface(YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1086 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1087 | return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Adds build method's implementation for class. |
| 1092 | * |
| 1093 | * @return build method implementation for class |
| 1094 | * @throws IOException when fails to append to temporary file |
| 1095 | */ |
| 1096 | String addBuildMethodImpl() |
| 1097 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1098 | return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1102 | * Adds default constructor for class. |
| 1103 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1104 | * @param modifier modifier for constructor. |
| 1105 | * @param toAppend string which need to be appended with the class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1106 | * @param pluginConfig plugin configurations |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1107 | * @param isSuffix is value need to be appended as suffix |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1108 | * @return default constructor for class |
| 1109 | * @throws IOException when fails to append to file |
| 1110 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1111 | String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1112 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1113 | String name = getGeneratedJavaClassName(); |
| 1114 | if (isRooNode() && !toAppend.equals(BUILDER)) { |
| 1115 | name = name + OP_PARAM; |
| 1116 | return NEW_LINE |
| 1117 | + getDefaultConstructorString(name, modifier, |
| 1118 | pluginConfig); |
| 1119 | } |
| 1120 | if (isSuffix) { |
| 1121 | return NEW_LINE + |
| 1122 | getDefaultConstructorString(name + toAppend, modifier, pluginConfig); |
| 1123 | } |
| 1124 | String appended; |
| 1125 | if (toAppend.equals(DEFAULT)) { |
| 1126 | appended = getCapitalCase(toAppend); |
| 1127 | } else { |
| 1128 | appended = toAppend; |
| 1129 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1130 | return NEW_LINE |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1131 | + getDefaultConstructorString(appended + name, modifier, |
| 1132 | pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1136 | * Adds hash code method for class. |
| 1137 | * |
| 1138 | * @param attr attribute info |
| 1139 | * @throws IOException when fails to append to temporary file |
| 1140 | */ |
| 1141 | private void addHashCodeMethod(JavaAttributeInfo attr) |
| 1142 | throws IOException { |
| 1143 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
| 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * Adds equals method for class. |
| 1148 | * |
| 1149 | * @param attr attribute info |
| 1150 | * @throws IOException when fails to append to temporary file |
| 1151 | */ |
| 1152 | private void addEqualsMethod(JavaAttributeInfo attr) |
| 1153 | throws IOException { |
| 1154 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
| 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Adds ToString method for class. |
| 1159 | * |
| 1160 | * @param attr attribute info |
| 1161 | * @throws IOException when fails to append to temporary file |
| 1162 | */ |
| 1163 | private void addToStringMethod(JavaAttributeInfo attr) |
| 1164 | throws IOException { |
| 1165 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
| 1166 | } |
| 1167 | |
| 1168 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1169 | * Adds from string method for union class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1170 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1171 | * @param javaAttributeInfo type attribute info |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1172 | * @param fromStringAttributeInfo from string attribute info |
| 1173 | * @throws IOException when fails to append to temporary file |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1174 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1175 | void addFromStringMethod(JavaAttributeInfo javaAttributeInfo, |
| 1176 | JavaAttributeInfo fromStringAttributeInfo) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1177 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1178 | appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, |
| 1179 | fromStringAttributeInfo) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1180 | } |
| 1181 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1182 | /** |
| 1183 | * Returns a temporary file handle for the specific file type. |
| 1184 | * |
| 1185 | * @param fileName file name |
| 1186 | * @return temporary file handle |
| 1187 | * @throws IOException when fails to create new file handle |
| 1188 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1189 | File getTemporaryFileHandle(String fileName) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1190 | throws IOException { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1191 | String path = getTempDirPath(getAbsoluteDirPath()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1192 | File dir = new File(path); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1193 | boolean isCreated; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1194 | if (!dir.exists()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1195 | isCreated = dir.mkdirs(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1196 | if (!isCreated) { |
| 1197 | throw new IOException("failed to create temporary directory for " + fileName); |
| 1198 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1199 | } |
| 1200 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
| 1201 | if (!file.exists()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1202 | isCreated = file.createNewFile(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1203 | if (!isCreated) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1204 | throw new IOException("failed to create temporary file for " + fileName); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1205 | } |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1206 | } else { |
| 1207 | throw new IOException(fileName + " is reused due to YANG naming"); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1208 | } |
| 1209 | return file; |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Returns a temporary file handle for the specific file type. |
| 1214 | * |
| 1215 | * @param fileName file name |
| 1216 | * @return temporary file handle |
| 1217 | * @throws IOException when fails to create new file handle |
| 1218 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1219 | File getJavaFileHandle(String fileName) |
| 1220 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1221 | return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * Returns data from the temporary files. |
| 1226 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1227 | * @param file temporary file handle |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1228 | * @param absolutePath absolute path |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1229 | * @return stored data from temporary files |
| 1230 | * @throws IOException when failed to get data from the given file |
| 1231 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1232 | public String getTemporaryDataFromFileHandle(File file, String absolutePath) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1233 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1234 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1235 | String path = getTempDirPath(absolutePath); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1236 | if (new File(path + file.getName()).exists()) { |
| 1237 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
| 1238 | } else { |
| 1239 | throw new IOException("Unable to get data from the given " |
| 1240 | + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Returns temporary directory path. |
| 1246 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1247 | * @param absolutePath absolute path |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1248 | * @return directory path |
| 1249 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1250 | private String getTempDirPath(String absolutePath) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1251 | return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName() |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1252 | + TEMP_FOLDER_NAME_SUFFIX + SLASH; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | * Parses attribute to get the attribute string. |
| 1257 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1258 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1259 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1260 | * @return attribute string |
| 1261 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1262 | String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1263 | /* |
| 1264 | * TODO: check if this utility needs to be called or move to the caller |
| 1265 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1266 | String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver()); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1267 | String attributeAccessType = PRIVATE; |
| 1268 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
| 1269 | attributeAccessType = PROTECTED; |
| 1270 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1271 | if (attr.isQualifiedName()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1272 | return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(), |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1273 | attr.getImportInfo().getClassInfo(), |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1274 | attributeName, attr.isListAttr(), attributeAccessType); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1275 | } else { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1276 | return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName, |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1277 | attr.isListAttr(), attributeAccessType); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Appends content to temporary file. |
| 1283 | * |
| 1284 | * @param file temporary file |
| 1285 | * @param data data to be appended |
| 1286 | * @throws IOException when fails to append to file |
| 1287 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1288 | void appendToFile(File file, String data) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1289 | throws IOException { |
| 1290 | try { |
| 1291 | insertDataIntoJavaFile(file, data); |
| 1292 | } catch (IOException ex) { |
| 1293 | throw new IOException("failed to write in temp file."); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1298 | * Adds parent's info to current node import list. |
| 1299 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1300 | * @param curNode current node for which import list needs to be updated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1301 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1302 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1303 | void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1304 | caseImportInfo = new JavaQualifiedTypeInfoTranslator(); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1305 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1306 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1307 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1308 | } |
| 1309 | if (!(curNode instanceof JavaFileInfoContainer)) { |
| 1310 | throw new TranslatorException("missing java file information to get the package details " |
| 1311 | + "of attribute corresponding to child node"); |
| 1312 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1313 | caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), |
| 1314 | pluginConfig.getConflictResolver()))); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1315 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1316 | |
| 1317 | JavaFileInfo fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 1318 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1319 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1320 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1321 | getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Adds leaf attributes in generated files. |
| 1326 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1327 | * @param listOfLeaves list of YANG leaf |
| 1328 | * @param yangPluginConfig plugin config |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1329 | * @param curNode current node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1330 | * @throws IOException IO operation fail |
| 1331 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1332 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
| 1333 | YangPluginConfig yangPluginConfig, YangNode curNode) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1334 | throws IOException { |
| 1335 | if (listOfLeaves != null) { |
| 1336 | for (YangLeaf leaf : listOfLeaves) { |
| 1337 | if (!(leaf instanceof JavaLeafInfoContainer)) { |
| 1338 | throw new TranslatorException("Leaf does not have java information"); |
| 1339 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1340 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
| 1341 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1342 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 1343 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf, |
| 1344 | yangPluginConfig), yangPluginConfig); |
| 1345 | } else { |
| 1346 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig), |
| 1347 | yangPluginConfig); |
| 1348 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * Adds leaf list's attributes in generated files. |
| 1355 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1356 | * @param listOfLeafList list of YANG leaves |
| 1357 | * @param yangPluginConfig plugin config |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1358 | * @param curNode current node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1359 | * @throws IOException IO operation fail |
| 1360 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1361 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig, |
| 1362 | YangNode curNode) throws IOException { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1363 | if (listOfLeafList != null) { |
| 1364 | for (YangLeafList leafList : listOfLeafList) { |
| 1365 | if (!(leafList instanceof JavaLeafInfoContainer)) { |
| 1366 | throw new TranslatorException("Leaf-list does not have java information"); |
| 1367 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1368 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
| 1369 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1370 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 1371 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles, |
| 1372 | leafList, yangPluginConfig), yangPluginConfig); |
| 1373 | } else { |
| 1374 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this, |
| 1375 | leafList, yangPluginConfig), yangPluginConfig); |
| 1376 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1382 | * Adds all the leaves in the current data model node as part of the generated temporary file. |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1383 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1384 | * @param curNode current node |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1385 | * @param yangPluginConfig plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1386 | * @throws IOException IO operation fail |
| 1387 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1388 | void addCurNodeLeavesInfoToTempFiles(YangNode curNode, |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1389 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1390 | throws IOException { |
| 1391 | if (!(curNode instanceof YangLeavesHolder)) { |
| 1392 | throw new TranslatorException("Data model node does not have any leaves"); |
| 1393 | } |
| 1394 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1395 | addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode); |
| 1396 | addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1400 | * Adds the new attribute info to the target generated temporary files. |
| 1401 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1402 | * @param newAttrInfo the attribute info that needs to be added to temporary files |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1403 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1404 | * @throws IOException IO operation fail |
| 1405 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1406 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1407 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1408 | setAttributePresent(true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1409 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1410 | addAttribute(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1411 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1412 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1413 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1414 | addGetterForInterface(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1415 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1416 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1417 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1418 | addSetterForInterface(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1419 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1420 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1421 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 1422 | addSetterImpl(newAttrInfo); |
| 1423 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1424 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1425 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1426 | addHashCodeMethod(newAttrInfo); |
| 1427 | } |
| 1428 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1429 | addEqualsMethod(newAttrInfo); |
| 1430 | } |
| 1431 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1432 | addToStringMethod(newAttrInfo); |
| 1433 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1434 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) { |
| 1435 | addAddToListImpl(newAttrInfo); |
| 1436 | } |
| 1437 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) { |
| 1438 | addAddToListInterface(newAttrInfo, pluginConfig); |
| 1439 | } |
| 1440 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr() |
| 1441 | && newAttrInfo.getAttributeType() != null) { |
| 1442 | leafCount++; |
| 1443 | addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig); |
| 1444 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1445 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1446 | if (!newAttrInfo.isIntConflict() && |
| 1447 | !newAttrInfo.isLongConflict()) { |
| 1448 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1449 | addGetterImpl(newAttrInfo, pluginConfig); |
| 1450 | } |
| 1451 | |
| 1452 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1453 | JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo, |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1454 | pluginConfig.getConflictResolver()); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1455 | /* |
| 1456 | * Create a new java attribute info with qualified information of |
| 1457 | * wrapper classes. |
| 1458 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1459 | JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString, |
| 1460 | newAttrInfo.getAttributeName(), |
| 1461 | newAttrInfo.getAttributeType(), |
| 1462 | getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1463 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1464 | addFromStringMethod(newAttrInfo, fromStringAttributeInfo); |
| 1465 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1466 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * Returns java class name. |
| 1471 | * |
| 1472 | * @param suffix for the class name based on the file type |
| 1473 | * @return java class name |
| 1474 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1475 | String getJavaClassName(String suffix) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1476 | return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /** |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1480 | * Returns java class name. |
| 1481 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1482 | * @param node YANG node |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1483 | * @return java class name |
| 1484 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1485 | private String getImplClassName(YangNode node) { |
| 1486 | if (node instanceof YangModule || node instanceof YangSubModule) { |
| 1487 | return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM; |
| 1488 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1489 | return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName()); |
| 1490 | } |
| 1491 | |
| 1492 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1493 | * Returns the directory path. |
| 1494 | * |
| 1495 | * @return directory path |
| 1496 | */ |
| 1497 | private String getDirPath() { |
| 1498 | return getJavaFileInfo().getPackageFilePath(); |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * Constructs java code exit. |
| 1503 | * |
| 1504 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1505 | * @param curNode current YANG node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1506 | * @throws IOException when fails to generate java files |
| 1507 | */ |
| 1508 | public void generateJavaFile(int fileType, YangNode curNode) |
| 1509 | throws IOException { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1510 | List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles() |
| 1511 | .getJavaImportData().getImports(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1512 | if (curNode instanceof YangAugmentableNode) { |
| 1513 | addImportsForAugmentableClass(imports, true, true); |
| 1514 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1515 | createPackage(curNode); |
| 1516 | |
| 1517 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1518 | * Generate java code. |
| 1519 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1520 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & |
| 1521 | BUILDER_INTERFACE_MASK) != 0) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1522 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1523 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1524 | * Create interface file. |
| 1525 | */ |
| 1526 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
| 1527 | setInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1528 | generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent())); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1529 | if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1530 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1531 | * Create builder interface file. |
| 1532 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1533 | if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1534 | setBuilderInterfaceJavaFileHandle( |
| 1535 | getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
| 1536 | setBuilderInterfaceJavaFileHandle( |
| 1537 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, |
| 1538 | isAttributePresent())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1539 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1540 | * Append builder interface file to interface file and close it. |
| 1541 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1542 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
| 1543 | validateLineLength(getInterfaceJavaFileHandle()); |
| 1544 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1545 | } |
| 1546 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1547 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1548 | if (curNode instanceof YangCase) { |
| 1549 | removeCaseImport(imports); |
| 1550 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1551 | if (curNode instanceof YangAugmentableNode) { |
| 1552 | addImportsForAugmentableClass(imports, false, true); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1553 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1554 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1555 | if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1556 | if (isAttributePresent()) { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1557 | addImportsToStringAndHasCodeMethods(imports, true); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1558 | addArrayListImport(imports); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1559 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1560 | addBitsetImport(imports); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1561 | if (curNode instanceof YangAugmentableNode) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1562 | addImportsForAugmentableClass(imports, true, false); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1563 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1564 | sortImports(imports); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1565 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1566 | * Create impl class file. |
| 1567 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1568 | setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode))); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1569 | setImplClassJavaFileHandle( |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1570 | generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports)); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1571 | |
| 1572 | /* |
| 1573 | * Create builder class file. |
| 1574 | */ |
| 1575 | if ((fileType & BUILDER_CLASS_MASK) != 0) { |
| 1576 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
| 1577 | setBuilderClassJavaFileHandle( |
| 1578 | generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode, |
| 1579 | isAttributePresent())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1580 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1581 | * Append impl class to builder class and close it. |
| 1582 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1583 | mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle()); |
| 1584 | validateLineLength(getImplClassJavaFileHandle()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1585 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1586 | insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose()); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1587 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1588 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1589 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1590 | * Close all the file handles. |
| 1591 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1592 | freeTemporaryResources(false); |
| 1593 | } |
| 1594 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1595 | /*Adds import for array list.*/ |
| 1596 | private void addArrayListImport(List<String> imports) { |
| 1597 | if (imports.contains(getJavaImportData().getImportForList())) { |
| 1598 | imports.add(ARRAY_LIST_IMPORT); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | /*Adds import for bitset list.*/ |
| 1603 | private void addBitsetImport(List<String> imports) { |
| 1604 | imports.add(getJavaImportData().getImportForToBitSet()); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1608 | * Adds imports for ToString and HashCodeMethod. |
| 1609 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1610 | * @param imports import list |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1611 | * @param operation add or remove |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1612 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1613 | void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1614 | if (operation) { |
| 1615 | imports.add(getJavaImportData().getImportForHashAndEquals()); |
| 1616 | imports.add(getJavaImportData().getImportForToString()); |
| 1617 | } else { |
| 1618 | imports.remove(getJavaImportData().getImportForHashAndEquals()); |
| 1619 | imports.remove(getJavaImportData().getImportForToString()); |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1624 | * Adds import for map and hash map. |
| 1625 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1626 | * @param imports import list |
| 1627 | * @param operations true for adding and false for deletion |
| 1628 | * @param isInterfaceFile if need to add in interface file |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1629 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1630 | private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile) { |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1631 | if (operations) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1632 | if (!isInterfaceFile) { |
| 1633 | imports.add(getJavaImportData().getHashMapImport()); |
| 1634 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1635 | imports.add(getJavaImportData().getMapImport()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1636 | addInvocationExceptionImport(imports); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1637 | } else { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1638 | if (!isInterfaceFile) { |
| 1639 | imports.remove(getJavaImportData().getHashMapImport()); |
| 1640 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1641 | imports.remove(getJavaImportData().getMapImport()); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1642 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1643 | sortImports(imports); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1647 | * Removes case import info from import list. |
| 1648 | * |
| 1649 | * @param imports list of imports |
| 1650 | * @return import for class |
| 1651 | */ |
| 1652 | private List<String> removeCaseImport(List<String> imports) { |
| 1653 | if (imports != null && caseImportInfo != null) { |
| 1654 | String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() + |
| 1655 | SEMI_COLAN + NEW_LINE; |
| 1656 | imports.remove(caseImport); |
| 1657 | } |
| 1658 | return imports; |
| 1659 | } |
| 1660 | |
| 1661 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1662 | * Adds invocation exception import. |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1663 | * |
| 1664 | * @param imports list of imports |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1665 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1666 | private void addInvocationExceptionImport(List<String> imports) { |
| 1667 | imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1671 | * Removes all temporary file handles. |
| 1672 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1673 | * @param isErrorOccurred flag to tell translator that error has occurred while file generation |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1674 | * @throws IOException when failed to delete the temporary files |
| 1675 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1676 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1677 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1678 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1679 | * Close all java file handles and when error occurs delete the files. |
| 1680 | */ |
| 1681 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1682 | closeFile(getInterfaceJavaFileHandle(), isErrorOccurred); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1683 | } |
| 1684 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1685 | closeFile(getBuilderClassJavaFileHandle(), true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1686 | } |
| 1687 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 1688 | closeFile(getBuilderInterfaceJavaFileHandle(), true); |
| 1689 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1690 | if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1691 | closeFile(getImplClassJavaFileHandle(), isErrorOccurred); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1692 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1693 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1694 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1695 | * Close all temporary file handles and delete the files. |
| 1696 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1697 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1698 | closeFile(getGetterImplTempFileHandle(), true); |
| 1699 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1700 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1701 | closeFile(getAttributesTempFileHandle(), true); |
| 1702 | } |
| 1703 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1704 | closeFile(getHashCodeImplTempFileHandle(), true); |
| 1705 | } |
| 1706 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1707 | closeFile(getToStringImplTempFileHandle(), true); |
| 1708 | } |
| 1709 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1710 | closeFile(getEqualsImplTempFileHandle(), true); |
| 1711 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1712 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 1713 | closeFile(getFromStringImplTempFileHandle(), true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1714 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1715 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) { |
| 1716 | closeFile(getAddToListImplTempFileHandle(), true); |
| 1717 | } |
| 1718 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) { |
| 1719 | closeFile(getAddToListInterfaceTempFileHandle(), true); |
| 1720 | } |
| 1721 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) { |
| 1722 | closeFile(getLeafIdAttributeTempFileHandle(), true); |
| 1723 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1727 | * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the |
| 1728 | * same needs to be done. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1729 | * |
| 1730 | * @param importInfo import info for the current attribute being added |
| 1731 | * @return status of the qualified access to the attribute |
| 1732 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1733 | boolean getIsQualifiedAccessOrAddToImportList( |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1734 | JavaQualifiedTypeInfoTranslator importInfo) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1735 | |
| 1736 | return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(), |
| 1737 | getJavaFileInfo().getPackage()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1738 | } |
| 1739 | |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1740 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1741 | * Returns temp file handle for add to list interface. |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1742 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1743 | * @return temp file handle for add to list interface |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1744 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1745 | public File getAddToListInterfaceTempFileHandle() { |
| 1746 | return addToListInterfaceTempFileHandle; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1750 | * Sets temp file handle for add to list interface. |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1751 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1752 | * @param addToListInterfaceTempFileHandle temp file handle for add to list interface |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1753 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame^] | 1754 | private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) { |
| 1755 | this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle; |
| 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * Returns temp file handle for add to list impl. |
| 1760 | * |
| 1761 | * @return temp file handle for add to list impl |
| 1762 | */ |
| 1763 | public File getAddToListImplTempFileHandle() { |
| 1764 | return addToListImplTempFileHandle; |
| 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * Sets temp file handle for add to list impl. |
| 1769 | * |
| 1770 | * @param addToListImplTempFileHandle temp file handle for add to list impl |
| 1771 | */ |
| 1772 | private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) { |
| 1773 | this.addToListImplTempFileHandle = addToListImplTempFileHandle; |
| 1774 | } |
| 1775 | |
| 1776 | /** |
| 1777 | * Returns temp file handle for leaf identifier attributes. |
| 1778 | * |
| 1779 | * @return temp file handle for leaf identifier attributes |
| 1780 | */ |
| 1781 | public File getLeafIdAttributeTempFileHandle() { |
| 1782 | return leafIdAttributeTempFileHandle; |
| 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * Sets temp file handle for leaf identifier attributes. |
| 1787 | * |
| 1788 | * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes. |
| 1789 | */ |
| 1790 | private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) { |
| 1791 | this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle; |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * Returns if root node is set. |
| 1796 | * |
| 1797 | * @return true if root node |
| 1798 | */ |
| 1799 | private boolean isRooNode() { |
| 1800 | return isRooNode; |
| 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * Sets true if root node. |
| 1805 | * |
| 1806 | * @param rooNode true if root node |
| 1807 | */ |
| 1808 | public void setRooNode(boolean rooNode) { |
| 1809 | isRooNode = rooNode; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1810 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1811 | } |