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