blob: 1988e5a53791a97bd3c8f5804217f23b44598dd8 [file] [log] [blame]
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301/*
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 */
16package org.onosproject.yangutils.translator.tojava;
17
18import java.io.File;
19import java.io.IOException;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053020import java.util.List;
Bharat saraswale304c252016-08-16 20:56:20 +053021
Bharat saraswale50edca2016-08-05 01:58:25 +053022import org.onosproject.yangutils.datamodel.YangAugment;
Bharat saraswalaf413b82016-07-14 15:18:20 +053023import org.onosproject.yangutils.datamodel.YangAugmentableNode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053024import org.onosproject.yangutils.datamodel.YangCase;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053025import org.onosproject.yangutils.datamodel.YangChoice;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053026import org.onosproject.yangutils.datamodel.YangLeaf;
27import org.onosproject.yangutils.datamodel.YangLeafList;
28import org.onosproject.yangutils.datamodel.YangLeavesHolder;
Vidyashree Ramab3670472016-08-06 15:49:56 +053029import org.onosproject.yangutils.datamodel.YangList;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053030import org.onosproject.yangutils.datamodel.YangModule;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053031import org.onosproject.yangutils.datamodel.YangNode;
Bharat saraswalaf413b82016-07-14 15:18:20 +053032import org.onosproject.yangutils.datamodel.YangSubModule;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053033import org.onosproject.yangutils.translator.exception.TranslatorException;
34import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Shankara-Huaweib7564772016-08-02 18:13:13 +053035import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053036import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053037import org.onosproject.yangutils.utils.io.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053038
Bharat saraswalc2d3be12016-06-16 00:29:12 +053039import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053040import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
41import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053042import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053043import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Bharat saraswalaf413b82016-07-14 15:18:20 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
46import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
49import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053050import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053052import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
54import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
55import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
Bharat saraswal250a7472016-05-12 13:16:57 +053056import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053057import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
58import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
59import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053060import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053061import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
62import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
63import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
64import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Shankara-Huaweib7564772016-08-02 18:13:13 +053065import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
66import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053067import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
Bharat saraswal8beac342016-08-04 02:00:03 +053068import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
69import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053070import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
Bharat saraswalaf413b82016-07-14 15:18:20 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053072import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
73import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswal8beac342016-08-04 02:00:03 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053075import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053076import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswald14cbe82016-07-14 13:26:18 +053077import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
Bharat saraswal8beac342016-08-04 02:00:03 +053078import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
79import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053080import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053081import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
82import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053084import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
85import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
86import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053087import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053088import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
89import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
90import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053091import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +053092import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
93 .getSubtreeFilteringForLeaf;
94import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
95 .getSubtreeFilteringForLeafList;
96import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
97 .getSubtreeFilteringForNode;
Bharat saraswal8beac342016-08-04 02:00:03 +053098import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053099import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530100import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530101import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
102import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530103import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530104import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530105import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530106import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530107import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530108import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
109import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530110import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530111import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530112import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530113import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswal8beac342016-08-04 02:00:03 +0530114import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530115import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswale304c252016-08-16 20:56:20 +0530116import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530117import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530118import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530119import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
120import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
121import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530122import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
123import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530124import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530125
126/**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530127 * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for
128 * Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530129 */
130public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530131
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530132 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530133 * File type extension for java classes.
134 */
135 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530136
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530137 /**
138 * File type extension for temporary classes.
139 */
140 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530141
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530142 /**
143 * Folder suffix for temporary files folder.
144 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530145 private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530146
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530147 /**
148 * File name for getter method.
149 */
150 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530151
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530152 /**
153 * File name for setter method.
154 */
155 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530156
157 /**
158 * File name for getter method implementation.
159 */
160 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
161
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530162 /**
163 * File name for setter method implementation.
164 */
165 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530166
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530167 /**
168 * File name for attributes.
169 */
170 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530171
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530172 /**
173 * File name for to string method.
174 */
175 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530176
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530177 /**
178 * File name for hash code method.
179 */
180 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530181
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530182 /**
183 * File name for equals method.
184 */
185 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530186
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530187 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530188 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530189 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530190 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530191
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530192 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530193 * File name for from add to list interface method.
194 */
195 private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList";
196
197 /**
198 * File name for from add to list impl method.
199 */
200 private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl";
201
202 /**
203 * File name for from leaf identifier attributes.
204 */
205 private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr";
206
207 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530208 * File name for is filter content leaf match.
209 */
210 private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME = "isFilterContentMatchLeafMask";
211
212 /**
213 * File name for is filter content leaf-list match.
214 */
215 private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME = "isFilterContentMatchLeafListMask";
216
217 /**
218 * File name for is filter content node match.
219 */
220 private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME = "isFilterContentMatchNodeMask";
221
222 /**
223 * File name for edit content file.
224 */
225 private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
226
227 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530228 * File name for interface java file name suffix.
229 */
230 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530231
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530232 /**
233 * File name for builder interface file name suffix.
234 */
235 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530236
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530237 /**
238 * File name for builder class file name suffix.
239 */
240 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530241
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530242 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530243 * Information about the java files being generated.
244 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530245 private JavaFileInfoTranslator javaFileInfo;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530246
247 /**
248 * Imported class info.
249 */
250 private JavaImportData javaImportData;
251
252 /**
253 * The variable which guides the types of temporary files generated using the temporary generated file types mask.
254 */
255 private int generatedTempFiles;
256
257 /**
258 * Absolute path where the target java file needs to be generated.
259 */
260 private String absoluteDirPath;
261
262 /**
263 * Contains all the interface(s)/class name which will be extended by generated files.
264 */
265 private JavaExtendsListHolder javaExtendsListHolder;
266
Bharat saraswald14cbe82016-07-14 13:26:18 +0530267 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530268 * Java file handle for interface file.
269 */
270 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530271
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530272 /**
273 * Java file handle for builder interface file.
274 */
275 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530276
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530277 /**
278 * Java file handle for builder class file.
279 */
280 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530281
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530282 /**
283 * Java file handle for impl class file.
284 */
285 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530286
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530287 /**
288 * Temporary file handle for attribute.
289 */
290 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530291
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530292 /**
293 * Temporary file handle for getter of interface.
294 */
295 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530296
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530297 /**
298 * Temporary file handle for setter of interface.
299 */
300 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530301
302 /**
303 * Temporary file handle for getter of class.
304 */
305 private File getterImplTempFileHandle;
306
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530307 /**
308 * Temporary file handle for setter of class.
309 */
310 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530311
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530312 /**
313 * Temporary file handle for hash code method of class.
314 */
315 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530316
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530317 /**
318 * Temporary file handle for equals method of class.
319 */
320 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530321
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530322 /**
323 * Temporary file handle for to string method of class.
324 */
325 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530326
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530327 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530328 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530329 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530330 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530331
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530332 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530333 * Temporary file handle for add to list interface method of class.
334 */
335 private File addToListInterfaceTempFileHandle;
336
337 /**
338 * Temporary file handle for add to list impl method of class.
339 */
340 private File addToListImplTempFileHandle;
341
342 /**
343 * Temporary file handle for leaf id attributes of enum.
344 */
345 private File leafIdAttributeTempFileHandle;
346
347 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530348 * Temporary file handle for is content match method for leaf-list.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530349 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530350 private File getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530351
352 /**
353 * Temporary file handle for is content match method for node.
354 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530355 private File getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530356
357 /**
358 * Temporary file handle for is content match method for leaf.
359 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530360 private File subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530361
362 /**
363 * Temporary file handle for edit content file.
364 */
365 private File editContentTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530366
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530367 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530368 * Leaf count.
369 */
370 private int leafCount = 0;
371
372 /**
373 * If current node is root node.
374 */
375 private boolean isRooNode;
376
377 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530378 * Is attribute added.
379 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530380 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530381
Bharat saraswalaf413b82016-07-14 15:18:20 +0530382 TempJavaFragmentFiles() {
383 }
384
385 /**
386 * Creates an instance of temporary java code fragment.
387 *
388 * @param javaFileInfo generated java file information
389 * @throws IOException when fails to create new file handle
390 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530391 TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530392 throws IOException {
393 setJavaExtendsListHolder(new JavaExtendsListHolder());
394 setJavaImportData(new JavaImportData());
395 setJavaFileInfo(javaFileInfo);
Bharat saraswal8beac342016-08-04 02:00:03 +0530396 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
397 getJavaFileInfo().getPackageFilePath()));
398
Bharat saraswalaf413b82016-07-14 15:18:20 +0530399 /*
400 * Initialize getter when generation file type matches to interface
401 * mask.
402 */
403 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
404 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
Bharat saraswal8beac342016-08-04 02:00:03 +0530405 addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK);
406 addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530407 }
408
409 /*
410 * Initialize getter and setter when generation file type matches to
411 * builder interface mask.
412 */
413 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
414 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
415 addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
416 }
417
418 /*
419 * Initialize getterImpl, setterImpl and attributes when generation file
420 * type matches to builder class mask.
421 */
422 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
423 addGeneratedTempFile(ATTRIBUTES_MASK);
424 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
425 addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530426 }
427
428 /*
429 * Initialize getterImpl, attributes, constructor, hash code, equals and
430 * to strings when generation file type matches to impl class mask.
431 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530432 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530433 addGeneratedTempFile(ATTRIBUTES_MASK);
434 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
435 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
436 addGeneratedTempFile(EQUALS_IMPL_MASK);
437 addGeneratedTempFile(TO_STRING_IMPL_MASK);
Bharat saraswal8beac342016-08-04 02:00:03 +0530438 addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK);
Bharat saraswale50edca2016-08-05 01:58:25 +0530439 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK);
440 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_MASK);
441 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_NODES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530442 }
443
444 /*
445 * Initialize temp files to generate type class.
446 */
447 if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
448 addGeneratedTempFile(ATTRIBUTES_MASK);
449 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
450 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
451 addGeneratedTempFile(EQUALS_IMPL_MASK);
452 addGeneratedTempFile(TO_STRING_IMPL_MASK);
453 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
454 }
455
Vidyashree Ramab3670472016-08-06 15:49:56 +0530456 //Initialize temp files to generate enum class.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530457 if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
458 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
459 }
460
Vidyashree Ramab3670472016-08-06 15:49:56 +0530461 //Set temporary file handles
Bharat saraswalaf413b82016-07-14 15:18:20 +0530462 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
463 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
464 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530465 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
466 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
467 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530468 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
469 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
470 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530471 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
472 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
473 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530474 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
475 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
476 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530477 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
478 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
479 }
480 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
481 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
482 }
483 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
484 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
485 }
486 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
487 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
488 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530489 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
490 setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME));
491 }
492 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
493 setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME));
494 }
495 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
496 setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME));
497 }
Bharat saraswale50edca2016-08-05 01:58:25 +0530498 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530499 setSubtreeFilteringForLeafTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530500 }
501 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530502 setGetSubtreeFilteringForListTempFileHandle(
503 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530504 }
505 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530506 setGetSubtreeFilteringForChildNodeTempFileHandle(
507 getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530508 }
509 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
510 setEditContentTempFileHandle(getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME));
511 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530512 }
513
514 /**
515 * Adds current node info as and attribute to the parent generated file.
516 *
517 * @param curNode current node which needs to be added as an attribute in the parent generated code
518 * @param isList is list construct
519 * @param pluginConfig plugin configurations
520 * @throws IOException IO operation exception
521 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530522 static void addCurNodeInfoInParentTempFile(YangNode curNode,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530523 boolean isList, YangPluginConfig pluginConfig)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530524 throws IOException {
525 YangNode parent = getParentNodeInGenCode(curNode);
526 if (!(parent instanceof JavaCodeGenerator)) {
527 throw new TranslatorException("missing parent node to contain current node info in generated file");
528 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530529
Shankara-Huaweib7564772016-08-02 18:13:13 +0530530 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530531 /*
532 * In case of grouping, there is no need to add the information, it
533 * will be taken care in uses
534 */
535 return;
536 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530537
Bharat saraswalaf413b82016-07-14 15:18:20 +0530538 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
539 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
540
541 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
542 parent, isList, tempJavaBeanFragmentFiles);
Bharat saraswal8beac342016-08-04 02:00:03 +0530543 tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530544 }
545
546 /**
547 * Creates an attribute info object corresponding to a data model node and return it.
548 *
549 * @param curNode current data model node for which the java code generation is being handled
550 * @param targetNode target node in which the current node is an attribute
551 * @param isListNode is the current added attribute needs to be a list
552 * @param tempJavaFragmentFiles temp java fragment files
553 * @return AttributeInfo attribute details required to add in temporary files
554 */
555 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530556 YangNode targetNode, boolean isListNode,
557 TempJavaFragmentFiles tempJavaFragmentFiles) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530558 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
559 if (curNodeName == null) {
560 updateJavaFileInfo(curNode, null);
561 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
562 }
563
564 /*
565 * Get the import info corresponding to the attribute for import in
566 * generated java files or qualified access
567 */
Shankara-Huaweib7564772016-08-02 18:13:13 +0530568 JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
Bharat saraswalaf413b82016-07-14 15:18:20 +0530569 getCapitalCase(curNodeName));
570 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
571 throw new TranslatorException("Parent node does not have file info");
572 }
573 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
Bharat saraswale50edca2016-08-05 01:58:25 +0530574 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530575
576 boolean isQualified;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530577 if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
Bharat saraswal8beac342016-08-04 02:00:03 +0530578 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
579 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530580
581 isQualified = true;
582 } else {
583 String className;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530584 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530585 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530586 } else {
587 className = getCapitalCase(fileInfo.getJavaName());
588 }
589
590 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
591 className, fileInfo.getPackage());
592 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530593 boolean collectionSetFlag = false;
594 if (curNode instanceof YangList) {
595 YangList yangList = (YangList) curNode;
596 if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
597 .getYangAppDataStructure() != null) {
598 switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
599 case QUEUE: {
600 parentImportData.setQueueToImport(true);
601 collectionSetFlag = true;
602 break;
603 }
604 case SET: {
605 parentImportData.setSetToImport(true);
606 collectionSetFlag = true;
607 break;
608 }
609 default: {
610 // TODO : to be implemented
611 }
612 }
613 }
614 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530615 if (isListNode && !(collectionSetFlag)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530616 parentImportData.setIfListImported(true);
617 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530618 if (curNode instanceof YangList) {
619 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
620 ((YangList) curNode).getCompilerAnnotation());
621 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530622 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
623 }
624
625 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530626 * Returns java attribute for leaf.
627 *
628 * @param tempJavaFragmentFiles temporary generated file
629 * @param leaf YANG leaf
630 * @param yangPluginConfig plugin configurations
631 * @return java attribute for leaf
632 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530633 private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530634 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530635 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
636 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
637 javaLeaf.updateJavaQualifiedInfo();
638 return getAttributeInfoForTheData(
639 javaLeaf.getJavaQualifiedInfo(),
640 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
641 javaLeaf.getDataType(),
642 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
643 false);
644 }
645
646 /**
647 * Returns java attribute for leaf-list.
648 *
649 * @param tempJavaFragmentFiles temporary generated file
650 * @param leafList YANG leaf-list
651 * @param yangPluginConfig plugin configurations
652 * @return java attribute for leaf-list
653 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530654 private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530655 YangLeafList leafList,
656 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530657 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
658 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
659 javaLeaf.updateJavaQualifiedInfo();
660 tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
661 return getAttributeInfoForTheData(
662 javaLeaf.getJavaQualifiedInfo(),
663 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
664 javaLeaf.getDataType(),
665 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
666 true);
667 }
668
Bharat saraswal039f59c2016-07-14 21:57:13 +0530669 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530670 * Retrieves the absolute path where the file needs to be generated.
671 *
672 * @return absolute path where the file needs to be generated
673 */
674 private String getAbsoluteDirPath() {
675 return absoluteDirPath;
676 }
677
678 /**
679 * Sets absolute path where the file needs to be generated.
680 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530681 * @param absoluteDirPath absolute path where the file needs to be generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530682 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530683 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530684 this.absoluteDirPath = absoluteDirPath;
685 }
686
687 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530688 * Retrieves the generated java file information.
689 *
690 * @return generated java file information
691 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530692 public JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530693 return javaFileInfo;
694 }
695
696 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530697 * Sets the generated java file information.
698 *
699 * @param javaFileInfo generated java file information
700 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530701 public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530702 this.javaFileInfo = javaFileInfo;
703 }
704
705 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530706 * Retrieves the generated temp files.
707 *
708 * @return generated temp files
709 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530710 int getGeneratedTempFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530711 return generatedTempFiles;
712 }
713
714 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530715 * Sets generated file files.
716 *
717 * @param fileType generated file type
718 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530719 private void setGeneratedTempFiles(int fileType) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530720 generatedTempFiles = fileType;
721 }
722
723 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530724 * Adds to generated temporary files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530725 *
726 * @param generatedTempFile generated file
727 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530728 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530729 generatedTempFiles |= generatedTempFile;
Bharat saraswal250a7472016-05-12 13:16:57 +0530730 setGeneratedTempFiles(generatedTempFiles);
731 }
732
733 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530734 * Retrieves the generated Java files.
735 *
736 * @return generated Java files
737 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530738 int getGeneratedJavaFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530739 return getJavaFileInfo().getGeneratedFileTypes();
740 }
741
742 /**
743 * Retrieves the mapped Java class name.
744 *
745 * @return mapped Java class name
746 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530747 String getGeneratedJavaClassName() {
janani b703cfe42016-05-17 13:12:22 +0530748 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530749 }
750
751 /**
752 * Retrieves the import data for the generated Java file.
753 *
754 * @return import data for the generated Java file
755 */
756 public JavaImportData getJavaImportData() {
757 return javaImportData;
758 }
759
760 /**
761 * Sets import data for the generated Java file.
762 *
763 * @param javaImportData import data for the generated Java file
764 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530765 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530766 this.javaImportData = javaImportData;
767 }
768
769 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530770 * Retrieves the status of any attributes added.
771 *
772 * @return status of any attributes added
773 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530774 boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530775 return isAttributePresent;
776 }
777
778 /**
779 * Sets status of any attributes added.
780 *
781 * @param attributePresent status of any attributes added
782 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530783 private void setAttributePresent(boolean attributePresent) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530784 isAttributePresent = attributePresent;
785 }
786
787 /**
788 * Returns getter methods's temporary file handle.
789 *
790 * @return temporary file handle
791 */
792 public File getGetterInterfaceTempFileHandle() {
793 return getterInterfaceTempFileHandle;
794 }
795
796 /**
797 * Sets to getter method's temporary file handle.
798 *
799 * @param getterForInterface file handle for to getter method
800 */
801 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
802 getterInterfaceTempFileHandle = getterForInterface;
803 }
804
805 /**
806 * Returns setter method's temporary file handle.
807 *
808 * @return temporary file handle
809 */
810 public File getSetterInterfaceTempFileHandle() {
811 return setterInterfaceTempFileHandle;
812 }
813
814 /**
815 * Sets to setter method's temporary file handle.
816 *
817 * @param setterForInterface file handle for to setter method
818 */
819 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
820 setterInterfaceTempFileHandle = setterForInterface;
821 }
822
823 /**
824 * Returns setter method's impl's temporary file handle.
825 *
826 * @return temporary file handle
827 */
828 public File getSetterImplTempFileHandle() {
829 return setterImplTempFileHandle;
830 }
831
832 /**
833 * Sets to setter method's impl's temporary file handle.
834 *
835 * @param setterImpl file handle for to setter method's implementation class
836 */
837 private void setSetterImplTempFileHandle(File setterImpl) {
838 setterImplTempFileHandle = setterImpl;
839 }
840
841 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530842 * Returns from string method's temporary file handle.
843 *
844 * @return from string method's temporary file handle
845 */
846 public File getFromStringImplTempFileHandle() {
847 return fromStringImplTempFileHandle;
848 }
849
850 /**
851 * Sets from string method's temporary file handle.
852 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530853 * @param fromStringImplTempFileHandle from string method's temporary file handle
Bharat saraswal250a7472016-05-12 13:16:57 +0530854 */
855 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
856 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
857 }
858
859 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530860 * Returns java file handle for interface file.
861 *
862 * @return java file handle for interface file
863 */
864 private File getInterfaceJavaFileHandle() {
865 return interfaceJavaFileHandle;
866 }
867
868 /**
869 * Sets the java file handle for interface file.
870 *
871 * @param interfaceJavaFileHandle java file handle
872 */
873 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
874 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
875 }
876
877 /**
878 * Returns java file handle for builder interface file.
879 *
880 * @return java file handle for builder interface file
881 */
882 private File getBuilderInterfaceJavaFileHandle() {
883 return builderInterfaceJavaFileHandle;
884 }
885
886 /**
887 * Sets the java file handle for builder interface file.
888 *
889 * @param builderInterfaceJavaFileHandle java file handle
890 */
891 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
892 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
893 }
894
895 /**
896 * Returns java file handle for builder class file.
897 *
898 * @return java file handle for builder class file
899 */
900 private File getBuilderClassJavaFileHandle() {
901 return builderClassJavaFileHandle;
902 }
903
904 /**
905 * Sets the java file handle for builder class file.
906 *
907 * @param builderClassJavaFileHandle java file handle
908 */
909 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
910 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
911 }
912
913 /**
914 * Returns java file handle for impl class file.
915 *
916 * @return java file handle for impl class file
917 */
918 private File getImplClassJavaFileHandle() {
919 return implClassJavaFileHandle;
920 }
921
922 /**
923 * Sets the java file handle for impl class file.
924 *
925 * @param implClassJavaFileHandle java file handle
926 */
927 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
928 this.implClassJavaFileHandle = implClassJavaFileHandle;
929 }
930
931 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530932 * Returns attribute's temporary file handle.
933 *
934 * @return temporary file handle
935 */
936 public File getAttributesTempFileHandle() {
937 return attributesTempFileHandle;
938 }
939
940 /**
941 * Sets attribute's temporary file handle.
942 *
943 * @param attributeForClass file handle for attribute
944 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530945 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530946 attributesTempFileHandle = attributeForClass;
947 }
948
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530949 /**
950 * Returns getter method's impl's temporary file handle.
951 *
952 * @return temporary file handle
953 */
954 public File getGetterImplTempFileHandle() {
955 return getterImplTempFileHandle;
956 }
957
958 /**
959 * Sets to getter method's impl's temporary file handle.
960 *
961 * @param getterImpl file handle for to getter method's impl
962 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530963 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530964 getterImplTempFileHandle = getterImpl;
965 }
966
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530967 /**
968 * Returns hash code method's temporary file handle.
969 *
970 * @return temporary file handle
971 */
972 public File getHashCodeImplTempFileHandle() {
973 return hashCodeImplTempFileHandle;
974 }
975
976 /**
977 * Sets hash code method's temporary file handle.
978 *
979 * @param hashCodeMethod file handle for hash code method
980 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530981 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530982 hashCodeImplTempFileHandle = hashCodeMethod;
983 }
984
985 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530986 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530987 *
988 * @return temporary file handle
989 */
990 public File getEqualsImplTempFileHandle() {
991 return equalsImplTempFileHandle;
992 }
993
994 /**
995 * Sets equals method's temporary file handle.
996 *
997 * @param equalsMethod file handle for to equals method
998 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530999 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301000 equalsImplTempFileHandle = equalsMethod;
1001 }
1002
1003 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301004 * Returns to string method's temporary file handle.
1005 *
1006 * @return temporary file handle
1007 */
1008 public File getToStringImplTempFileHandle() {
1009 return toStringImplTempFileHandle;
1010 }
1011
1012 /**
1013 * Sets to string method's temporary file handle.
1014 *
1015 * @param toStringMethod file handle for to string method
1016 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301017 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301018 toStringImplTempFileHandle = toStringMethod;
1019 }
1020
1021 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301022 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301023 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301024 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301025 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301026 public JavaExtendsListHolder getJavaExtendsListHolder() {
1027 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301028 }
1029
1030 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301031 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301032 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301033 * @param javaExtendsListHolder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301034 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301035 void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301036 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301037 }
1038
1039 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301040 * Adds is filter content match for leaf.
1041 *
1042 * @param attr java attribute
1043 * @throws IOException when fails to do IO operations
1044 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301045 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301046 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301047 appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
1048 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301049 }
1050
1051 /**
1052 * Adds is filter content match for leaf-list.
1053 *
1054 * @param attr java attribute
1055 * @throws IOException when fails to do IO operations
1056 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301057 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301058 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301059 appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
1060 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301061 }
1062
1063 /**
1064 * Adds is filter content match for nodes.
1065 *
1066 * @param attr java attribute
1067 * @throws IOException when fails to do IO operations
1068 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301069 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301070 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301071 appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
1072 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301073 }
1074
1075 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301076 * Adds attribute for class.
1077 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301078 * @param attr attribute info
1079 * @param yangPluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301080 * @throws IOException when fails to append to temporary file
1081 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301082 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301083 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301084 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
1085 + FOUR_SPACE_INDENTATION);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301086 }
1087
1088 /**
1089 * Adds getter for interface.
1090 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301091 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301092 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301093 * @throws IOException when fails to append to temporary file
1094 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301095 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301096 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301097 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301098 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301099 }
1100
1101 /**
1102 * Adds setter for interface.
1103 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301104 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301105 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301106 * @throws IOException when fails to append to temporary file
1107 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301108 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301109 throws IOException {
1110 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301111 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
1112 + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301113 }
1114
1115 /**
1116 * Adds setter's implementation for class.
1117 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301118 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301119 * @throws IOException when fails to append to temporary file
1120 */
Bharat saraswale304c252016-08-16 20:56:20 +05301121 private void addSetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301122 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301123 if (isRooNode()) {
Bharat saraswale304c252016-08-16 20:56:20 +05301124 appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
1125 attr.isListAttr(), pluginConfig, null) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301126 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
Bharat saraswale304c252016-08-16 20:56:20 +05301127 + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301128 } else {
1129 appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
1130 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
1131 + NEW_LINE);
1132 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301133 }
1134
1135 /**
1136 * Adds getter method's impl for class.
1137 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301138 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301139 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301140 * @throws IOException when fails to append to temporary file
1141 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301142 void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301143 throws IOException {
1144 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
1145 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301146 if (!isRooNode()) {
1147 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
1148 getGeneratedJavaFiles()) + NEW_LINE);
1149 } else {
1150 appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
1151 getGeneratedJavaFiles()) + NEW_LINE);
1152 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301153 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301154 String appDataStructure = null;
1155 if (attr.getCompilerAnnotation() != null) {
1156 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1157 }
janani b703cfe42016-05-17 13:12:22 +05301158 appendToFile(getGetterImplTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301159 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
1160 appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301161 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301162 }
1163
1164 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301165 * Adds add to list interface method.
1166 *
1167 * @param attr attribute
1168 * @param pluginConfig plugin configurations
1169 * @throws IOException when fails to do IO operations
1170 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301171 private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
1172 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301173 appendToFile(getAddToListInterfaceTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301174 getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301175 + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301176 }
1177
1178 /**
1179 * Adds add to list interface method.
1180 *
1181 * @param attr attribute
1182 * @throws IOException when fails to do IO operations
1183 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301184 private void addAddToListImpl(JavaAttributeInfo attr)
1185 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301186 appendToFile(getAddToListImplTempFileHandle(),
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301187 getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301188 }
1189
1190 /**
1191 * Adds leaf identifier enum attributes.
1192 *
1193 * @param attr attribute
1194 * @param value value
1195 * @param yangPluginConfig plugin config
1196 * @throws IOException when fails to do IO operations
1197 */
1198 private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
1199 throws IOException {
1200 appendToFile(getLeafIdAttributeTempFileHandle(),
1201 FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
1202 value, yangPluginConfig));
1203 }
1204
1205 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301206 * Adds build method for interface.
1207 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301208 * @param pluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301209 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301210 * @throws IOException when fails to append to temporary file
1211 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301212 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301213 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301214 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301215 }
1216
1217 /**
1218 * Adds build method's implementation for class.
1219 *
1220 * @return build method implementation for class
1221 * @throws IOException when fails to append to temporary file
1222 */
1223 String addBuildMethodImpl()
1224 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301225 return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301226 }
1227
1228 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301229 * Adds default constructor for class.
1230 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301231 * @param modifier modifier for constructor.
1232 * @param toAppend string which need to be appended with the class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301233 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +05301234 * @param isSuffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301235 * @return default constructor for class
1236 * @throws IOException when fails to append to file
1237 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301238 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301239 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301240 String name = getGeneratedJavaClassName();
1241 if (isRooNode() && !toAppend.equals(BUILDER)) {
1242 name = name + OP_PARAM;
1243 return NEW_LINE
1244 + getDefaultConstructorString(name, modifier,
1245 pluginConfig);
1246 }
1247 if (isSuffix) {
1248 return NEW_LINE +
1249 getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
1250 }
1251 String appended;
1252 if (toAppend.equals(DEFAULT)) {
1253 appended = getCapitalCase(toAppend);
1254 } else {
1255 appended = toAppend;
1256 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301257 return NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +05301258 + getDefaultConstructorString(appended + name, modifier,
1259 pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301260 }
1261
1262 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301263 * Adds hash code method for class.
1264 *
1265 * @param attr attribute info
1266 * @throws IOException when fails to append to temporary file
1267 */
1268 private void addHashCodeMethod(JavaAttributeInfo attr)
1269 throws IOException {
1270 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
1271 }
1272
1273 /**
1274 * Adds equals method for class.
1275 *
1276 * @param attr attribute info
1277 * @throws IOException when fails to append to temporary file
1278 */
1279 private void addEqualsMethod(JavaAttributeInfo attr)
1280 throws IOException {
1281 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
1282 }
1283
1284 /**
1285 * Adds ToString method for class.
1286 *
1287 * @param attr attribute info
1288 * @throws IOException when fails to append to temporary file
1289 */
1290 private void addToStringMethod(JavaAttributeInfo attr)
1291 throws IOException {
1292 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
1293 }
1294
1295 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301296 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301297 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301298 * @param javaAttributeInfo type attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301299 * @param fromStringAttributeInfo from string attribute info
1300 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301301 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301302 void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301303 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301304 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301305 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
1306 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301307 }
1308
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301309 /**
1310 * Returns a temporary file handle for the specific file type.
1311 *
1312 * @param fileName file name
1313 * @return temporary file handle
1314 * @throws IOException when fails to create new file handle
1315 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301316 File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301317 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301318 String path = getTempDirPath(getAbsoluteDirPath());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301319 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301320 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301321 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301322 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301323 if (!isCreated) {
1324 throw new IOException("failed to create temporary directory for " + fileName);
1325 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301326 }
1327 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1328 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301329 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301330 if (!isCreated) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301331 throw new IOException("failed to create temporary file for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301332 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301333 } else {
1334 throw new IOException(fileName + " is reused due to YANG naming");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301335 }
1336 return file;
1337 }
1338
1339 /**
1340 * Returns a temporary file handle for the specific file type.
1341 *
1342 * @param fileName file name
1343 * @return temporary file handle
1344 * @throws IOException when fails to create new file handle
1345 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301346 File getJavaFileHandle(String fileName)
1347 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301348 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301349 }
1350
1351 /**
1352 * Returns data from the temporary files.
1353 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301354 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301355 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301356 * @return stored data from temporary files
1357 * @throws IOException when failed to get data from the given file
1358 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301359 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301360 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301361 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301362 if (new File(path + file.getName()).exists()) {
1363 return readAppendFile(path + file.getName(), EMPTY_STRING);
1364 } else {
1365 throw new IOException("Unable to get data from the given "
1366 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
1367 }
1368 }
1369
1370 /**
1371 * Returns temporary directory path.
1372 *
Bharat saraswald14cbe82016-07-14 13:26:18 +05301373 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301374 * @return directory path
1375 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301376 private String getTempDirPath(String absolutePath) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301377 return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
Bharat saraswal64e7e232016-07-14 23:33:55 +05301378 + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301379 }
1380
1381 /**
1382 * Parses attribute to get the attribute string.
1383 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301384 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301385 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301386 * @return attribute string
1387 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301388 String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301389 /*
1390 * TODO: check if this utility needs to be called or move to the caller
1391 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301392 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301393 String attributeAccessType = PRIVATE;
1394 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
1395 attributeAccessType = PROTECTED;
1396 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301397 if (attr.isQualifiedName()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301398 return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
Bharat saraswal250a7472016-05-12 13:16:57 +05301399 attr.getImportInfo().getClassInfo(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301400 attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301401 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301402 return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
Vidyashree Ramab3670472016-08-06 15:49:56 +05301403 attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301404 }
1405 }
1406
1407 /**
1408 * Appends content to temporary file.
1409 *
1410 * @param file temporary file
1411 * @param data data to be appended
1412 * @throws IOException when fails to append to file
1413 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301414 void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301415 throws IOException {
1416 try {
1417 insertDataIntoJavaFile(file, data);
1418 } catch (IOException ex) {
1419 throw new IOException("failed to write in temp file.");
1420 }
1421 }
1422
1423 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301424 * Adds parent's info to current node import list.
1425 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301426 * @param curNode current node for which import list needs to be updated
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301427 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301428 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301429 void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301430 JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301431 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301432 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1433 return;
1434 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301435 if (!(parent instanceof JavaCodeGenerator)) {
1436 throw new TranslatorException("missing parent node to contain current node info in generated file");
1437 }
1438 if (!(curNode instanceof JavaFileInfoContainer)) {
1439 throw new TranslatorException("missing java file information to get the package details "
1440 + "of attribute corresponding to child node");
1441 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301442 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1443 pluginConfig.getConflictResolver())));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301444 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301445
Bharat saraswale50edca2016-08-05 01:58:25 +05301446 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301447
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301448 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301449 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
Bharat saraswald14cbe82016-07-14 13:26:18 +05301450 getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301451 }
1452
1453 /**
1454 * Adds leaf attributes in generated files.
1455 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301456 * @param listOfLeaves list of YANG leaf
1457 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301458 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301459 * @throws IOException IO operation fail
1460 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301461 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301462 YangPluginConfig yangPluginConfig, YangNode curNode)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301463 throws IOException {
1464 if (listOfLeaves != null) {
1465 for (YangLeaf leaf : listOfLeaves) {
1466 if (!(leaf instanceof JavaLeafInfoContainer)) {
1467 throw new TranslatorException("Leaf does not have java information");
1468 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301469 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1470 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1471 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1472 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
1473 yangPluginConfig), yangPluginConfig);
1474 } else {
1475 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
1476 yangPluginConfig);
1477 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301478 }
1479 }
1480 }
1481
1482 /**
1483 * Adds leaf list's attributes in generated files.
1484 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301485 * @param listOfLeafList list of YANG leaves
1486 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301487 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301488 * @throws IOException IO operation fail
1489 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301490 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301491 YangNode curNode)
1492 throws IOException {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301493 if (listOfLeafList != null) {
1494 for (YangLeafList leafList : listOfLeafList) {
1495 if (!(leafList instanceof JavaLeafInfoContainer)) {
1496 throw new TranslatorException("Leaf-list does not have java information");
1497 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301498 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1499 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1500 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1501 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
1502 leafList, yangPluginConfig), yangPluginConfig);
1503 } else {
1504 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
1505 leafList, yangPluginConfig), yangPluginConfig);
1506 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301507 }
1508 }
1509 }
1510
1511 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301512 * Adds all the leaves in the current data model node as part of the generated temporary file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301513 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301514 * @param curNode current node
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301515 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301516 * @throws IOException IO operation fail
1517 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301518 void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301519 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301520 throws IOException {
1521 if (!(curNode instanceof YangLeavesHolder)) {
1522 throw new TranslatorException("Data model node does not have any leaves");
1523 }
1524 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301525 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
1526 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301527 }
1528
1529 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301530 * Adds the new attribute info to the target generated temporary files.
1531 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301532 * @param newAttrInfo the attribute info that needs to be added to temporary files
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301533 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301534 * @throws IOException IO operation fail
1535 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301536 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301537 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301538 setAttributePresent(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301539 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301540 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301541 }
1542 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301543 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301544 }
1545 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301546 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301547 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301548 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswale304c252016-08-16 20:56:20 +05301549 addSetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301550 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301551 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1552 addHashCodeMethod(newAttrInfo);
1553 }
1554 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1555 addEqualsMethod(newAttrInfo);
1556 }
1557 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1558 addToStringMethod(newAttrInfo);
1559 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301560 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1561 //TODO: add implementation for edit content match.
1562 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301563 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
1564 addAddToListImpl(newAttrInfo);
1565 }
1566 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
1567 addAddToListInterface(newAttrInfo, pluginConfig);
1568 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301569 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0
1570 && newAttrInfo.getAttributeType() == null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301571 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301572 }
1573 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr()
1574 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301575 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301576 }
1577 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr()
1578 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301579 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301580 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301581 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
1582 && newAttrInfo.getAttributeType() != null) {
1583 leafCount++;
1584 addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
1585 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301586 if (!newAttrInfo.isIntConflict() &&
1587 !newAttrInfo.isLongConflict()) {
1588 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1589 addGetterImpl(newAttrInfo, pluginConfig);
1590 }
1591
1592 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Shankara-Huaweib7564772016-08-02 18:13:13 +05301593 JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
Bharat saraswal64e7e232016-07-14 23:33:55 +05301594 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301595 /*
1596 * Create a new java attribute info with qualified information of
1597 * wrapper classes.
1598 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301599 JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1600 newAttrInfo.getAttributeName(),
1601 newAttrInfo.getAttributeType(),
1602 getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
Bharat saraswal250a7472016-05-12 13:16:57 +05301603
Bharat saraswal64e7e232016-07-14 23:33:55 +05301604 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1605 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301606 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301607 }
1608
1609 /**
1610 * Returns java class name.
1611 *
1612 * @param suffix for the class name based on the file type
1613 * @return java class name
1614 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301615 String getJavaClassName(String suffix) {
janani b703cfe42016-05-17 13:12:22 +05301616 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301617 }
1618
1619 /**
Bharat saraswald14cbe82016-07-14 13:26:18 +05301620 * Returns java class name.
1621 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301622 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301623 * @return java class name
1624 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301625 private String getImplClassName(YangNode node) {
1626 if (node instanceof YangModule || node instanceof YangSubModule) {
1627 return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
1628 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301629 return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
1630 }
1631
1632 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301633 * Returns the directory path.
1634 *
1635 * @return directory path
1636 */
1637 private String getDirPath() {
1638 return getJavaFileInfo().getPackageFilePath();
1639 }
1640
1641 /**
1642 * Constructs java code exit.
1643 *
1644 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301645 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301646 * @throws IOException when fails to generate java files
1647 */
1648 public void generateJavaFile(int fileType, YangNode curNode)
1649 throws IOException {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301650 List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
1651 .getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301652 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301653 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301654 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301655 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301656
1657 //Generate java code.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301658 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1659 BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301660
1661 //Create interface file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301662 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1663 setInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301664 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
Bharat saraswal8beac342016-08-04 02:00:03 +05301665 if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301666
1667 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301668 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1669 setBuilderInterfaceJavaFileHandle(
1670 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1671 setBuilderInterfaceJavaFileHandle(
1672 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
1673 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301674
1675 //Append builder interface file to interface file and close it.
Bharat saraswal8beac342016-08-04 02:00:03 +05301676 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301677 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301678 }
1679 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301680 validateLineLength(getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301681 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301682 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301683 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301684 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301685 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301686 if (isAttributePresent()) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301687 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301688 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301689 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301690
1691 boolean isLeavesPresent;
1692 if (curNode instanceof YangLeavesHolder) {
1693 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1694 isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
1695 || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
1696 if (isLeavesPresent) {
1697 addBitsetImport(imports);
1698 }
1699 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301700 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301701 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301702 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301703 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301704 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301705
1706 //Create impl class file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301707 setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
Bharat saraswald14cbe82016-07-14 13:26:18 +05301708 setImplClassJavaFileHandle(
Bharat saraswal8beac342016-08-04 02:00:03 +05301709 generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301710
1711 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301712 if ((fileType & BUILDER_CLASS_MASK) != 0) {
1713 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1714 setBuilderClassJavaFileHandle(
1715 generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
1716 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301717
1718 //Append impl class to builder class and close it.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301719 mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301720 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301721 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301722 validateLineLength(getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301723 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301724 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301725 freeTemporaryResources(false);
1726 }
1727
Vidyashree Ramab3670472016-08-06 15:49:56 +05301728 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301729 private void addArrayListImport(List<String> imports) {
1730 if (imports.contains(getJavaImportData().getImportForList())) {
1731 imports.add(ARRAY_LIST_IMPORT);
1732 }
1733 }
1734
Bharat saraswal8beac342016-08-04 02:00:03 +05301735 private void addBitsetImport(List<String> imports) {
1736 imports.add(getJavaImportData().getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301737 }
1738
1739 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301740 * Adds imports for ToString and HashCodeMethod.
1741 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301742 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301743 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301744 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301745 void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301746 if (operation) {
1747 imports.add(getJavaImportData().getImportForHashAndEquals());
1748 imports.add(getJavaImportData().getImportForToString());
1749 } else {
1750 imports.remove(getJavaImportData().getImportForHashAndEquals());
1751 imports.remove(getJavaImportData().getImportForToString());
1752 }
1753 }
1754
1755 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301756 * Adds import for map and hash map.
1757 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301758 * @param imports import list
1759 * @param operations true for adding and false for deletion
1760 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301761 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301762 */
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301763 private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301764 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301765 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301766 if (!isInterfaceFile) {
1767 imports.add(getJavaImportData().getHashMapImport());
1768 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301769 // Add import for hash map only if node is not a YANG choice.
1770 if (!(curNode instanceof YangChoice)) {
1771 imports.add(getJavaImportData().getMapImport());
1772 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301773 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301774 if (!isInterfaceFile) {
1775 imports.remove(getJavaImportData().getHashMapImport());
1776 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301777 imports.remove(getJavaImportData().getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301778 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301779 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301780 }
1781
1782 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301783 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301784 *
1785 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301786 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301787 private void addInvocationExceptionImport(List<String> imports) {
1788 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301789 }
1790
1791 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301792 * Removes all temporary file handles.
1793 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301794 * @param isErrorOccurred flag to tell translator that error has occurred while file generation
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301795 * @throws IOException when failed to delete the temporary files
1796 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301797 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301798 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301799 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301800 * Close all java file handles and when error occurs delete the files.
1801 */
1802 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301803 closeFile(getInterfaceJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301804 }
1805 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301806 closeFile(getBuilderClassJavaFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301807 }
1808 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1809 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1810 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301811 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301812 closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301813 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301814 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301815 * Close all temporary file handles and delete the files.
1816 */
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301817 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1818 closeFile(getGetterImplTempFileHandle(), true);
1819 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301820 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1821 closeFile(getAttributesTempFileHandle(), true);
1822 }
1823 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1824 closeFile(getHashCodeImplTempFileHandle(), true);
1825 }
1826 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1827 closeFile(getToStringImplTempFileHandle(), true);
1828 }
1829 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1830 closeFile(getEqualsImplTempFileHandle(), true);
1831 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301832 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1833 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301834 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301835 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
1836 closeFile(getAddToListImplTempFileHandle(), true);
1837 }
1838 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
1839 closeFile(getAddToListInterfaceTempFileHandle(), true);
1840 }
1841 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
1842 closeFile(getLeafIdAttributeTempFileHandle(), true);
1843 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301844 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301845 closeFile(getSubtreeFilteringForLeafTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301846 }
1847 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301848 closeFile(getGetSubtreeFilteringForListTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301849 }
1850 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301851 closeFile(getGetSubtreeFilteringForChildNodeTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301852 }
1853 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1854 closeFile(getEditContentTempFileHandle(), true);
1855 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301856 }
1857
1858 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301859 * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
1860 * same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301861 *
1862 * @param importInfo import info for the current attribute being added
1863 * @return status of the qualified access to the attribute
1864 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301865 boolean getIsQualifiedAccessOrAddToImportList(
Shankara-Huaweib7564772016-08-02 18:13:13 +05301866 JavaQualifiedTypeInfoTranslator importInfo) {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301867 return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(),
1868 getJavaFileInfo().getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301869 }
1870
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301871 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301872 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301873 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301874 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301875 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301876 public File getAddToListInterfaceTempFileHandle() {
1877 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301878 }
1879
1880 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301881 * Sets temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301882 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301883 * @param addToListInterfaceTempFileHandle temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301884 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301885 private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
1886 this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
1887 }
1888
1889 /**
1890 * Returns temp file handle for add to list impl.
1891 *
1892 * @return temp file handle for add to list impl
1893 */
1894 public File getAddToListImplTempFileHandle() {
1895 return addToListImplTempFileHandle;
1896 }
1897
1898 /**
1899 * Sets temp file handle for add to list impl.
1900 *
1901 * @param addToListImplTempFileHandle temp file handle for add to list impl
1902 */
1903 private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
1904 this.addToListImplTempFileHandle = addToListImplTempFileHandle;
1905 }
1906
1907 /**
1908 * Returns temp file handle for leaf identifier attributes.
1909 *
1910 * @return temp file handle for leaf identifier attributes
1911 */
1912 public File getLeafIdAttributeTempFileHandle() {
1913 return leafIdAttributeTempFileHandle;
1914 }
1915
1916 /**
1917 * Sets temp file handle for leaf identifier attributes.
1918 *
Bharat saraswale50edca2016-08-05 01:58:25 +05301919 * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes
Bharat saraswal8beac342016-08-04 02:00:03 +05301920 */
1921 private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
1922 this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
1923 }
1924
1925 /**
1926 * Returns if root node is set.
1927 *
1928 * @return true if root node
1929 */
1930 private boolean isRooNode() {
1931 return isRooNode;
1932 }
1933
1934 /**
1935 * Sets true if root node.
1936 *
1937 * @param rooNode true if root node
1938 */
Bharat saraswale50edca2016-08-05 01:58:25 +05301939 void setRooNode(boolean rooNode) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301940 isRooNode = rooNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301941 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301942
1943 /**
1944 * Returns temp file for is content match.
1945 *
1946 * @return temp file for is content match
1947 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301948 public File getSubtreeFilteringForLeafTempFileHandle() {
1949 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301950 }
1951
1952 /**
1953 * Sets temp file handle for is content match.
1954 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301955 * @param subtreeFilteringForLeafTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301956 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301957 private void setSubtreeFilteringForLeafTempFileHandle(File subtreeFilteringForLeafTempFileHandle) {
1958 this.subtreeFilteringForLeafTempFileHandle = subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301959 }
1960
1961 /**
1962 * Returns temp file for edit content file.
1963 *
1964 * @return temp file for edit content file
1965 */
1966 public File getEditContentTempFileHandle() {
1967 return editContentTempFileHandle;
1968 }
1969
1970 /**
1971 * Sets temp file for edit content file.
1972 *
1973 * @param editContentTempFileHandle temp file for edit content file
1974 */
1975 private void setEditContentTempFileHandle(File editContentTempFileHandle) {
1976 this.editContentTempFileHandle = editContentTempFileHandle;
1977 }
1978
1979 /**
1980 * Returns temp file for is content match.
1981 *
1982 * @return temp file for is content match
1983 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301984 public File getGetSubtreeFilteringForListTempFileHandle() {
1985 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301986 }
1987
1988 /**
1989 * Sets temp file handle for is content match.
1990 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301991 * @param getSubtreeFilteringForListTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301992 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301993 private void setGetSubtreeFilteringForListTempFileHandle(File getSubtreeFilteringForListTempFileHandle) {
1994 this.getSubtreeFilteringForListTempFileHandle = getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301995 }
1996
1997 /**
1998 * Returns temp file for is content match.
1999 *
2000 * @return temp file for is content match
2001 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302002 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
2003 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302004 }
2005
2006 /**
2007 * Sets temp file handle for is content match.
2008 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302009 * @param getSubtreeFilteringForChildNodeTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302010 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302011 private void setGetSubtreeFilteringForChildNodeTempFileHandle(File getSubtreeFilteringForChildNodeTempFileHandle) {
2012 this.getSubtreeFilteringForChildNodeTempFileHandle = getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302013 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05302014}