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.List; |
| 22 | |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
| 25 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
| 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAnnotationsImports; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile; |
| 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; |
| 38 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; |
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
| 44 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 50 | |
| 51 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 52 | * Represents implementation of java service code fragments temporary implementations. Maintains the temp files required |
| 53 | * specific for service and manager java snippet generation. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 54 | */ |
| 55 | public class TempJavaServiceFragmentFiles |
| 56 | extends TempJavaFragmentFiles { |
| 57 | |
| 58 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 59 | * File name for rpc method. |
| 60 | */ |
| 61 | private static final String RPC_INTERFACE_FILE_NAME = "Rpc"; |
| 62 | |
| 63 | /** |
| 64 | * File name for rpc implementation method. |
| 65 | */ |
| 66 | private static final String RPC_IMPL_FILE_NAME = "RpcImpl"; |
| 67 | |
| 68 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 69 | * File name for generated class file for service suffix. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 70 | */ |
| 71 | private static final String SERVICE_FILE_NAME_SUFFIX = "Service"; |
| 72 | |
| 73 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 74 | * File name for generated class file for manager suffix. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 75 | */ |
| 76 | private static final String MANAGER_FILE_NAME_SUFFIX = "Manager"; |
| 77 | |
| 78 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 79 | * Flag to set the manager files generation. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 80 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 81 | boolean isManagerNeedToBeGenerated = false; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 82 | |
| 83 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 84 | * Temporary file handle for rpc interface. |
| 85 | */ |
| 86 | private File rpcInterfaceTempFileHandle; |
| 87 | |
| 88 | /** |
| 89 | * Temporary file handle for rpc manager impl. |
| 90 | */ |
| 91 | private File rpcImplTempFileHandle; |
| 92 | |
| 93 | /** |
| 94 | * Java file handle for rpc interface file. |
| 95 | */ |
| 96 | private File serviceInterfaceJavaFileHandle; |
| 97 | |
| 98 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 99 | * Path for serive file to be generated. |
| 100 | */ |
| 101 | private String serviceGenPath; |
| 102 | |
| 103 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 104 | * Java file handle for manager impl file. |
| 105 | */ |
| 106 | private File managerJavaFileHandle; |
| 107 | |
| 108 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 109 | * Creates an instance of temporary java code fragment. |
| 110 | * |
| 111 | * @param javaFileInfo generated file information |
| 112 | * @throws IOException when fails to create new file handle |
| 113 | */ |
| 114 | public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo) |
| 115 | throws IOException { |
| 116 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
| 117 | setJavaImportData(new JavaImportData()); |
| 118 | setJavaFileInfo(javaFileInfo); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 119 | setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath()); |
| 120 | setServiceGenPath(getJavaFileInfo().getPluginConfig().getCodeGenDir()); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 121 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 122 | getJavaFileInfo().getPackageFilePath())); |
| 123 | addGeneratedTempFile(RPC_INTERFACE_MASK); |
| 124 | addGeneratedTempFile(RPC_IMPL_MASK); |
| 125 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 126 | setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME)); |
| 127 | setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME)); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 131 | * Returns rpc method's java file handle. |
| 132 | * |
| 133 | * @return java file handle |
| 134 | */ |
| 135 | private File getServiceInterfaceJavaFileHandle() { |
| 136 | return serviceInterfaceJavaFileHandle; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets rpc method's java file handle. |
| 141 | * |
| 142 | * @param serviceInterfaceJavaFileHandle file handle for to rpc method |
| 143 | */ |
| 144 | private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) { |
| 145 | this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Returns managers java file handle. |
| 150 | * |
| 151 | * @return java file handle |
| 152 | */ |
| 153 | public File getManagerJavaFileHandle() { |
| 154 | return managerJavaFileHandle; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Sets manager java file handle. |
| 159 | * |
| 160 | * @param managerJavaFileHandle file handle for to manager |
| 161 | */ |
| 162 | public void setManagerJavaFileHandle(File managerJavaFileHandle) { |
| 163 | this.managerJavaFileHandle = managerJavaFileHandle; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns rpc method's temporary file handle. |
| 168 | * |
| 169 | * @return temporary file handle |
| 170 | */ |
| 171 | public File getRpcInterfaceTempFileHandle() { |
| 172 | return rpcInterfaceTempFileHandle; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Sets rpc method's temporary file handle. |
| 177 | * |
| 178 | * @param rpcInterfaceTempFileHandle file handle for to rpc method |
| 179 | */ |
| 180 | private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) { |
| 181 | this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Retrieves the manager impl temp file. |
| 186 | * |
| 187 | * @return the manager impl temp file |
| 188 | */ |
| 189 | public File getRpcImplTempFileHandle() { |
| 190 | return rpcImplTempFileHandle; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Sets the manager impl temp file. |
| 195 | * |
| 196 | * @param rpcImplTempFileHandle the manager impl temp file |
| 197 | */ |
| 198 | public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) { |
| 199 | this.rpcImplTempFileHandle = rpcImplTempFileHandle; |
| 200 | } |
| 201 | |
| 202 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 203 | * Constructs java code exit. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 204 | * |
| 205 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 206 | * @param curNode current YANG node |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 207 | * @throws IOException when fails to generate java files |
| 208 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 209 | @Override |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 210 | public void generateJavaFile(int fileType, YangNode curNode) |
| 211 | throws IOException { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 212 | List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() |
| 213 | .getJavaImportData().getImports(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 214 | createPackage(curNode); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 215 | boolean isNotification = false; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 216 | if (curNode instanceof YangJavaModule) { |
| 217 | if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 218 | isNotification = true; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 219 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 220 | } else if (curNode instanceof YangJavaSubModule) { |
| 221 | if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) { |
| 222 | isNotification = true; |
| 223 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | if (isNotification) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 227 | addListenersImport(curNode, imports, true, LISTENER_SERVICE); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 228 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 229 | /** |
| 230 | * Creates rpc interface file. |
| 231 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 232 | setBaseCodePath(getServiceGenPath()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 233 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 234 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 235 | setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 236 | if (isNotification) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 237 | addListenersImport(curNode, imports, false, LISTENER_SERVICE); |
| 238 | addListenersImport(curNode, imports, true, LISTENER_REG); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 239 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 240 | addAnnotationsImports(imports, true); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 241 | /** |
| 242 | * Create builder class file. |
| 243 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 244 | if (isManagerNeedToBeGenerated()) { |
| 245 | setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX))); |
| 246 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode); |
| 247 | insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose()); |
| 248 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 249 | if (isNotification) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 250 | addListenersImport(curNode, imports, false, LISTENER_REG); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 251 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 252 | addAnnotationsImports(imports, false); |
| 253 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 254 | /** |
| 255 | * Close all the file handles. |
| 256 | */ |
| 257 | freeTemporaryResources(false); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Adds rpc string information to applicable temp file. |
| 262 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 263 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 264 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 265 | * @param rpcName name of the rpc function |
| 266 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 267 | * @throws IOException IO operation fail |
| 268 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 269 | private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 270 | JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
| 271 | String rpcName) |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 272 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 273 | String rpcInput = EMPTY_STRING; |
| 274 | String rpcOutput = VOID; |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 275 | String rpcInputJavaDoc = EMPTY_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 276 | if (javaAttributeInfoOfInput != null) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 277 | rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 278 | } |
| 279 | if (javaAttributeInfoOfOutput != null) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 280 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 281 | } |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 282 | if (!rpcInput.equals(EMPTY_STRING)) { |
| 283 | rpcInputJavaDoc = RPC_INPUT_VAR_NAME; |
| 284 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 285 | appendToFile(getRpcInterfaceTempFileHandle(), |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 286 | generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig) |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 287 | + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
| 288 | appendToFile(getRpcImplTempFileHandle(), |
| 289 | getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Adds the JAVA rpc snippet information. |
| 294 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 295 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 296 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 297 | * @param pluginConfig plugin configurations |
| 298 | * @param rpcName name of the rpc function |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 299 | * @throws IOException IO operation fail |
| 300 | */ |
| 301 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 302 | JavaAttributeInfo javaAttributeInfoOfOutput, |
| 303 | YangPluginConfig pluginConfig, String rpcName) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 304 | throws IOException { |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 305 | addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 309 | * Removes all temporary file handles. |
| 310 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 311 | * @param isErrorOccurred when translator fails to generate java files we need to close all open file handles |
| 312 | * include temporary files and java files. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 313 | * @throws IOException when failed to delete the temporary files |
| 314 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 315 | @Override |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 316 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 317 | throws IOException { |
| 318 | boolean isError = isErrorOccurred; |
| 319 | |
| 320 | closeFile(getServiceInterfaceJavaFileHandle(), isError); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 321 | closeFile(getManagerJavaFileHandle(), isError); |
| 322 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 323 | closeFile(getRpcInterfaceTempFileHandle(), true); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 324 | closeFile(getRpcImplTempFileHandle(), true); |
| 325 | closeFile(getGetterInterfaceTempFileHandle(), true); |
| 326 | closeFile(getSetterInterfaceTempFileHandle(), true); |
| 327 | closeFile(getSetterImplTempFileHandle(), true); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 328 | |
| 329 | super.freeTemporaryResources(isErrorOccurred); |
| 330 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 331 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 332 | |
| 333 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 334 | * Returns the path where service file should be generated. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 335 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 336 | * @return path where service file should be generated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 337 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 338 | public String getServiceGenPath() { |
| 339 | return serviceGenPath; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 343 | * Sets path where service file should be generated. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 344 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 345 | * @param serviceGenPath path where service file should be generated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 346 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 347 | public void setServiceGenPath(String serviceGenPath) { |
| 348 | this.serviceGenPath = serviceGenPath; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 352 | * Returns true if manager needs to be generated. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 353 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 354 | * @return true if manager needs to be generated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 355 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 356 | public boolean isManagerNeedToBeGenerated() { |
| 357 | return isManagerNeedToBeGenerated; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 361 | * Sets true if manager needs to be generated. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 362 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 363 | * @param managerNeedToBeGenerated true if manager needs to be generated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 364 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame^] | 365 | public void setManagerNeedToBeGenerated(boolean managerNeedToBeGenerated) { |
| 366 | isManagerNeedToBeGenerated = managerNeedToBeGenerated; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 367 | } |
| 368 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 369 | } |