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; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 24 | |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 25 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 26 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 29 | 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] | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 31 | |
| 32 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 33 | * Represents implementation of java code fragments temporary implementations. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 34 | * Contains fragment file object of different types of java file. |
| 35 | * Uses required object(s) to generate the target java file(s). |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 36 | */ |
| 37 | public class TempJavaCodeFragmentFiles { |
| 38 | |
| 39 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 40 | * Has the temporary files required for bean generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 41 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 42 | private TempJavaBeanFragmentFiles beanTempFiles; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 43 | |
| 44 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 45 | * Has the temporary files required for bean generated classes. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 46 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 47 | private TempJavaTypeFragmentFiles typeTempFiles; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 48 | |
| 49 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 50 | * Has the temporary files required for service generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 51 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 52 | private TempJavaServiceFragmentFiles serviceTempFiles; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 53 | |
| 54 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 55 | * Has the temporary files required for enumeration generated classes. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 56 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 57 | private TempJavaEnumerationFragmentFiles enumerationTempFiles; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 58 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 59 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 60 | * Has the temporary files required for generated event classes. |
| 61 | */ |
| 62 | private TempJavaEventFragmentFiles eventTempFiles; |
| 63 | |
| 64 | /** |
| 65 | * Has the temporary files required for generated event listenerclasses. |
| 66 | */ |
| 67 | private TempJavaEventListenerFragmentFiles eventListenerTempFiles; |
| 68 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 69 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 70 | * Creates an instance of temporary java code fragment. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 71 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 72 | * @param javaFileInfo generated java file info |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 73 | * @throws IOException when fails to create new file handle |
| 74 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 75 | public TempJavaCodeFragmentFiles(JavaFileInfo javaFileInfo) |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 76 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 77 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 78 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
| 79 | setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | * Creates user defined data type class file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 84 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 85 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) { |
| 86 | setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 90 | * Creates enumeration class file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 91 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 92 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) { |
| 93 | setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo)); |
| 94 | } |
| 95 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 96 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 97 | setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo)); |
| 98 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 99 | |
| 100 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) { |
| 101 | setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo)); |
| 102 | } |
| 103 | |
| 104 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) { |
| 105 | setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo)); |
| 106 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Retrieves the temp file handle for bean file generation. |
| 111 | * |
| 112 | * @return temp file handle for bean file generation |
| 113 | */ |
| 114 | public TempJavaBeanFragmentFiles getBeanTempFiles() { |
| 115 | return beanTempFiles; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Sets temp file handle for bean file generation. |
| 120 | * |
| 121 | * @param beanTempFiles temp file handle for bean file generation |
| 122 | */ |
| 123 | public void setBeanTempFiles(TempJavaBeanFragmentFiles beanTempFiles) { |
| 124 | this.beanTempFiles = beanTempFiles; |
| 125 | } |
| 126 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 127 | /** |
| 128 | * Retrieves the temp file handle for data type file generation. |
| 129 | * |
| 130 | * @return temp file handle for data type file generation |
| 131 | */ |
| 132 | public TempJavaTypeFragmentFiles getTypeTempFiles() { |
| 133 | return typeTempFiles; |
| 134 | } |
| 135 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 136 | /** |
| 137 | * Sets temp file handle for data type file generation. |
| 138 | * |
| 139 | * @param typeTempFiles temp file handle for data type file generation |
| 140 | */ |
| 141 | public void setTypeTempFiles(TempJavaTypeFragmentFiles typeTempFiles) { |
| 142 | this.typeTempFiles = typeTempFiles; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Retrieves the temp file handle for service file generation. |
| 147 | * |
| 148 | * @return temp file handle for service file generation |
| 149 | */ |
| 150 | public TempJavaServiceFragmentFiles getServiceTempFiles() { |
| 151 | return serviceTempFiles; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Sets temp file handle for service file generation. |
| 156 | * |
| 157 | * @param serviceTempFiles temp file handle for service file generation |
| 158 | */ |
| 159 | public void setServiceTempFiles(TempJavaServiceFragmentFiles serviceTempFiles) { |
| 160 | this.serviceTempFiles = serviceTempFiles; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Retrieves the temp file handle for enumeration file generation. |
| 165 | * |
| 166 | * @return temp file handle for enumeration file generation |
| 167 | */ |
| 168 | public TempJavaEnumerationFragmentFiles getEnumerationTempFiles() { |
| 169 | return enumerationTempFiles; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Sets temp file handle for enumeration file generation. |
| 174 | * |
| 175 | * @param enumerationTempFiles temp file handle for enumeration file generation |
| 176 | */ |
| 177 | public void setEnumerationTempFiles( |
| 178 | TempJavaEnumerationFragmentFiles enumerationTempFiles) { |
| 179 | this.enumerationTempFiles = enumerationTempFiles; |
| 180 | } |
| 181 | |
| 182 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 183 | * Retrieves the temp file handle for event file generation. |
| 184 | * |
| 185 | * @return temp file handle for event file generation |
| 186 | */ |
| 187 | public TempJavaEventFragmentFiles getEventTempFiles() { |
| 188 | return eventTempFiles; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Sets temp file handle for event file generation. |
| 193 | * |
| 194 | * @param eventTempFiles temp file handle for event file generation |
| 195 | */ |
| 196 | public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) { |
| 197 | this.eventTempFiles = eventTempFiles; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Retrieves the temp file handle for event listener file generation. |
| 202 | * |
| 203 | * @return temp file handle for event listener file generation |
| 204 | */ |
| 205 | public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() { |
| 206 | return eventListenerTempFiles; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Sets temp file handle for event listener file generation. |
| 211 | * |
| 212 | * @param eventListenerTempFiles temp file handle for event listener file generation |
| 213 | */ |
| 214 | public void setEventListenerTempFiles( |
| 215 | TempJavaEventListenerFragmentFiles eventListenerTempFiles) { |
| 216 | this.eventListenerTempFiles = eventListenerTempFiles; |
| 217 | } |
| 218 | |
| 219 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 220 | * Constructs java code exit. |
| 221 | * |
| 222 | * @param fileType generated file type |
| 223 | * @param curNode current YANG node |
| 224 | * @throws IOException when fails to generate java files |
| 225 | */ |
| 226 | public void generateJavaFile(int fileType, YangNode curNode) |
| 227 | throws IOException { |
| 228 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 229 | if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 230 | getBeanTempFiles().generateJavaFile(fileType, curNode); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 231 | } |
| 232 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 233 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 234 | * Creates user defined data type class file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 235 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 236 | if ((fileType & GENERATE_TYPE_CLASS) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 237 | getTypeTempFiles().generateJavaFile(fileType, curNode); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 238 | } |
| 239 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 240 | /* |
| 241 | * Creats service and manager class file. |
| 242 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 243 | if (fileType == GENERATE_SERVICE_AND_MANAGER) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 244 | getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 245 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 246 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 247 | /* |
| 248 | * Creats enumeration class file. |
| 249 | */ |
| 250 | if (fileType == GENERATE_ENUM_CLASS) { |
| 251 | getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if ((fileType & GENERATE_EVENT_CLASS) != 0) { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 255 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 256 | * Creates event class file. |
| 257 | */ |
| 258 | if (getEventTempFiles() != null) { |
| 259 | getEventTempFiles().generateJavaFile(fileType, curNode); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) { |
| 264 | /** |
| 265 | * Creates event listener class file. |
| 266 | */ |
| 267 | getEventListenerTempFiles().generateJavaFile(fileType, curNode); |
| 268 | } |
| 269 | |
| 270 | freeTemporaryResources(false); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Adds the new attribute info to the target generated temporary files. |
| 275 | * |
| 276 | * @param newAttrInfo the attribute info that needs to be added to temporary |
| 277 | * files |
| 278 | * @throws IOException IO operation fail |
| 279 | */ |
| 280 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
| 281 | throws IOException { |
| 282 | |
| 283 | if (getBeanTempFiles() != null) { |
| 284 | getBeanTempFiles() |
| 285 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 286 | } |
| 287 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 288 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 289 | * Creates user defined data type class file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 290 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 291 | if (getTypeTempFiles() != null) { |
| 292 | getTypeTempFiles() |
| 293 | .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 294 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 298 | * Add all the type in the current data model node as part of the |
| 299 | * generated temporary file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 300 | * |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 301 | * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 302 | * @throws IOException IO operation fail |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 303 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 304 | public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 305 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 306 | getTypeTempFiles() |
| 307 | .addTypeInfoToTempFiles(yangTypeHolder); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 311 | * Adds build method for interface. |
| 312 | * |
| 313 | * @return build method for interface |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 314 | * @throws IOException when fails to append to temporary file |
| 315 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 316 | public String addBuildMethodForInterface() |
| 317 | throws IOException { |
| 318 | if (getBeanTempFiles() != null) { |
| 319 | return getBeanTempFiles().addBuildMethodForInterface(); |
| 320 | } |
| 321 | throw new TranslatorException("build method only supported for bean class"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Adds default constructor for class. |
| 326 | * |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 327 | * @param modifier modifier for constructor. |
| 328 | * @param toAppend string which need to be appended with the class name |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 329 | * @return default constructor for class |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 330 | * @throws IOException when fails to append to file |
| 331 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 332 | public String addDefaultConstructor(String modifier, String toAppend) |
| 333 | throws IOException { |
| 334 | if (getTypeTempFiles() != null) { |
| 335 | return getTypeTempFiles() |
| 336 | .addDefaultConstructor(modifier, toAppend); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 337 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 338 | |
| 339 | if (getBeanTempFiles() != null) { |
| 340 | return getBeanTempFiles().addDefaultConstructor(modifier, toAppend); |
| 341 | } |
| 342 | |
| 343 | throw new TranslatorException("default constructor should not be added"); |
| 344 | } |
| 345 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 346 | /** |
| 347 | * Adds build method's implementation for class. |
| 348 | * |
| 349 | * @return build method implementation for class |
| 350 | * @throws IOException when fails to append to temporary file |
| 351 | */ |
| 352 | public String addBuildMethodImpl() |
| 353 | throws IOException { |
| 354 | if (getBeanTempFiles() != null) { |
| 355 | return getBeanTempFiles().addBuildMethodImpl(); |
| 356 | } |
| 357 | |
| 358 | throw new TranslatorException("build should not be added"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 362 | * Removes all temporary file handles. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 363 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 364 | * @param isErrorOccurred when translator fails to generate java files we need to close |
| 365 | * all open file handles include temporary files and java files. |
| 366 | * @throws IOException when failed to delete the temporary files |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 367 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 368 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 369 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 370 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 371 | if (getBeanTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 372 | getBeanTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 373 | } |
| 374 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 375 | if (getTypeTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 376 | getTypeTempFiles().freeTemporaryResources(isErrorOccurred); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 377 | } |
| 378 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 379 | if (getEnumerationTempFiles() != null) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 380 | getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred); |
| 381 | } |
| 382 | |
| 383 | if (getEventTempFiles() != null) { |
| 384 | getEventTempFiles().freeTemporaryResources(isErrorOccurred); |
| 385 | } |
| 386 | |
| 387 | if (getEventListenerTempFiles() != null) { |
| 388 | getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 392 | } |