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 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Adds the new attribute info to the target generated temporary files. |
| 196 | * |
| 197 | * @param newAttrInfo the attribute info that needs to be added to temporary |
| 198 | * files |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 199 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 200 | * @throws IOException IO operation fail |
| 201 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 202 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, |
| 203 | YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 204 | throws IOException { |
| 205 | |
| 206 | if (getBeanTempFiles() != null) { |
| 207 | getBeanTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 208 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 211 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 212 | * Creates user defined data type class file. |
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 | if (getTypeTempFiles() != null) { |
| 215 | getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 216 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 217 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 221 | * Add all the type in the current data model node as part of the |
| 222 | * generated temporary file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 223 | * |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 224 | * @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] | 225 | * @param pluginConfig plugin configurations for naming convention |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 226 | * @throws IOException IO operation fail |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 227 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 228 | public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 229 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 230 | getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 231 | .addTypeInfoToTempFiles(yangTypeHolder, pluginConfig); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 235 | * Adds build method for interface. |
| 236 | * |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 237 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 238 | * @return build method for interface |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 239 | * @throws IOException when fails to append to temporary file |
| 240 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 241 | public String addBuildMethodForInterface(YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 242 | throws IOException { |
| 243 | if (getBeanTempFiles() != null) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 244 | return getBeanTempFiles().addBuildMethodForInterface(pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 245 | } |
| 246 | throw new TranslatorException("build method only supported for bean class"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Adds default constructor for class. |
| 251 | * |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 252 | * @param modifier modifier for constructor. |
| 253 | * @param toAppend string which need to be appended with the class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 254 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 255 | * @return default constructor for class |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 256 | * @throws IOException when fails to append to file |
| 257 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 258 | public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 259 | throws IOException { |
| 260 | if (getTypeTempFiles() != null) { |
| 261 | return getTypeTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 262 | .addDefaultConstructor(modifier, toAppend, pluginConfig); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 263 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 264 | |
| 265 | if (getBeanTempFiles() != null) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 266 | return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | throw new TranslatorException("default constructor should not be added"); |
| 270 | } |
| 271 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 272 | /** |
| 273 | * Adds build method's implementation for class. |
| 274 | * |
| 275 | * @return build method implementation for class |
| 276 | * @throws IOException when fails to append to temporary file |
| 277 | */ |
| 278 | public String addBuildMethodImpl() |
| 279 | throws IOException { |
| 280 | if (getBeanTempFiles() != null) { |
| 281 | return getBeanTempFiles().addBuildMethodImpl(); |
| 282 | } |
| 283 | |
| 284 | throw new TranslatorException("build should not be added"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 288 | * Removes all temporary file handles. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 289 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 290 | * @param isErrorOccurred when translator fails to generate java files we need to close |
| 291 | * all open file handles include temporary files and java files. |
| 292 | * @throws IOException when failed to delete the temporary files |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 293 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 294 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 295 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 296 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 297 | if (getBeanTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 298 | getBeanTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 299 | } |
| 300 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 301 | if (getTypeTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 302 | getTypeTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 303 | } |
| 304 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 305 | if (getEnumerationTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 306 | getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred); |
| 307 | } |
| 308 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 309 | if (getServiceTempFiles() != null) { |
| 310 | getServiceTempFiles().freeTemporaryResources(isErrorOccurred); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 311 | } |
| 312 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 313 | } |
| 314 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 315 | } |