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