blob: 237b6bbf421591fb7a75502ee3bdd9b8e222585a [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
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053018import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
Bharat saraswale50edca2016-08-05 01:58:25 +053019import org.onosproject.yangutils.datamodel.YangAugment;
Bharat saraswalaf413b82016-07-14 15:18:20 +053020import org.onosproject.yangutils.datamodel.YangAugmentableNode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053021import org.onosproject.yangutils.datamodel.YangCase;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053022import org.onosproject.yangutils.datamodel.YangChoice;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053023import org.onosproject.yangutils.datamodel.YangLeaf;
24import org.onosproject.yangutils.datamodel.YangLeafList;
25import org.onosproject.yangutils.datamodel.YangLeavesHolder;
Vidyashree Ramab3670472016-08-06 15:49:56 +053026import org.onosproject.yangutils.datamodel.YangList;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053027import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053028import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053029import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053030import org.onosproject.yangutils.translator.exception.TranslatorException;
31import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Shankara-Huaweib7564772016-08-02 18:13:13 +053032import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053033import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053034import org.onosproject.yangutils.utils.io.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053035
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053036import java.io.File;
37import java.io.IOException;
38import java.util.List;
39
Bharat saraswalc2d3be12016-06-16 00:29:12 +053040import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
42import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053043import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Bharat saraswalaf413b82016-07-14 15:18:20 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053046import 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;
Bharat saraswalaf413b82016-07-14 15:18:20 +053070import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
72import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswal8beac342016-08-04 02:00:03 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053075import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswald14cbe82016-07-14 13:26:18 +053076import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
Bharat saraswal8beac342016-08-04 02:00:03 +053077import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
78import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053080import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
84import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
85import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053086import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
87import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
88import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053090import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053091import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
92import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
93import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
94import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
95import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
96import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
97import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
98import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
99import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
Bharat saraswal8beac342016-08-04 02:00:03 +0530100import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530101import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530102import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530103import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530104import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530105import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
106import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530107import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530108import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530109import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530110import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
111import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_CLASS;
Bharat saraswal8beac342016-08-04 02:00:03 +0530112import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530113import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530114import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
115import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530116import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530117import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530118import static org.onosproject.yangutils.utils.UtilConstants.YANG;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530119import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530120import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswal8beac342016-08-04 02:00:03 +0530121import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530122import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswale304c252016-08-16 20:56:20 +0530123import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530124import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530125import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530126import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
127import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
128import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530129import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
130import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530131import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530132
133/**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530134 * Represents implementation of java code fragments temporary implementations.
135 * Manages the common temp file required for Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530136 */
137public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530138
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530139 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530140 * File type extension for java classes.
141 */
142 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530143
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530144 /**
145 * File type extension for temporary classes.
146 */
147 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530148
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530149 /**
150 * Folder suffix for temporary files folder.
151 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530152 private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530153
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530154 /**
155 * File name for getter method.
156 */
157 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530158
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530159 /**
160 * File name for setter method.
161 */
162 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530163
164 /**
165 * File name for getter method implementation.
166 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530167 private static final String GETTER_METHOD_IMPL_FILE_NAME =
168 "GetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530169
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530170 /**
171 * File name for setter method implementation.
172 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530173 private static final String SETTER_METHOD_IMPL_FILE_NAME =
174 "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530175
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530176 /**
177 * File name for attributes.
178 */
179 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530180
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530181 /**
182 * File name for to string method.
183 */
184 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530185
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530186 /**
187 * File name for hash code method.
188 */
189 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530190
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530191 /**
192 * File name for equals method.
193 */
194 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530195
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530196 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530197 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530198 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530199 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530200
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530201 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530202 * File name for from add to list interface method.
203 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530204 private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME =
205 "addToList";
Bharat saraswal8beac342016-08-04 02:00:03 +0530206
207 /**
208 * File name for from add to list impl method.
209 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530210 private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME =
211 "addToListImpl";
Bharat saraswal8beac342016-08-04 02:00:03 +0530212
213 /**
214 * File name for from leaf identifier attributes.
215 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530216 private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME =
217 "leafIdentifierAtr";
Bharat saraswal8beac342016-08-04 02:00:03 +0530218
219 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530220 * File name for is filter content leaf match.
221 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530222 private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME =
223 "isFilterContentMatchLeafMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530224
225 /**
226 * File name for is filter content leaf-list match.
227 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530228 private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME =
229 "isFilterContentMatchLeafListMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530230
231 /**
232 * File name for is filter content node match.
233 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530234 private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME =
235 "isFilterContentMatchNodeMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530236
237 /**
238 * File name for edit content file.
239 */
240 private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
241
242 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530243 * File name for interface java file name suffix.
244 */
245 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530246
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530247 /**
248 * File name for builder interface file name suffix.
249 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530250 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX =
251 BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530252
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530253 /**
254 * File name for builder class file name suffix.
255 */
256 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530257
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530258 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530259 * Information about the java files being generated.
260 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530261 private JavaFileInfoTranslator javaFileInfo;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530262
263 /**
264 * Imported class info.
265 */
266 private JavaImportData javaImportData;
267
268 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530269 * The variable which guides the types of temporary files generated using
270 * the temporary generated file types mask.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530271 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530272 private int tempFilesFlagSet;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530273
274 /**
275 * Absolute path where the target java file needs to be generated.
276 */
277 private String absoluteDirPath;
278
279 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530280 * Contains all the interface(s)/class name which will be extended by
281 * generated files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530282 */
283 private JavaExtendsListHolder javaExtendsListHolder;
284
Bharat saraswald14cbe82016-07-14 13:26:18 +0530285 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530286 * Java file handle for interface file.
287 */
288 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530289
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530290 /**
291 * Java file handle for builder interface file.
292 */
293 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530294
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530295 /**
296 * Java file handle for builder class file.
297 */
298 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530299
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530300 /**
301 * Java file handle for impl class file.
302 */
303 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530304
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530305 /**
306 * Temporary file handle for attribute.
307 */
308 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530309
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530310 /**
311 * Temporary file handle for getter of interface.
312 */
313 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530314
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530315 /**
316 * Temporary file handle for setter of interface.
317 */
318 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530319
320 /**
321 * Temporary file handle for getter of class.
322 */
323 private File getterImplTempFileHandle;
324
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530325 /**
326 * Temporary file handle for setter of class.
327 */
328 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530329
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530330 /**
331 * Temporary file handle for hash code method of class.
332 */
333 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530334
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530335 /**
336 * Temporary file handle for equals method of class.
337 */
338 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530339
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530340 /**
341 * Temporary file handle for to string method of class.
342 */
343 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530344
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530345 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530346 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530347 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530348 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530349
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530350 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530351 * Temporary file handle for add to list interface method of class.
352 */
353 private File addToListInterfaceTempFileHandle;
354
355 /**
356 * Temporary file handle for add to list impl method of class.
357 */
358 private File addToListImplTempFileHandle;
359
360 /**
361 * Temporary file handle for leaf id attributes of enum.
362 */
363 private File leafIdAttributeTempFileHandle;
364
365 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530366 * Temporary file handle for is content match method for leaf-list.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530367 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530368 private File getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530369
370 /**
371 * Temporary file handle for is content match method for node.
372 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530373 private File getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530374
375 /**
376 * Temporary file handle for is content match method for leaf.
377 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530378 private File subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530379
380 /**
381 * Temporary file handle for edit content file.
382 */
383 private File editContentTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530384
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530385 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530386 * Leaf count.
387 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530388 private int leafCount;
Bharat saraswal8beac342016-08-04 02:00:03 +0530389
390 /**
391 * If current node is root node.
392 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530393 private boolean rootNode;
Bharat saraswal8beac342016-08-04 02:00:03 +0530394
395 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530396 * Is attribute added.
397 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530398 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530399
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530400 /**
401 * Creates an instance of temp JAVA fragment files.
402 */
Bharat saraswalaf413b82016-07-14 15:18:20 +0530403 TempJavaFragmentFiles() {
404 }
405
406 /**
407 * Creates an instance of temporary java code fragment.
408 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530409 * @param fileInfo generated java file information
Bharat saraswalaf413b82016-07-14 15:18:20 +0530410 * @throws IOException when fails to create new file handle
411 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530412 protected TempJavaFragmentFiles(JavaFileInfoTranslator fileInfo)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530413 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530414 javaExtendsListHolder = new JavaExtendsListHolder();
415 javaImportData = new JavaImportData();
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530416 javaFileInfo = fileInfo;
417 absoluteDirPath = getAbsolutePackagePath(fileInfo.getBaseCodeGenPath(),
418 fileInfo.getPackageFilePath());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530419 /*
420 * Initialize getter when generation file type matches to interface
421 * mask.
422 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530423 if (javaFlagSet(INTERFACE_MASK)) {
424 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
425 ADD_TO_LIST_INTERFACE_MASK |
426 LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530427 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530428 /*
429 * Initialize getter and setter when generation file type matches to
430 * builder interface mask.
431 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530432 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
433 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
434 SETTER_FOR_INTERFACE_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530435 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530436 /*
437 * Initialize getterImpl, setterImpl and attributes when generation file
438 * type matches to builder class mask.
439 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530440 if (javaFlagSet(BUILDER_CLASS_MASK)) {
441 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
442 SETTER_FOR_CLASS_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530443 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530444 /*
445 * Initialize getterImpl, attributes, constructor, hash code, equals and
446 * to strings when generation file type matches to impl class mask.
447 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530448 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
449 addGeneratedTempFile(
450 ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
451 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
452 TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
453 FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
454 FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
455 FILTER_CONTENT_MATCH_FOR_NODES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530456 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530457 /*
458 * Initialize temp files to generate type class.
459 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530460 if (javaFlagSet(GENERATE_TYPE_CLASS)) {
461 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
462 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
463 TO_STRING_IMPL_MASK |
464 FROM_STRING_IMPL_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530465 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530466 //Initialize temp files to generate enum class.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530467 if (javaFlagSet(GENERATE_ENUM_CLASS)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530468 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
469 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530470 //Set temporary file handles
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530471 if (tempFlagSet(ATTRIBUTES_MASK)) {
472 attributesTempFileHandle =
473 getTemporaryFileHandle(ATTRIBUTE_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530474 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530475 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
476 getterInterfaceTempFileHandle =
477 getTemporaryFileHandle(GETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530478 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530479 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
480 setterInterfaceTempFileHandle =
481 getTemporaryFileHandle(SETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530482 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530483 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
484 getterImplTempFileHandle =
485 getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530486 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530487 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
488 setterImplTempFileHandle =
489 getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530490 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530491 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
492 hashCodeImplTempFileHandle =
493 getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530494 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530495 if (tempFlagSet(EQUALS_IMPL_MASK)) {
496 equalsImplTempFileHandle =
497 getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530498 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530499 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
500 toStringImplTempFileHandle =
501 getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530502 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530503 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
504 fromStringImplTempFileHandle =
505 getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530506 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530507 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
508 addToListInterfaceTempFileHandle =
509 getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530510 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530511 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
512 addToListImplTempFileHandle =
513 getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530514 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530515 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
516 leafIdAttributeTempFileHandle =
517 getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530518 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530519 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
520 subtreeFilteringForLeafTempFileHandle =
521 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530522 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530523 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
524 getSubtreeFilteringForListTempFileHandle =
525 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530526 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530527 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
528 getSubtreeFilteringForChildNodeTempFileHandle =
529 getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530530 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530531 if (tempFlagSet(EDIT_CONTENT_MASK)) {
532 editContentTempFileHandle =
533 getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530534 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530535 }
536
537 /**
538 * Adds current node info as and attribute to the parent generated file.
539 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530540 * @param curNode current node
541 * @param isList is list construct
542 * @param config plugin configurations
Bharat saraswalaf413b82016-07-14 15:18:20 +0530543 * @throws IOException IO operation exception
544 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530545 protected static void addCurNodeInfoInParentTempFile(YangNode curNode,
546 boolean isList,
547 YangPluginConfig config)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530548 throws IOException {
549 YangNode parent = getParentNodeInGenCode(curNode);
550 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530551 throw new TranslatorException(getErrorMsg(MISSING_PARENT_NODE,
552 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530553 }
Shankara-Huaweib7564772016-08-02 18:13:13 +0530554 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530555 /*
556 * In case of grouping, there is no need to add the information, it
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530557 * will be taken care in uses.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530558 */
559 return;
560 }
Gaurav Agrawal9381ebb2016-09-29 19:00:33 +0530561 addCurNodeInfoInParentTempFile(curNode, isList, config, parent);
562 }
563
564 /**
565 * Adds current node info as and attribute to a specified parent generated
566 * file. In case of grouping parent will be referred grouping node or
567 * referred node in grouping.
568 *
569 * @param curNode current node
570 * @param isList is list construct
571 * @param config plugin configurations
572 * @param parent parent node
573 * @throws IOException IO operation exception
574 */
575 protected static void addCurNodeInfoInParentTempFile(
576 YangNode curNode, boolean isList, YangPluginConfig config,
577 YangNode parent)
578 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530579 TempJavaBeanFragmentFiles tempFiles =
580 getBeanFiles((JavaCodeGeneratorInfo) parent);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530581 JavaAttributeInfo attr =
582 getCurNodeAsAttributeInTarget(curNode, parent, isList,
583 tempFiles);
584 tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530585 }
586
587 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530588 * Creates an attribute info object corresponding to a data model node
589 * and return it.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530590 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530591 * @param curNode current node
592 * @param targetNode target node
593 * @param listNode flag indicating if a node is a list node
594 * @param tempFiles temp java fragment files
595 * @return java attribute info
Bharat saraswalaf413b82016-07-14 15:18:20 +0530596 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530597 public static JavaAttributeInfo
598 getCurNodeAsAttributeInTarget(YangNode curNode, YangNode targetNode,
599 boolean listNode,
600 TempJavaFragmentFiles tempFiles) {
601 JavaFileInfoTranslator translator =
602 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
603 String curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530604 if (curNodeName == null) {
605 updateJavaFileInfo(curNode, null);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530606 curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530607 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530608 /*
609 * Get the import info corresponding to the attribute for import in
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530610 * generated java files or qualified access.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530611 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530612 JavaQualifiedTypeInfoTranslator typeInfo =
613 getQualifiedTypeInfoOfCurNode(curNode,
614 getCapitalCase(curNodeName));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530615 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530616 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
617 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530618 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530619 JavaImportData parentImportData = tempFiles.getJavaImportData();
620 JavaFileInfoTranslator fileInfo =
621 ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530622
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530623 boolean qualified;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530624 if (tempFiles instanceof TempJavaServiceFragmentFiles &&
625 typeInfo.getClassInfo().contentEquals(SERVICE) ||
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530626 typeInfo.getClassInfo()
627 .contentEquals(getCapitalCase(fileInfo.getJavaName() +
628 SERVICE))) {
629 qualified = true;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530630 } else {
631 String className;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530632 if (tempFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530633 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530634 } else {
635 className = getCapitalCase(fileInfo.getJavaName());
636 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530637 qualified = parentImportData.addImportInfo(typeInfo, className,
638 fileInfo.getPackage());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530639 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530640 boolean collectionSet = false;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530641 if (curNode instanceof YangList) {
642 YangList yangList = (YangList) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530643 if (yangList.getCompilerAnnotation() != null &&
644 yangList.getCompilerAnnotation()
645 .getYangAppDataStructure() != null) {
646 switch (yangList.getCompilerAnnotation()
647 .getYangAppDataStructure().getDataStructure()) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530648 case QUEUE: {
649 parentImportData.setQueueToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530650 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530651 break;
652 }
653 case SET: {
654 parentImportData.setSetToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530655 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530656 break;
657 }
658 default: {
659 // TODO : to be implemented
660 }
661 }
662 }
663 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530664 if (listNode && !collectionSet) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530665 parentImportData.setIfListImported(true);
666 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530667 if (curNode instanceof YangList) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530668 return getAttributeInfoForTheData(typeInfo, curNodeName,
669 null, qualified, listNode,
670 ((YangList) curNode)
671 .getCompilerAnnotation());
Vidyashree Ramab3670472016-08-06 15:49:56 +0530672 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530673 return getAttributeInfoForTheData(typeInfo, curNodeName, null,
674 qualified, listNode);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530675 }
676
677 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530678 * Returns java attribute for leaf.
679 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530680 * @param tempFiles temporary generated file
681 * @param container JAVA leaf info container
682 * @param config plugin configurations
683 * @param leafList flag indicating if it's leaf list
684 * @return java attribute info
Bharat saraswal64e7e232016-07-14 23:33:55 +0530685 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530686 private static JavaAttributeInfo
687 getJavaAttributeOfLeaf(TempJavaFragmentFiles tempFiles,
688 JavaLeafInfoContainer container,
689 YangPluginConfig config, boolean leafList) {
690 if (leafList) {
691 tempFiles.getJavaImportData().setIfListImported(true);
692 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
693 true);
694 }
695 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
696 false);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530697 }
698
699 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530700 * Returns java attribute for leaf container.
Bharat saraswal64e7e232016-07-14 23:33:55 +0530701 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530702 * @param tempFiles temporary generated file
703 * @param container JAVA leaf info container
704 * @param config plugin configurations
705 * @param listAttribute flag indicating if list attribute
706 * @return JAVA attribute information
Bharat saraswal64e7e232016-07-14 23:33:55 +0530707 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530708 private static JavaAttributeInfo
709 getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
710 JavaLeafInfoContainer container,
711 YangPluginConfig config,
712 boolean listAttribute) {
713 container.setConflictResolveConfig(config.getConflictResolver());
714 container.updateJavaQualifiedInfo();
Bharat saraswal64e7e232016-07-14 23:33:55 +0530715 return getAttributeInfoForTheData(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530716 container.getJavaQualifiedInfo(),
717 container.getJavaName(config.getConflictResolver()),
718 container.getDataType(),
719 tempFiles.getIsQualifiedAccessOrAddToImportList(
720 container.getJavaQualifiedInfo()), listAttribute);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530721 }
722
723 /**
724 * Sets absolute path where the file needs to be generated.
725 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530726 * @param absoluteDirPath absolute path where the file needs to be
727 * generated
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530728 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530729 protected void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530730 this.absoluteDirPath = absoluteDirPath;
731 }
732
733 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530734 * Returns the generated java file information.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530735 *
736 * @return generated java file information
737 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530738 protected JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530739 return javaFileInfo;
740 }
741
742 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530743 * Sets the generated java file information.
744 *
745 * @param javaFileInfo generated java file information
746 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530747 protected void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530748 this.javaFileInfo = javaFileInfo;
749 }
750
751 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530752 * Returns the flag-set for generated temp files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530753 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530754 * @return flag-set
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530755 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530756 protected int getGeneratedTempFiles() {
757 return tempFilesFlagSet;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530758 }
759
760 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530761 * Adds to the flag-set for generated temp files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530762 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530763 * @param flags generated temp files flag-set
Bharat saraswalaf413b82016-07-14 15:18:20 +0530764 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530765 protected void addGeneratedTempFile(int flags) {
766 tempFilesFlagSet |= flags;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530767 }
768
769 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530770 * Returns the generated Java files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530771 *
772 * @return generated Java files
773 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530774 protected int getGeneratedJavaFiles() {
775 return javaFileInfo.getGeneratedFileTypes();
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530776 }
777
778 /**
779 * Retrieves the mapped Java class name.
780 *
781 * @return mapped Java class name
782 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530783 protected String getGeneratedJavaClassName() {
784 return getCapitalCase(javaFileInfo.getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530785 }
786
787 /**
788 * Retrieves the import data for the generated Java file.
789 *
790 * @return import data for the generated Java file
791 */
792 public JavaImportData getJavaImportData() {
793 return javaImportData;
794 }
795
796 /**
797 * Sets import data for the generated Java file.
798 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530799 * @param data import data for the generated Java file
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530800 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530801 protected void setJavaImportData(JavaImportData data) {
802 javaImportData = data;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530803 }
804
805 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530806 * Retrieves the status of any attributes added.
807 *
808 * @return status of any attributes added
809 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530810 protected boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530811 return isAttributePresent;
812 }
813
814 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530815 * Returns getter methods's temporary file handle.
816 *
817 * @return temporary file handle
818 */
819 public File getGetterInterfaceTempFileHandle() {
820 return getterInterfaceTempFileHandle;
821 }
822
823 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530824 * Returns setter method's temporary file handle.
825 *
826 * @return temporary file handle
827 */
828 public File getSetterInterfaceTempFileHandle() {
829 return setterInterfaceTempFileHandle;
830 }
831
832 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530833 * Returns setter method's impl's temporary file handle.
834 *
835 * @return temporary file handle
836 */
837 public File getSetterImplTempFileHandle() {
838 return setterImplTempFileHandle;
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 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530851 * Returns attribute's temporary file handle.
852 *
853 * @return temporary file handle
854 */
855 public File getAttributesTempFileHandle() {
856 return attributesTempFileHandle;
857 }
858
859 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530860 * Returns getter method's impl's temporary file handle.
861 *
862 * @return temporary file handle
863 */
864 public File getGetterImplTempFileHandle() {
865 return getterImplTempFileHandle;
866 }
867
868 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530869 * Returns hash code method's temporary file handle.
870 *
871 * @return temporary file handle
872 */
873 public File getHashCodeImplTempFileHandle() {
874 return hashCodeImplTempFileHandle;
875 }
876
877 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530878 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530879 *
880 * @return temporary file handle
881 */
882 public File getEqualsImplTempFileHandle() {
883 return equalsImplTempFileHandle;
884 }
885
886 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530887 * Returns to string method's temporary file handle.
888 *
889 * @return temporary file handle
890 */
891 public File getToStringImplTempFileHandle() {
892 return toStringImplTempFileHandle;
893 }
894
895 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530896 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530897 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530898 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530899 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530900 public JavaExtendsListHolder getJavaExtendsListHolder() {
901 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530902 }
903
904 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530905 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530906 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530907 * @param holder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530908 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530909 protected void setJavaExtendsListHolder(
910 JavaExtendsListHolder holder) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530911 javaExtendsListHolder = holder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530912 }
913
914 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530915 * Adds is filter content match for leaf.
916 *
917 * @param attr java attribute
918 * @throws IOException when fails to do IO operations
919 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530920 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530921 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530922 appendToFile(subtreeFilteringForLeafTempFileHandle,
923 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
924 NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530925 }
926
927 /**
928 * Adds is filter content match for leaf-list.
929 *
930 * @param attr java attribute
931 * @throws IOException when fails to do IO operations
932 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530933 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530934 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530935 appendToFile(getSubtreeFilteringForListTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +0530936 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530937 }
938
939 /**
940 * Adds is filter content match for nodes.
941 *
942 * @param attr java attribute
943 * @throws IOException when fails to do IO operations
944 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530945 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530946 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530947 appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +0530948 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530949 }
950
951 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530952 * Adds attribute for class.
953 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530954 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530955 * @throws IOException when fails to append to temporary file
956 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530957 private void addAttribute(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530958 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530959 appendToFile(attributesTempFileHandle, parseAttribute(attr));
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530960 }
961
962 /**
963 * Adds getter for interface.
964 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530965 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530966 * @throws IOException when fails to append to temporary file
967 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530968 private void addGetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530969 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530970 appendToFile(getterInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530971 getGetterString(attr, getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530972 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530973 }
974
975 /**
976 * Adds setter for interface.
977 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530978 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530979 * @throws IOException when fails to append to temporary file
980 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530981 private void addSetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530982 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530983 appendToFile(setterInterfaceTempFileHandle,
984 getSetterString(attr, getGeneratedJavaClassName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530985 getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530986 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530987 }
988
989 /**
990 * Adds setter's implementation for class.
991 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530992 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530993 * @throws IOException when fails to append to temporary file
994 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530995 private void addSetterImpl(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530996 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530997 String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
998 getGeneratedJavaFiles());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530999 if (rootNode) {
1000 appendToFile(setterImplTempFileHandle,
1001 getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301002 attr.isListAttr(), null) + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301003 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301004 appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301005 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301006 }
1007
1008 /**
1009 * Adds getter method's impl for class.
1010 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301011 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301012 * @throws IOException when fails to append to temporary file
1013 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301014 protected void addGetterImpl(JavaAttributeInfo attr)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301015 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301016 String getter = getGetterForClass(attr, getGeneratedJavaFiles());
1017 if (javaFlagSet(BUILDER_CLASS_MASK)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301018 if (!rootNode) {
1019 appendToFile(getterImplTempFileHandle, getOverRideString() +
1020 getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301021 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301022 appendToFile(getterImplTempFileHandle, getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301023 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301024 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301025 String appDataStructure = null;
1026 if (attr.getCompilerAnnotation() != null) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301027 appDataStructure = attr.getCompilerAnnotation()
1028 .getYangAppDataStructure().getDataStructure().name();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301029 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301030 appendToFile(getterImplTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301031 getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
1032 false, appDataStructure) + getter);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301033 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301034 }
1035
1036 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301037 * Adds add to list interface method.
1038 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301039 * @param attr attribute
Bharat saraswal8beac342016-08-04 02:00:03 +05301040 * @throws IOException when fails to do IO operations
1041 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301042 private void addAddToListInterface(JavaAttributeInfo attr)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301043 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301044 appendToFile(addToListInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301045 getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
1046 null) + getAddToListMethodInterface(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301047 attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301048 }
1049
1050 /**
1051 * Adds add to list interface method.
1052 *
1053 * @param attr attribute
1054 * @throws IOException when fails to do IO operations
1055 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301056 private void addAddToListImpl(JavaAttributeInfo attr)
1057 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301058 appendToFile(addToListImplTempFileHandle,
1059 getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
1060 rootNode) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301061 }
1062
1063 /**
1064 * Adds leaf identifier enum attributes.
1065 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301066 * @param attr attribute
1067 * @param value value
Bharat saraswal8beac342016-08-04 02:00:03 +05301068 * @throws IOException when fails to do IO operations
1069 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301070 private void addLeafIdAttributes(JavaAttributeInfo attr, int value)
Bharat saraswal8beac342016-08-04 02:00:03 +05301071 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301072 appendToFile(leafIdAttributeTempFileHandle, FOUR_SPACE_INDENTATION +
1073 generateEnumAttributeString(attr.getAttributeName(), value));
Bharat saraswal8beac342016-08-04 02:00:03 +05301074 }
1075
1076 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301077 * Adds build method for interface.
1078 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301079 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301080 * @throws IOException when fails to append to temporary file
1081 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301082 protected String addBuildMethodForInterface()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301083 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301084 return parseBuilderInterfaceBuildMethodString(
1085 getGeneratedJavaClassName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301086 }
1087
1088 /**
1089 * Adds build method's implementation for class.
1090 *
1091 * @return build method implementation for class
1092 * @throws IOException when fails to append to temporary file
1093 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301094 protected String addBuildMethodImpl()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301095 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301096 return getBuildString(getGeneratedJavaClassName(), rootNode) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301097 }
1098
1099 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301100 * Adds default constructor for class.
1101 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301102 * @param modifier modifier for constructor
1103 * @param toAppend string which need to be appended with the class name
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301104 * @param suffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301105 * @return default constructor for class
1106 * @throws IOException when fails to append to file
1107 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301108 protected String addDefaultConstructor(String modifier, String toAppend,
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301109 boolean suffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301110 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301111 StringBuilder name = new StringBuilder();
1112 name.append(getGeneratedJavaClassName());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301113 if (rootNode && !toAppend.equals(BUILDER)) {
1114 name.append(OP_PARAM);
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301115 return getDefaultConstructorString(name.toString(), modifier
1116 );
Bharat saraswal8beac342016-08-04 02:00:03 +05301117 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301118 if (suffix) {
1119 name.append(toAppend);
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301120 return getDefaultConstructorString(name.toString(), modifier
1121 );
Bharat saraswal8beac342016-08-04 02:00:03 +05301122 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301123 StringBuilder appended = new StringBuilder();
Bharat saraswal8beac342016-08-04 02:00:03 +05301124 if (toAppend.equals(DEFAULT)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301125 appended.append(getCapitalCase(toAppend));
Bharat saraswal8beac342016-08-04 02:00:03 +05301126 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301127 appended.append(toAppend);
Bharat saraswal8beac342016-08-04 02:00:03 +05301128 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301129 return NEW_LINE + getDefaultConstructorString(appended.append(
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301130 name).toString(), modifier);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301131 // TODO getDefaultConstructorString to handle new line.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301132 }
1133
1134 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301135 * Adds hash code method for class.
1136 *
1137 * @param attr attribute info
1138 * @throws IOException when fails to append to temporary file
1139 */
1140 private void addHashCodeMethod(JavaAttributeInfo attr)
1141 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301142 appendToFile(hashCodeImplTempFileHandle,
1143 getHashCodeMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301144 }
1145
1146 /**
1147 * Adds equals method for class.
1148 *
1149 * @param attr attribute info
1150 * @throws IOException when fails to append to temporary file
1151 */
1152 private void addEqualsMethod(JavaAttributeInfo attr)
1153 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301154 appendToFile(equalsImplTempFileHandle,
1155 getEqualsMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301156 }
1157
1158 /**
1159 * Adds ToString method for class.
1160 *
1161 * @param attr attribute info
1162 * @throws IOException when fails to append to temporary file
1163 */
1164 private void addToStringMethod(JavaAttributeInfo attr)
1165 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301166 appendToFile(toStringImplTempFileHandle,
1167 getToStringMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301168 }
1169
1170 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301171 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301172 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301173 * @param attr type attribute info
1174 * @param fromStringAttr from string attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301175 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301176 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301177 void addFromStringMethod(JavaAttributeInfo attr,
1178 JavaAttributeInfo fromStringAttr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301179 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301180 appendToFile(fromStringImplTempFileHandle,
1181 getFromStringMethod(attr, fromStringAttr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301182 }
1183
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301184 /**
1185 * Returns a temporary file handle for the specific file type.
1186 *
1187 * @param fileName file name
1188 * @return temporary file handle
1189 * @throws IOException when fails to create new file handle
1190 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301191 protected File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301192 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301193 String path = getTempDirPath(absoluteDirPath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301194 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301195 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301196 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301197 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301198 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301199 throw new IOException("failed to create temporary directory " +
1200 "for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301201 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301202 }
1203 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1204 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301205 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301206 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301207 throw new IOException("failed to create temporary file for " +
1208 fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301209 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301210 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301211 throw new IOException(fileName + " is reused due to YANG naming. " +
1212 "probably your previous build " +
1213 "would have failed");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301214 }
1215 return file;
1216 }
1217
1218 /**
1219 * Returns a temporary file handle for the specific file type.
1220 *
1221 * @param fileName file name
1222 * @return temporary file handle
1223 * @throws IOException when fails to create new file handle
1224 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301225 protected File getJavaFileHandle(String fileName)
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301226 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301227 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
1228 javaFileInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301229 }
1230
1231 /**
1232 * Returns data from the temporary files.
1233 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301234 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301235 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301236 * @return stored data from temporary files
1237 * @throws IOException when failed to get data from the given file
1238 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301239 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301240 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301241 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301242 if (new File(path + file.getName()).exists()) {
1243 return readAppendFile(path + file.getName(), EMPTY_STRING);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301244 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301245 throw new IOException("Unable to get data from the given " +
1246 file.getName() + " file for " +
1247 getGeneratedJavaClassName() + PERIOD);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301248 }
1249
1250 /**
1251 * Returns temporary directory path.
1252 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301253 * @param path absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301254 * @return directory path
1255 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301256 private String getTempDirPath(String path) {
1257 return getPackageDirPathFromJavaJPackage(path) + SLASH +
1258 getGeneratedJavaClassName() + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301259 }
1260
1261 /**
1262 * Parses attribute to get the attribute string.
1263 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301264 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301265 * @return attribute string
1266 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301267 protected String parseAttribute(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301268 /*
1269 * TODO: check if this utility needs to be called or move to the caller
1270 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301271 String attrName = attr.getAttributeName();
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301272 String attrAccessType = PRIVATE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301273 if ((getGeneratedJavaFiles() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301274 attrAccessType = PROTECTED;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301275 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301276 String pkg = null;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301277 if (attr.isQualifiedName()) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301278 pkg = attr.getImportInfo().getPkgInfo();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301279 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301280 return getJavaAttributeDefinition(
1281 pkg, attr.getImportInfo().getClassInfo(), attrName,
1282 attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301283 }
1284
1285 /**
1286 * Appends content to temporary file.
1287 *
1288 * @param file temporary file
1289 * @param data data to be appended
1290 * @throws IOException when fails to append to file
1291 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301292 protected void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301293 throws IOException {
1294 try {
1295 insertDataIntoJavaFile(file, data);
1296 } catch (IOException ex) {
1297 throw new IOException("failed to write in temp file.");
1298 }
1299 }
1300
1301 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301302 * Adds parent's info to current node import list.
1303 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301304 * @param curNode current node
1305 * @param config plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301306 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301307 protected void addParentInfoInCurNodeTempFile(YangNode curNode,
1308 YangPluginConfig config) {
1309 JavaQualifiedTypeInfoTranslator caseImportInfo =
1310 new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301311 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301312 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1313 return;
1314 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301315 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301316 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301317 }
1318 if (!(curNode instanceof JavaFileInfoContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301319 throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301320 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301321 caseImportInfo.setClassInfo(
1322 getCapitalCase(getCamelCase(parent.getName(),
1323 config.getConflictResolver())));
1324 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo()
1325 .getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301326
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301327 JavaFileInfoTranslator fileInfo =
1328 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301329
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301330 getBeanFiles(curNode).getJavaImportData().addImportInfo(
1331 caseImportInfo, getCapitalCase(fileInfo.getJavaName()),
1332 fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301333 }
1334
1335 /**
1336 * Adds leaf attributes in generated files.
1337 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301338 * @param entry JAVA leaf info container
1339 * @param config plugin config
1340 * @param curNode current node
1341 * @param leafList flag indicating whether leaf container is leafList
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301342 * @throws IOException IO operation fail
1343 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301344 private void addLeafInfoToTempFiles(JavaLeafInfoContainer entry,
1345 YangPluginConfig config,
1346 YangNode curNode,
1347 boolean leafList)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301348 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301349 if (entry != null) {
1350 if (curNode instanceof RpcNotificationContainer) {
1351 TempJavaBeanFragmentFiles tempFiles = getBeanFiles(curNode);
1352 addJavaSnippetInfoToApplicableTempFiles(
1353 getJavaAttributeOfLeaf(tempFiles, entry,
1354 config, leafList), config);
1355 } else {
1356 addJavaSnippetInfoToApplicableTempFiles(
1357 getJavaAttributeOfLeaf(this, entry,
1358 config, leafList), config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301359 }
1360 }
1361 }
1362
1363 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301364 * Adds all the leaves in the current data model node as part of the
1365 * generated temporary file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301366 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301367 * @param curNode current node
1368 * @param config plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301369 * @throws IOException IO operation fail
1370 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301371 protected void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
1372 YangPluginConfig config)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301373 throws IOException {
1374 if (!(curNode instanceof YangLeavesHolder)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301375 throw new TranslatorException(getErrorMsg(INVALID_LEAF_HOLDER,
1376 curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301377 }
1378 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301379
1380 for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
1381 addLeafInfoToTempFiles((JavaLeafInfoContainer) leaf, config,
1382 curNode, false);
1383 }
1384
1385 for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
1386 addLeafInfoToTempFiles((JavaLeafInfoContainer) leafList, config,
1387 curNode, true);
1388 }
1389 }
1390
1391 /**
1392 * Adds operation type to temp files.
1393 *
1394 * @param curNode current YANG node
1395 * @param config YANG plugin config
1396 * @throws IOException IO exception
1397 */
1398 protected void addOperationTypeToTempFiles(YangNode curNode,
1399 YangPluginConfig config)
1400 throws IOException {
1401 JavaQualifiedTypeInfoTranslator typeInfo =
1402 new JavaQualifiedTypeInfoTranslator();
1403 typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
1404 typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
1405 .getPackage());
1406 JavaAttributeInfo attributeInfo =
1407 getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
1408 curNode.getJavaClassNameOrBuiltInType()) +
1409 OPERATION_TYPE_ATTRIBUTE, null, false, false);
1410 addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301411 }
1412
1413 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301414 * Adds the new attribute info to the target generated temporary files.
1415 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301416 * @param newAttrInfo new attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301417 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301418 * @throws IOException IO operation fail
1419 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301420 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
1421 YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301422 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301423 isAttributePresent = true;
1424 if (tempFlagSet(ATTRIBUTES_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301425 addAttribute(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301426 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301427 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301428 addGetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301429 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301430 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301431 addSetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301432 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301433 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301434 addSetterImpl(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301435 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301436 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301437 addHashCodeMethod(newAttrInfo);
1438 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301439 if (tempFlagSet(EQUALS_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301440 addEqualsMethod(newAttrInfo);
1441 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301442 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301443 addToStringMethod(newAttrInfo);
1444 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301445 if (tempFlagSet(EDIT_CONTENT_MASK)) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301446 //TODO: add implementation for edit content match.
1447 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301448 boolean listAttr = newAttrInfo.isListAttr();
1449 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK) && listAttr) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301450 addAddToListImpl(newAttrInfo);
1451 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301452 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301453 addAddToListInterface(newAttrInfo);
Bharat saraswal8beac342016-08-04 02:00:03 +05301454 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301455 YangType attrType = newAttrInfo.getAttributeType();
1456 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
1457 attrType == null && !newAttrInfo.getAttributeName()
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301458 .contains(OPERATION_TYPE_ATTRIBUTE)) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301459 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301460 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301461 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
1462 !listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301463 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301464 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301465 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
1466 listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301467 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301468 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301469 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
1470 !listAttr && attrType != null) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301471 leafCount++;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301472 addLeafIdAttributes(newAttrInfo, leafCount);
Bharat saraswal8beac342016-08-04 02:00:03 +05301473 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301474 if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
1475 !newAttrInfo.isShortConflict()) {
1476 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301477 addGetterImpl(newAttrInfo);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301478 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301479 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1480 JavaQualifiedTypeInfoTranslator typeInfo =
1481 getQualifiedInfoOfFromString(newAttrInfo,
1482 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301483 /*
1484 * Create a new java attribute info with qualified information of
1485 * wrapper classes.
1486 */
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301487 JavaAttributeInfo fromStringAttributeInfo =
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301488 getAttributeInfoForTheData(
1489 typeInfo, newAttrInfo.getAttributeName(),
1490 attrType, getIsQualifiedAccessOrAddToImportList(
1491 typeInfo), false);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301492 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1493 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301494 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301495 }
1496
1497 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301498 * Returns JAVA class name for non implementation classes.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301499 *
1500 * @param suffix for the class name based on the file type
1501 * @return java class name
1502 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301503 protected String getJavaClassName(String suffix) {
1504 return getCapitalCase(javaFileInfo.getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301505 }
1506
1507 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301508 * Returns class name for implementation classes.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301509 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301510 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301511 * @return java class name
1512 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301513 private String getImplClassName(YangNode node) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301514 if (node instanceof RpcNotificationContainer) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301515 return getGeneratedJavaClassName() + OP_PARAM;
Bharat saraswal8beac342016-08-04 02:00:03 +05301516 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301517 return DEFAULT_CAPS + getGeneratedJavaClassName();
Bharat saraswald14cbe82016-07-14 13:26:18 +05301518 }
1519
1520 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301521 * Returns the directory path.
1522 *
1523 * @return directory path
1524 */
1525 private String getDirPath() {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301526 return javaFileInfo.getPackageFilePath();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301527 }
1528
1529 /**
1530 * Constructs java code exit.
1531 *
1532 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301533 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301534 * @throws IOException when fails to generate java files
1535 */
1536 public void generateJavaFile(int fileType, YangNode curNode)
1537 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301538 List<String> imports =
1539 getBeanFiles(curNode).getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301540 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301541 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301542 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301543 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301544
1545 //Generate java code.
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301546 if ((fileType & INTERFACE_MASK) != 0 ||
1547 (fileType & BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301548
1549 //Create interface file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301550 interfaceJavaFileHandle =
1551 getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
1552 interfaceJavaFileHandle =
1553 generateInterfaceFile(interfaceJavaFileHandle, imports,
1554 curNode, isAttributePresent);
1555 if (!(curNode instanceof RpcNotificationContainer)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301556
1557 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301558 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301559 builderInterfaceJavaFileHandle =
1560 getJavaFileHandle(getJavaClassName(
1561 BUILDER_INTERFACE_FILE_NAME_SUFFIX));
1562 builderInterfaceJavaFileHandle =
1563 generateBuilderInterfaceFile(
1564 builderInterfaceJavaFileHandle,
1565 curNode, isAttributePresent);
1566 /*
1567 * Append builder interface file to interface file and
1568 * close it.
1569 */
1570 mergeJavaFiles(builderInterfaceJavaFileHandle,
1571 interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301572 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301573 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301574 insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301575 validateLineLength(interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301576 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301577 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301578 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301579 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301580 if ((fileType & BUILDER_CLASS_MASK) != 0 ||
1581 (fileType & DEFAULT_CLASS_MASK) != 0) {
1582 if (isAttributePresent) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301583 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301584 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301585 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301586
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301587 boolean leavesPresent;
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301588 if (curNode instanceof YangLeavesHolder) {
1589 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301590 leavesPresent = leavesHolder.getListOfLeaf() != null &&
1591 !leavesHolder.getListOfLeaf().isEmpty() ||
1592 leavesHolder.getListOfLeafList() != null &&
1593 !leavesHolder.getListOfLeafList().isEmpty();
1594 if (leavesPresent) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301595 addBitsetImport(imports);
1596 }
1597 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301598 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301599 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301600 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301601 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301602 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301603
1604 //Create impl class file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301605 implClassJavaFileHandle =
1606 getJavaFileHandle(getImplClassName(curNode));
1607 implClassJavaFileHandle =
1608 generateDefaultClassFile(implClassJavaFileHandle,
1609 curNode, isAttributePresent,
1610 imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301611
1612 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301613 if ((fileType & BUILDER_CLASS_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301614 builderClassJavaFileHandle =
1615 getJavaFileHandle(getJavaClassName(
1616 BUILDER_CLASS_FILE_NAME_SUFFIX));
1617 builderClassJavaFileHandle =
1618 generateBuilderClassFile(builderClassJavaFileHandle,
1619 curNode,
1620 isAttributePresent);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301621
1622 //Append impl class to builder class and close it.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301623 mergeJavaFiles(builderClassJavaFileHandle,
1624 implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301625 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301626 insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301627 validateLineLength(implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301628 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301629 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301630 freeTemporaryResources(false);
1631 }
1632
Vidyashree Ramab3670472016-08-06 15:49:56 +05301633 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301634 private void addArrayListImport(List<String> imports) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301635 if (imports.contains(javaImportData.getImportForList())) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301636 imports.add(ARRAY_LIST_IMPORT);
1637 }
1638 }
1639
Bharat saraswal8beac342016-08-04 02:00:03 +05301640 private void addBitsetImport(List<String> imports) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301641 imports.add(javaImportData.getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301642 }
1643
1644 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301645 * Adds imports for ToString and HashCodeMethod.
1646 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301647 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301648 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301649 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301650 protected void addImportsToStringAndHasCodeMethods(List<String> imports,
1651 boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301652 if (operation) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301653 imports.add(javaImportData.getImportForHashAndEquals());
1654 imports.add(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301655 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301656 imports.remove(javaImportData.getImportForHashAndEquals());
1657 imports.remove(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301658 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301659 // TODO change boolean to OPERATION, in all related places.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301660 }
1661
1662 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301663 * Adds import for map and hash map.
1664 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301665 * @param imports import list
1666 * @param operations true for adding and false for deletion
1667 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301668 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301669 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301670 private void addImportsForAugmentableClass(List<String> imports,
1671 boolean operations,
1672 boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301673 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301674 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301675 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301676 imports.add(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301677 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301678 // Add import for hash map only if node is not a YANG choice.
1679 if (!(curNode instanceof YangChoice)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301680 imports.add(javaImportData.getMapImport());
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301681 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301682 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301683 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301684 imports.remove(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301685 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301686 imports.remove(javaImportData.getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301687 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301688 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301689 }
1690
1691 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301692 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301693 *
1694 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301695 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301696 private void addInvocationExceptionImport(List<String> imports) {
1697 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301698 }
1699
1700 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301701 * Removes all temporary file handles.
1702 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301703 * @param errorOccurred flag indicating if error occurred
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301704 * @throws IOException when failed to delete the temporary files
1705 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301706 public void freeTemporaryResources(boolean errorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301707 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301708 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301709 * Close all java file handles and when error occurs delete the files.
1710 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301711 if (javaFlagSet(INTERFACE_MASK)) {
1712 closeFile(interfaceJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301713 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301714 if (javaFlagSet(BUILDER_CLASS_MASK)) {
1715 closeFile(builderClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301716 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301717 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
1718 closeFile(builderInterfaceJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301719 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301720 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
1721 closeFile(implClassJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301722 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301723 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301724 * Close all temporary file handles and delete the files.
1725 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301726 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
1727 closeFile(getterImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301728 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301729 if (tempFlagSet(ATTRIBUTES_MASK)) {
1730 closeFile(attributesTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301731 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301732 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
1733 closeFile(hashCodeImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301734 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301735 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
1736 closeFile(toStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301737 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301738 if (tempFlagSet(EQUALS_IMPL_MASK)) {
1739 closeFile(equalsImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301740 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301741 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1742 closeFile(fromStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301743 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301744 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
1745 closeFile(addToListImplTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301746 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301747 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
1748 closeFile(addToListInterfaceTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301749 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301750 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
1751 closeFile(leafIdAttributeTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301752 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301753 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
1754 closeFile(subtreeFilteringForLeafTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301755 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301756 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
1757 closeFile(getSubtreeFilteringForListTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301758 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301759 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
1760 closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301761 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301762 if (tempFlagSet(EDIT_CONTENT_MASK)) {
1763 closeFile(editContentTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301764 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301765 }
1766
1767 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301768 * Returns if the attribute needs to be accessed in a qualified manner or
1769 * not, if it needs to be imported, then the same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301770 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301771 * @param importInfo import info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301772 * @return status of the qualified access to the attribute
1773 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301774 protected boolean getIsQualifiedAccessOrAddToImportList(
1775 JavaQualifiedTypeInfo importInfo) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301776 return javaImportData
1777 .addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
1778 getGeneratedJavaClassName(),
1779 javaFileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301780 }
1781
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301782 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301783 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301784 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301785 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301786 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301787 public File getAddToListInterfaceTempFileHandle() {
1788 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301789 }
1790
1791 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301792 * Returns temp file handle for add to list impl.
1793 *
1794 * @return temp file handle for add to list impl
1795 */
1796 public File getAddToListImplTempFileHandle() {
1797 return addToListImplTempFileHandle;
1798 }
1799
1800 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301801 * Returns temp file handle for leaf identifier attributes.
1802 *
1803 * @return temp file handle for leaf identifier attributes
1804 */
1805 public File getLeafIdAttributeTempFileHandle() {
1806 return leafIdAttributeTempFileHandle;
1807 }
1808
1809 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301810 * Sets true if root node.
1811 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301812 * @param rootNode true if root node
Bharat saraswal8beac342016-08-04 02:00:03 +05301813 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301814 void setRootNode(boolean rootNode) {
1815 this.rootNode = rootNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301816 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301817
1818 /**
1819 * Returns temp file for is content match.
1820 *
1821 * @return temp file for is content match
1822 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301823 public File getSubtreeFilteringForLeafTempFileHandle() {
1824 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301825 }
1826
1827 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301828 * Returns temp file for edit content file.
1829 *
1830 * @return temp file for edit content file
1831 */
1832 public File getEditContentTempFileHandle() {
1833 return editContentTempFileHandle;
1834 }
1835
1836 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301837 * Returns temp file for is content match.
1838 *
1839 * @return temp file for is content match
1840 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301841 public File getGetSubtreeFilteringForListTempFileHandle() {
1842 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301843 }
1844
1845 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301846 * Returns temp file for is content match.
1847 *
1848 * @return temp file for is content match
1849 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301850 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
1851 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301852 }
1853
1854 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301855 * Checks if a given flag is set in generated java files.
1856 * Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
1857 * <pre>
1858 * javaFlagSet(FOO | BAR)
1859 * </pre>
1860 * returns true if either FOO flag or BAR flag is set.
Bharat saraswale50edca2016-08-05 01:58:25 +05301861 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301862 * @param flag input flag mask value
1863 * @return true if set, else false
Bharat saraswale50edca2016-08-05 01:58:25 +05301864 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301865 private boolean javaFlagSet(int flag) {
1866 return (getGeneratedJavaFiles() & flag) != 0;
1867 }
1868
1869 /**
1870 * Checks if a given flag is set in temp files.
1871 *
1872 * @param flag input flag mask value
1873 * @return true if set, else false
1874 */
1875 private boolean tempFlagSet(int flag) {
1876 return (tempFilesFlagSet & flag) != 0;
Bharat saraswale50edca2016-08-05 01:58:25 +05301877 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301878}