Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava; |
| 18 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 25 | |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 30 | |
| 31 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 32 | * Represents implementation of java code fragments temporary implementations. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 33 | * Contains fragment file object of different types of java file. |
| 34 | * Uses required object(s) to generate the target java file(s). |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 35 | */ |
| 36 | public class TempJavaCodeFragmentFiles { |
| 37 | |
| 38 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 39 | * Has the temporary files required for bean generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 40 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | private TempJavaBeanFragmentFiles beanTempFiles; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 42 | |
| 43 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 44 | * Has the temporary files required for bean generated classes. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 45 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 46 | private TempJavaTypeFragmentFiles typeTempFiles; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 47 | |
| 48 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 49 | * Has the temporary files required for service generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 50 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 51 | private TempJavaServiceFragmentFiles serviceTempFiles; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 52 | |
| 53 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 54 | * Has the temporary files required for enumeration generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 55 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 56 | private TempJavaEnumerationFragmentFiles enumerationTempFiles; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 57 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 58 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 59 | * Creates an instance of temporary java code fragment. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 60 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 61 | * @param javaFileInfo generated java file info |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 62 | * @throws IOException when fails to create new file handle |
| 63 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 64 | public TempJavaCodeFragmentFiles(JavaFileInfo javaFileInfo) |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 65 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 66 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 67 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
| 68 | setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 69 | } |
| 70 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 71 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) { |
| 72 | setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 73 | } |
| 74 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 75 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) { |
| 76 | setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo)); |
| 77 | } |
| 78 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 79 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 80 | setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo)); |
| 81 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 82 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Retrieves the temp file handle for bean file generation. |
| 87 | * |
| 88 | * @return temp file handle for bean file generation |
| 89 | */ |
| 90 | public TempJavaBeanFragmentFiles getBeanTempFiles() { |
| 91 | return beanTempFiles; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Sets temp file handle for bean file generation. |
| 96 | * |
| 97 | * @param beanTempFiles temp file handle for bean file generation |
| 98 | */ |
| 99 | public void setBeanTempFiles(TempJavaBeanFragmentFiles beanTempFiles) { |
| 100 | this.beanTempFiles = beanTempFiles; |
| 101 | } |
| 102 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 103 | /** |
| 104 | * Retrieves the temp file handle for data type file generation. |
| 105 | * |
| 106 | * @return temp file handle for data type file generation |
| 107 | */ |
| 108 | public TempJavaTypeFragmentFiles getTypeTempFiles() { |
| 109 | return typeTempFiles; |
| 110 | } |
| 111 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 112 | /** |
| 113 | * Sets temp file handle for data type file generation. |
| 114 | * |
| 115 | * @param typeTempFiles temp file handle for data type file generation |
| 116 | */ |
| 117 | public void setTypeTempFiles(TempJavaTypeFragmentFiles typeTempFiles) { |
| 118 | this.typeTempFiles = typeTempFiles; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Retrieves the temp file handle for service file generation. |
| 123 | * |
| 124 | * @return temp file handle for service file generation |
| 125 | */ |
| 126 | public TempJavaServiceFragmentFiles getServiceTempFiles() { |
| 127 | return serviceTempFiles; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Sets temp file handle for service file generation. |
| 132 | * |
| 133 | * @param serviceTempFiles temp file handle for service file generation |
| 134 | */ |
| 135 | public void setServiceTempFiles(TempJavaServiceFragmentFiles serviceTempFiles) { |
| 136 | this.serviceTempFiles = serviceTempFiles; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Retrieves the temp file handle for enumeration file generation. |
| 141 | * |
| 142 | * @return temp file handle for enumeration file generation |
| 143 | */ |
| 144 | public TempJavaEnumerationFragmentFiles getEnumerationTempFiles() { |
| 145 | return enumerationTempFiles; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Sets temp file handle for enumeration file generation. |
| 150 | * |
| 151 | * @param enumerationTempFiles temp file handle for enumeration file generation |
| 152 | */ |
| 153 | public void setEnumerationTempFiles( |
| 154 | TempJavaEnumerationFragmentFiles enumerationTempFiles) { |
| 155 | this.enumerationTempFiles = enumerationTempFiles; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Constructs java code exit. |
| 160 | * |
| 161 | * @param fileType generated file type |
| 162 | * @param curNode current YANG node |
| 163 | * @throws IOException when fails to generate java files |
| 164 | */ |
| 165 | public void generateJavaFile(int fileType, YangNode curNode) |
| 166 | throws IOException { |
| 167 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 168 | if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 169 | getBeanTempFiles().generateJavaFile(fileType, curNode); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 170 | } |
| 171 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 172 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 173 | * Creates user defined data type class file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 174 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 175 | if ((fileType & GENERATE_TYPE_CLASS) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 176 | getTypeTempFiles().generateJavaFile(fileType, curNode); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 177 | } |
| 178 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 179 | /* |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 180 | * Creates service and manager class file. |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 181 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 182 | if (fileType == GENERATE_SERVICE_AND_MANAGER) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 183 | getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 184 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 185 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 186 | /* |
| 187 | * Creats enumeration class file. |
| 188 | */ |
| 189 | if (fileType == GENERATE_ENUM_CLASS) { |
| 190 | getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 191 | } |
| 192 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 193 | freeTemporaryResources(false); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Adds the new attribute info to the target generated temporary files. |
| 198 | * |
| 199 | * @param newAttrInfo the attribute info that needs to be added to temporary |
| 200 | * files |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 201 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 202 | * @throws IOException IO operation fail |
| 203 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 204 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, |
| 205 | YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 206 | throws IOException { |
| 207 | |
| 208 | if (getBeanTempFiles() != null) { |
| 209 | getBeanTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 210 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 211 | } |
| 212 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 213 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 214 | * Creates user defined data type class file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 215 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 216 | if (getTypeTempFiles() != null) { |
| 217 | getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 218 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 219 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 223 | * Add all the type in the current data model node as part of the |
| 224 | * generated temporary file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 225 | * |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 226 | * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 227 | * @param pluginConfig plugin configurations for naming convention |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 228 | * @throws IOException IO operation fail |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 229 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 230 | public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 231 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 232 | getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 233 | .addTypeInfoToTempFiles(yangTypeHolder, pluginConfig); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 237 | * Adds build method for interface. |
| 238 | * |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 239 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 240 | * @return build method for interface |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 241 | * @throws IOException when fails to append to temporary file |
| 242 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 243 | public String addBuildMethodForInterface(YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 244 | throws IOException { |
| 245 | if (getBeanTempFiles() != null) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 246 | return getBeanTempFiles().addBuildMethodForInterface(pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 247 | } |
| 248 | throw new TranslatorException("build method only supported for bean class"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Adds default constructor for class. |
| 253 | * |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 254 | * @param modifier modifier for constructor. |
| 255 | * @param toAppend string which need to be appended with the class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 256 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 257 | * @return default constructor for class |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 258 | * @throws IOException when fails to append to file |
| 259 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 260 | public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 261 | throws IOException { |
| 262 | if (getTypeTempFiles() != null) { |
| 263 | return getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 264 | .addDefaultConstructor(modifier, toAppend, pluginConfig); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 265 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 266 | |
| 267 | if (getBeanTempFiles() != null) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 268 | return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | throw new TranslatorException("default constructor should not be added"); |
| 272 | } |
| 273 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 274 | /** |
| 275 | * Adds build method's implementation for class. |
| 276 | * |
| 277 | * @return build method implementation for class |
| 278 | * @throws IOException when fails to append to temporary file |
| 279 | */ |
| 280 | public String addBuildMethodImpl() |
| 281 | throws IOException { |
| 282 | if (getBeanTempFiles() != null) { |
| 283 | return getBeanTempFiles().addBuildMethodImpl(); |
| 284 | } |
| 285 | |
| 286 | throw new TranslatorException("build should not be added"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 290 | * Removes all temporary file handles. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 291 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 292 | * @param isErrorOccurred when translator fails to generate java files we need to close |
| 293 | * all open file handles include temporary files and java files. |
| 294 | * @throws IOException when failed to delete the temporary files |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 295 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 296 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 297 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 298 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 299 | if (getBeanTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 300 | getBeanTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 301 | } |
| 302 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 303 | if (getTypeTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 304 | getTypeTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 305 | } |
| 306 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 307 | if (getEnumerationTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 308 | getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred); |
| 309 | } |
| 310 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 311 | if (getServiceTempFiles() != null) { |
| 312 | getServiceTempFiles().freeTemporaryResources(isErrorOccurred); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 313 | } |
| 314 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 315 | } |
| 316 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 317 | } |