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