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