Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 19 | import java.io.File; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | import java.io.IOException; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangNotification; |
| 26 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
| 27 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; |
| 28 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 29 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
| 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
| 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; |
| 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; |
| 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
| 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
| 41 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; |
| 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; |
| 45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile; |
| 47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
| 49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
| 53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; |
| 55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 57 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAnnotationsImports; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 58 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; |
| 65 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 67 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 68 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 70 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 71 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; |
| 72 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; |
| 74 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 75 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Represents implementation of java service code fragments temporary implementations. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 80 | * Maintains the temp files required specific for service and manager java snippet generation. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 81 | */ |
| 82 | public class TempJavaServiceFragmentFiles |
| 83 | extends TempJavaFragmentFiles { |
| 84 | |
| 85 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 86 | * File name for rpc method. |
| 87 | */ |
| 88 | private static final String RPC_INTERFACE_FILE_NAME = "Rpc"; |
| 89 | |
| 90 | /** |
| 91 | * File name for rpc implementation method. |
| 92 | */ |
| 93 | private static final String RPC_IMPL_FILE_NAME = "RpcImpl"; |
| 94 | |
| 95 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 96 | * File name for event enum temp file. |
| 97 | */ |
| 98 | private static final String EVENT_ENUM_FILE_NAME = "EventEnum"; |
| 99 | |
| 100 | /** |
| 101 | * File name for event method temp file. |
| 102 | */ |
| 103 | private static final String EVENT_METHOD_FILE_NAME = "EventMethod"; |
| 104 | |
| 105 | /** |
| 106 | * File name for event subject attribute temp file. |
| 107 | */ |
| 108 | private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute"; |
| 109 | |
| 110 | /** |
| 111 | * File name for event subject getter temp file. |
| 112 | */ |
| 113 | private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter"; |
| 114 | |
| 115 | /** |
| 116 | * File name for event subject setter temp file. |
| 117 | */ |
| 118 | private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter"; |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 119 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 120 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 121 | * File name for generated class file for service |
| 122 | * suffix. |
| 123 | */ |
| 124 | private static final String SERVICE_FILE_NAME_SUFFIX = "Service"; |
| 125 | |
| 126 | /** |
| 127 | * File name for generated class file for manager |
| 128 | * suffix. |
| 129 | */ |
| 130 | private static final String MANAGER_FILE_NAME_SUFFIX = "Manager"; |
| 131 | |
| 132 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 133 | * File name for generated class file for special type like union, typedef |
| 134 | * suffix. |
| 135 | */ |
| 136 | private static final String EVENT_FILE_NAME_SUFFIX = "Event"; |
| 137 | |
| 138 | /** |
| 139 | * File name for generated class file for special type like union, typedef |
| 140 | * suffix. |
| 141 | */ |
| 142 | private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener"; |
| 143 | |
| 144 | /** |
| 145 | * File name for generated class file for special type like union, typedef |
| 146 | * suffix. |
| 147 | */ |
| 148 | public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject"; |
| 149 | |
| 150 | private static final String JAVA_FILE_EXTENSION = ".java"; |
| 151 | |
| 152 | /** |
| 153 | * Java file handle for event subject file. |
| 154 | */ |
| 155 | private File eventSubjectJavaFileHandle; |
| 156 | |
| 157 | /** |
| 158 | * Java file handle for event listener file. |
| 159 | */ |
| 160 | private File eventListenerJavaFileHandle; |
| 161 | |
| 162 | /** |
| 163 | * Java file handle for event file. |
| 164 | */ |
| 165 | private File eventJavaFileHandle; |
| 166 | |
| 167 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 168 | * Temporary file handle for rpc interface. |
| 169 | */ |
| 170 | private File rpcInterfaceTempFileHandle; |
| 171 | |
| 172 | /** |
| 173 | * Temporary file handle for rpc manager impl. |
| 174 | */ |
| 175 | private File rpcImplTempFileHandle; |
| 176 | |
| 177 | /** |
| 178 | * Java file handle for rpc interface file. |
| 179 | */ |
| 180 | private File serviceInterfaceJavaFileHandle; |
| 181 | |
| 182 | /** |
| 183 | * Java file handle for manager impl file. |
| 184 | */ |
| 185 | private File managerJavaFileHandle; |
| 186 | |
| 187 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 188 | * Java file handle for event enum impl file. |
| 189 | */ |
| 190 | private File eventEnumTempFileHandle; |
| 191 | |
| 192 | /** |
| 193 | * Java file handle for event method impl file. |
| 194 | */ |
| 195 | private File eventMethodTempFileHandle; |
| 196 | |
| 197 | /** |
| 198 | * Java file handle for event subject attribute file. |
| 199 | */ |
| 200 | private File eventSubjectAttributeTempFileHandle; |
| 201 | |
| 202 | /** |
| 203 | * Java file handle for event subject getter impl file. |
| 204 | */ |
| 205 | private File eventSubjectGetterTempFileHandle; |
| 206 | |
| 207 | /** |
| 208 | * Java file handle for event subject setter impl file. |
| 209 | */ |
| 210 | private File eventSubjectSetterTempFileHandle; |
| 211 | |
| 212 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 213 | * Returns rpc method's java file handle. |
| 214 | * |
| 215 | * @return java file handle |
| 216 | */ |
| 217 | private File getServiceInterfaceJavaFileHandle() { |
| 218 | return serviceInterfaceJavaFileHandle; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Sets rpc method's java file handle. |
| 223 | * |
| 224 | * @param serviceInterfaceJavaFileHandle file handle for to rpc method |
| 225 | */ |
| 226 | private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) { |
| 227 | this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Returns managers java file handle. |
| 232 | * |
| 233 | * @return java file handle |
| 234 | */ |
| 235 | public File getManagerJavaFileHandle() { |
| 236 | return managerJavaFileHandle; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Sets manager java file handle. |
| 241 | * |
| 242 | * @param managerJavaFileHandle file handle for to manager |
| 243 | */ |
| 244 | public void setManagerJavaFileHandle(File managerJavaFileHandle) { |
| 245 | this.managerJavaFileHandle = managerJavaFileHandle; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Returns rpc method's temporary file handle. |
| 250 | * |
| 251 | * @return temporary file handle |
| 252 | */ |
| 253 | public File getRpcInterfaceTempFileHandle() { |
| 254 | return rpcInterfaceTempFileHandle; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Sets rpc method's temporary file handle. |
| 259 | * |
| 260 | * @param rpcInterfaceTempFileHandle file handle for to rpc method |
| 261 | */ |
| 262 | private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) { |
| 263 | this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Retrieves the manager impl temp file. |
| 268 | * |
| 269 | * @return the manager impl temp file |
| 270 | */ |
| 271 | public File getRpcImplTempFileHandle() { |
| 272 | return rpcImplTempFileHandle; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Sets the manager impl temp file. |
| 277 | * |
| 278 | * @param rpcImplTempFileHandle the manager impl temp file |
| 279 | */ |
| 280 | public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) { |
| 281 | this.rpcImplTempFileHandle = rpcImplTempFileHandle; |
| 282 | } |
| 283 | |
| 284 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 285 | * Returns event's java file handle. |
| 286 | * |
| 287 | * @return java file handle |
| 288 | */ |
| 289 | private File getEventJavaFileHandle() { |
| 290 | return eventJavaFileHandle; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Sets event's java file handle. |
| 295 | * |
| 296 | * @param eventJavaFileHandle file handle for event |
| 297 | */ |
| 298 | private void setEventJavaFileHandle(File eventJavaFileHandle) { |
| 299 | this.eventJavaFileHandle = eventJavaFileHandle; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Returns event listeners's java file handle. |
| 304 | * |
| 305 | * @return java file handle |
| 306 | */ |
| 307 | private File getEventListenerJavaFileHandle() { |
| 308 | return eventListenerJavaFileHandle; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Sets event's java file handle. |
| 313 | * |
| 314 | * @param eventListenerJavaFileHandle file handle for event |
| 315 | */ |
| 316 | private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) { |
| 317 | this.eventListenerJavaFileHandle = eventListenerJavaFileHandle; |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Returns event subject's java file handle. |
| 322 | * |
| 323 | * @return java file handle |
| 324 | */ |
| 325 | private File getEventSubjectJavaFileHandle() { |
| 326 | return eventSubjectJavaFileHandle; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Sets event's subject java file handle. |
| 331 | * |
| 332 | * @param eventSubjectJavaFileHandle file handle for event's subject |
| 333 | */ |
| 334 | private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) { |
| 335 | this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle; |
| 336 | } |
| 337 | |
| 338 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 339 | * Creates an instance of temporary java code fragment. |
| 340 | * |
| 341 | * @param javaFileInfo generated file information |
| 342 | * @throws IOException when fails to create new file handle |
| 343 | */ |
| 344 | public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo) |
| 345 | throws IOException { |
| 346 | super(javaFileInfo); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 347 | |
| 348 | addGeneratedTempFile(RPC_INTERFACE_MASK); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 349 | addGeneratedTempFile(RPC_IMPL_MASK); |
| 350 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 351 | addGeneratedTempFile(EVENT_ENUM_MASK); |
| 352 | addGeneratedTempFile(EVENT_METHOD_MASK); |
| 353 | addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK); |
| 354 | addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK); |
| 355 | addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK); |
| 356 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 357 | setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME)); |
| 358 | setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 359 | |
| 360 | setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME)); |
| 361 | setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME)); |
| 362 | setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME)); |
| 363 | setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME)); |
| 364 | setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME)); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 368 | * Constructs java code exit. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 369 | * |
| 370 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 371 | * @param curNode current YANG node |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 372 | * @throws IOException when fails to generate java files |
| 373 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 374 | @Override |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 375 | public void generateJavaFile(int fileType, YangNode curNode) |
| 376 | throws IOException { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 377 | List<String> imports = getJavaImportData().getImports(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 378 | |
| 379 | createPackage(curNode); |
| 380 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 381 | boolean isNotification = false; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 382 | if (curNode instanceof YangJavaModule) { |
| 383 | if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 384 | isNotification = true; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 385 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 386 | } else if (curNode instanceof YangJavaSubModule) { |
| 387 | if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) { |
| 388 | isNotification = true; |
| 389 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (isNotification) { |
| 393 | addListnersImport(curNode, imports, true, LISTENER_SERVICE); |
| 394 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 395 | /** |
| 396 | * Creates rpc interface file. |
| 397 | */ |
| 398 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); |
| 399 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); |
| 400 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 401 | if (isNotification) { |
| 402 | addListnersImport(curNode, imports, false, LISTENER_SERVICE); |
| 403 | addListnersImport(curNode, imports, true, LISTENER_REG); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 404 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 405 | addAnnotationsImports(imports, true); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 406 | /** |
| 407 | * Create builder class file. |
| 408 | */ |
| 409 | setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX))); |
| 410 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent()); |
| 411 | |
| 412 | insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 413 | if (isNotification) { |
| 414 | addListnersImport(curNode, imports, false, LISTENER_REG); |
| 415 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 416 | addAnnotationsImports(imports, false); |
| 417 | |
| 418 | if (isNotification) { |
| 419 | generateEventJavaFile(GENERATE_EVENT_CLASS, curNode); |
| 420 | generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode); |
| 421 | generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode); |
| 422 | } |
| 423 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 424 | /** |
| 425 | * Close all the file handles. |
| 426 | */ |
| 427 | freeTemporaryResources(false); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Adds rpc string information to applicable temp file. |
| 432 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 433 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 434 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 435 | * @param rpcName name of the rpc function |
| 436 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 437 | * @throws IOException IO operation fail |
| 438 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 439 | private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 440 | JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 441 | String rpcName) |
| 442 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 443 | String rpcInput = EMPTY_STRING; |
| 444 | String rpcOutput = VOID; |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 445 | String rpcInputJavaDoc = EMPTY_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 446 | if (javaAttributeInfoOfInput != null) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 447 | rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 448 | } |
| 449 | if (javaAttributeInfoOfOutput != null) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 450 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 451 | } |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 452 | if (!rpcInput.equals(EMPTY_STRING)) { |
| 453 | rpcInputJavaDoc = RPC_INPUT_VAR_NAME; |
| 454 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 455 | appendToFile(getRpcInterfaceTempFileHandle(), |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 456 | generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig) |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 457 | + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
| 458 | appendToFile(getRpcImplTempFileHandle(), |
| 459 | getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Adds the JAVA rpc snippet information. |
| 464 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 465 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 466 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 467 | * @param pluginConfig plugin configurations |
| 468 | * @param rpcName name of the rpc function |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 469 | * @throws IOException IO operation fail |
| 470 | */ |
| 471 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 472 | JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 473 | String rpcName) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 474 | throws IOException { |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 475 | addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Constructs java code exit. |
| 480 | * |
| 481 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 482 | * @param curNode current YANG node |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 483 | * @throws IOException when fails to generate java files |
| 484 | */ |
| 485 | public void generateEventJavaFile(int fileType, YangNode curNode) |
| 486 | throws IOException { |
| 487 | |
| 488 | List<String> imports = new ArrayList<>(); |
| 489 | |
| 490 | imports.add(getJavaImportData().getAbstractEventsImport()); |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 491 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 492 | String nodeName = curNodeInfo + EVENT_STRING; |
| 493 | |
| 494 | addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX); |
| 495 | |
| 496 | /** |
| 497 | * Creates event interface file. |
| 498 | */ |
| 499 | setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX)); |
| 500 | generateEventFile(getEventJavaFileHandle(), curNode, imports); |
| 501 | |
| 502 | /** |
| 503 | * Close all the file handles. |
| 504 | */ |
| 505 | freeTemporaryResources(false); |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Constructs java code exit. |
| 510 | * |
| 511 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 512 | * @param curNode current YANG node |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 513 | * @throws IOException when fails to generate java files |
| 514 | */ |
| 515 | public void generateEventListenerJavaFile(int fileType, YangNode curNode) |
| 516 | throws IOException { |
| 517 | |
| 518 | List<String> imports = new ArrayList<>(); |
| 519 | |
| 520 | imports.add(getJavaImportData().getEventListenerImport()); |
| 521 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) |
| 522 | .getJavaFileInfo().getJavaName()); |
| 523 | /** |
| 524 | * Creates event listener interface file. |
| 525 | */ |
| 526 | setEventListenerJavaFileHandle( |
| 527 | getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX)); |
| 528 | generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports); |
| 529 | |
| 530 | /** |
| 531 | * Close all the file handles. |
| 532 | */ |
| 533 | freeTemporaryResources(false); |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Constructs java code exit. |
| 538 | * |
| 539 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 540 | * @param curNode current YANG node |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 541 | * @throws IOException when fails to generate java files |
| 542 | */ |
| 543 | public void generateEventSubjectJavaFile(int fileType, YangNode curNode) |
| 544 | throws IOException { |
| 545 | |
| 546 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) |
| 547 | .getJavaFileInfo().getJavaName()); |
| 548 | /** |
| 549 | * Creates event interface file. |
| 550 | */ |
| 551 | setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + |
| 552 | EVENT_SUBJECT_NAME_SUFFIX)); |
| 553 | generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode); |
| 554 | |
| 555 | /** |
| 556 | * Close all the file handles. |
| 557 | */ |
| 558 | freeTemporaryResources(false); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Removes all temporary file handles. |
| 563 | * |
| 564 | * @param isErrorOccurred when translator fails to generate java files we |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 565 | * need to close all open file handles include temporary files |
| 566 | * and java files. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 567 | * @throws IOException when failed to delete the temporary files |
| 568 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 569 | @Override |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 570 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 571 | throws IOException { |
| 572 | boolean isError = isErrorOccurred; |
| 573 | |
| 574 | closeFile(getServiceInterfaceJavaFileHandle(), isError); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 575 | closeFile(getManagerJavaFileHandle(), isError); |
| 576 | |
| 577 | if (getEventJavaFileHandle() != null) { |
| 578 | closeFile(getEventJavaFileHandle(), isError); |
| 579 | } |
| 580 | if (getEventListenerJavaFileHandle() != null) { |
| 581 | closeFile(getEventListenerJavaFileHandle(), isError); |
| 582 | } |
| 583 | if (getEventSubjectJavaFileHandle() != null) { |
| 584 | closeFile(getEventSubjectJavaFileHandle(), isError); |
| 585 | } |
| 586 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 587 | closeFile(getRpcInterfaceTempFileHandle(), true); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 588 | closeFile(getRpcImplTempFileHandle(), true); |
| 589 | closeFile(getGetterInterfaceTempFileHandle(), true); |
| 590 | closeFile(getSetterInterfaceTempFileHandle(), true); |
| 591 | closeFile(getSetterImplTempFileHandle(), true); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 592 | |
| 593 | super.freeTemporaryResources(isErrorOccurred); |
| 594 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 595 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * Returns event enum temp file. |
| 599 | * |
| 600 | * @return event enum temp file |
| 601 | */ |
| 602 | public File getEventEnumTempFileHandle() { |
| 603 | return eventEnumTempFileHandle; |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Sets event enum temp file. |
| 608 | * |
| 609 | * @param eventEnumTempFileHandle event enum temp file |
| 610 | */ |
| 611 | public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) { |
| 612 | this.eventEnumTempFileHandle = eventEnumTempFileHandle; |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Returns event method temp file. |
| 617 | * |
| 618 | * @return event method temp file |
| 619 | */ |
| 620 | public File getEventMethodTempFileHandle() { |
| 621 | return eventMethodTempFileHandle; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Sets event method temp file. |
| 626 | * |
| 627 | * @param eventMethodTempFileHandle event method temp file |
| 628 | */ |
| 629 | public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) { |
| 630 | this.eventMethodTempFileHandle = eventMethodTempFileHandle; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Returns event subject attribute temp file. |
| 635 | * |
| 636 | * @return event subject attribute temp file |
| 637 | */ |
| 638 | public File getEventSubjectAttributeTempFileHandle() { |
| 639 | return eventSubjectAttributeTempFileHandle; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Sets event subject attribute temp file. |
| 644 | * |
| 645 | * @param eventSubjectAttributeTempFileHandle event subject attribute temp file |
| 646 | */ |
| 647 | public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) { |
| 648 | this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle; |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Returns event subject getter temp file. |
| 653 | * |
| 654 | * @return event subject getter temp file |
| 655 | */ |
| 656 | public File getEventSubjectGetterTempFileHandle() { |
| 657 | return eventSubjectGetterTempFileHandle; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Sets event subject getter temp file. |
| 662 | * |
| 663 | * @param eventSubjectGetterTempFileHandle event subject getter temp file |
| 664 | */ |
| 665 | public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) { |
| 666 | this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle; |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Returns event subject setter temp file. |
| 671 | * |
| 672 | * @return event subject setter temp file |
| 673 | */ |
| 674 | public File getEventSubjectSetterTempFileHandle() { |
| 675 | return eventSubjectSetterTempFileHandle; |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Sets event subject setter temp file. |
| 680 | * |
| 681 | * @param eventSubjectSetterTempFileHandle event subject setter temp file |
| 682 | */ |
| 683 | public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) { |
| 684 | this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Adds java snippet for events to event subject file. |
| 689 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 690 | * @param curNode current node |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 691 | * @param pluginConfig plugin configurations |
| 692 | * @throws IOException when fails to do IO operations |
| 693 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 694 | public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) |
| 695 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 696 | |
| 697 | String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(), |
| 698 | pluginConfig.getConflictResolver())); |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 699 | String notificationName = ((YangNotification) curNode).getName(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 700 | |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 701 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 702 | getCapitalCase(currentInfo)); |
| 703 | |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 704 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo), |
| 705 | null, false, false); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 706 | |
| 707 | /*Adds java info for event in respective temp files.*/ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 708 | addEventEnum(notificationName, pluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 709 | addEventSubjectAttribute(javaAttributeInfo, pluginConfig); |
| 710 | addEventSubjectGetter(javaAttributeInfo, pluginConfig); |
| 711 | addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo); |
| 712 | } |
| 713 | |
| 714 | /*Adds event to enum temp file.*/ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 715 | private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) |
| 716 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 717 | appendToFile(getEventEnumTempFileHandle(), |
| 718 | getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 719 | + getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /*Adds event method in event class*/ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 723 | private void addEnumMethod(String eventClassname, String className) |
| 724 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 725 | appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className)); |
| 726 | } |
| 727 | |
| 728 | /*Adds event method contents to event file.*/ |
| 729 | private static String getEventFileContents(String eventClassname, String classname) { |
| 730 | return "\n" + |
| 731 | " /**\n" + |
| 732 | " * Creates " + classname + " event with type and subject.\n" + |
| 733 | " *\n" + |
| 734 | " * @param type event type\n" + |
| 735 | " * @param subject subject " + classname + "\n" + |
| 736 | " */\n" + |
| 737 | " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" + |
| 738 | " super(type, subject);\n" + |
| 739 | " }\n" + |
| 740 | "\n" + |
| 741 | " /**\n" + |
| 742 | " * Creates " + classname + " event with type, subject and time.\n" + |
| 743 | " *\n" + |
| 744 | " * @param type event type\n" + |
| 745 | " * @param subject subject " + classname + "\n" + |
| 746 | " * @param time time of event\n" + |
| 747 | " */\n" + |
| 748 | " public " + eventClassname + "(Type type, " + getCapitalCase(classname) |
| 749 | + " subject, long time) {\n" + |
| 750 | " super(type, subject, time);\n" + |
| 751 | " }\n" + |
| 752 | "\n"; |
| 753 | } |
| 754 | |
| 755 | /*Adds events to event subject file.*/ |
| 756 | private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
| 757 | throws IOException { |
| 758 | appendToFile(getEventSubjectAttributeTempFileHandle(), |
| 759 | FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig)); |
| 760 | } |
| 761 | |
| 762 | /*Adds getter method for event in event subject class.*/ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 763 | private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
| 764 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 765 | appendToFile(getEventSubjectGetterTempFileHandle(), |
| 766 | getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
| 767 | + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE); |
| 768 | } |
| 769 | |
| 770 | /*Adds setter method for event in event subject class.*/ |
| 771 | private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className) |
| 772 | throws IOException { |
| 773 | appendToFile(getEventSubjectSetterTempFileHandle(), |
| 774 | getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
| 775 | + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE); |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Returns a temporary file handle for the event's file type. |
| 780 | * |
| 781 | * @param fileName file name |
| 782 | * @return temporary file handle |
| 783 | * @throws IOException when fails to create new file handle |
| 784 | */ |
| 785 | private File getJavaFileHandle(YangNode curNode, String name) |
| 786 | throws IOException { |
| 787 | |
| 788 | JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 789 | |
| 790 | return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION, |
| 791 | parentInfo); |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Returns the directory path. |
| 796 | * |
| 797 | * @return directory path |
| 798 | */ |
| 799 | private String getDirPath(JavaFileInfo parentInfo) { |
| 800 | return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase(); |
| 801 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 802 | } |