Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +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.utils; |
| 18 | |
| 19 | import java.io.IOException; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangCase; |
| 23 | import org.onosproject.yangutils.datamodel.YangChoice; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 25 | import org.onosproject.yangutils.datamodel.YangNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 28 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 31 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
| 34 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 35 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
| 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
Vidyashree Rama | 5daea74 | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| 45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Represents utility class for YANG java model. |
| 49 | */ |
| 50 | public final class YangJavaModelUtils { |
| 51 | |
| 52 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 53 | * Creates an instance of YANG java model utility. |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 54 | */ |
| 55 | private YangJavaModelUtils() { |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Updates YANG java file package information. |
| 60 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 61 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 62 | * @param yangPluginConfig YANG plugin config |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 63 | * @throws IOException IO operations fails |
| 64 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 65 | public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 66 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 67 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 68 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 69 | javaCodeGeneratorInfo.getJavaFileInfo() |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 70 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), |
| 71 | yangPluginConfig.getConflictResolver())); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 72 | javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo)); |
| 73 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
| 74 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 75 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 76 | javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Updates YANG java file package information for specified package. |
| 81 | * |
| 82 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 83 | * @param yangPlugin YANG plugin config |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 84 | * @throws IOException IO operations fails |
| 85 | */ |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 86 | private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 87 | String pkg) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 88 | throws IOException { |
| 89 | javaCodeGeneratorInfo.getJavaFileInfo() |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 90 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), |
| 91 | yangPlugin.getConflictResolver())); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 92 | javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg); |
| 93 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
| 94 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 95 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 96 | javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Updates temporary java code fragment files. |
| 101 | * |
| 102 | * @param javaCodeGeneratorInfo YANG java file info node |
| 103 | * @throws IOException IO operations fails |
| 104 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 105 | private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo) |
| 106 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 107 | javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles( |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 108 | new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo())); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Updates leaf information in temporary java code fragment files. |
| 113 | * |
| 114 | * @param javaCodeGeneratorInfo YANG java file info node |
| 115 | * @throws IOException IO operations fails |
| 116 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 117 | private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 118 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 119 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 120 | if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 121 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 122 | * Module / sub module node code generation. |
| 123 | */ |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 124 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 125 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 126 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 127 | if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { |
| 128 | if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { |
| 129 | updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); |
| 130 | } |
| 131 | } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { |
| 132 | if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { |
| 133 | updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); |
| 134 | } |
| 135 | } |
| 136 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 137 | } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 138 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 139 | * Container |
| 140 | * Case |
| 141 | * Grouping |
| 142 | * Input |
| 143 | * List |
| 144 | * Notification |
| 145 | * Output |
| 146 | */ |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 147 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 148 | .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles( |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 149 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 150 | } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 151 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 152 | * Typedef |
| 153 | * Union |
| 154 | */ |
| 155 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 156 | .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 157 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 158 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 159 | * Enumeration |
| 160 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 161 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 162 | .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
| 163 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 164 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { |
| 165 | /*Do nothing, only the interface needs to be generated*/ |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 166 | } else { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 167 | throw new TranslatorException("Unsupported Node Translation"); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Process generate code entry of YANG node. |
| 173 | * |
| 174 | * @param javaCodeGeneratorInfo YANG java file info node |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 175 | * @throws IOException IO operations fails |
| 176 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 177 | private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 178 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 179 | throws IOException { |
| 180 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 181 | throw new TranslatorException("translation is not supported for the node"); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 182 | } |
| 183 | createTempFragmentFile(javaCodeGeneratorInfo); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 184 | updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 185 | |
| 186 | } |
| 187 | |
| 188 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 189 | * Updates notification node info in service temporary file. |
| 190 | * |
| 191 | * @param javaCodeGeneratorInfo java code generator info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 192 | * @param yangPluginConfig plugin configurations |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 193 | * @throws IOException when fails to do IO operations |
| 194 | */ |
| 195 | private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 196 | YangPluginConfig yangPluginConfig) |
| 197 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 198 | if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { |
| 199 | for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) { |
| 200 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
| 201 | .getServiceTempFiles() |
| 202 | .addJavaSnippetOfEvent(notificaiton, yangPluginConfig); |
| 203 | } |
| 204 | } |
| 205 | if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { |
| 206 | for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo) |
| 207 | .getNotificationNodes()) { |
| 208 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
| 209 | .getServiceTempFiles() |
| 210 | .addJavaSnippetOfEvent(notificaiton, yangPluginConfig); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 216 | * Generates code for the current ata model node and adds itself as an attribute in the parent. |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 217 | * |
| 218 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 219 | * @param yangPlugin YANG plugin config |
| 220 | * @param isMultiInstance flag to indicate whether it's a list |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 221 | * @throws IOException IO operations fails |
| 222 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 223 | public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 224 | YangPluginConfig yangPlugin, boolean isMultiInstance) |
| 225 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 226 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 227 | throw new TranslatorException("Invalid node for translation"); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 228 | } |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 229 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 230 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 231 | * Generate the Java files corresponding to the current node. |
| 232 | */ |
| 233 | generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin); |
| 234 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 235 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 236 | * Update the current nodes info in its parent nodes generated files. |
| 237 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 238 | addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 242 | * Generates code for the current data model node and adds support for it to be augmented. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 243 | * |
| 244 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 245 | * @param yangPlugin YANG plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 246 | * @throws IOException IO operations fails |
| 247 | */ |
| 248 | public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 249 | YangPluginConfig yangPlugin) |
| 250 | throws IOException { |
| 251 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
| 252 | throw new TranslatorException("invalid node for translation"); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 253 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 254 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 255 | generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin); |
| 256 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 257 | /* |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 258 | TODO: Need to use this, when augmentation is added in YMS |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 259 | * For augmentation of nodes. |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 260 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 261 | if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) { |
| 262 | JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo(); |
| 263 | augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER); |
| 264 | augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG); |
| 265 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() |
| 266 | .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo); |
| 267 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 268 | } else if (javaCodeGeneratorInfo instanceof YangAugment) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 269 | JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo(); |
| 270 | augmentedInfo.setClassInfo(AUGMENTED_INFO); |
| 271 | augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG); |
| 272 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() |
| 273 | .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo); |
| 274 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 275 | } |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 276 | */ |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 277 | if (javaCodeGeneratorInfo instanceof YangCase) { |
| 278 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 279 | JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo(); |
Vidyashree Rama | 5daea74 | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 280 | String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 281 | String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); |
| 282 | parentsInfo.setClassInfo(parentName); |
| 283 | parentsInfo.setPkgInfo(parentPkg); |
| 284 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() |
| 285 | .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo); |
| 286 | |
| 287 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 288 | .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 289 | |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 290 | } |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 294 | * Generates code for the current data model node. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 295 | * |
| 296 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 297 | * @param yangPluginConfig YANG plugin config |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 298 | * @throws IOException IO operations fails |
| 299 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 300 | public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 301 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 302 | throws IOException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 303 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
| 304 | // TODO:throw exception |
| 305 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 306 | updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig); |
| 307 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 311 | * Generates code for the root module/sub-module node. |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 312 | * |
| 313 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 314 | * @param yangPluginConfig YANG plugin config |
| 315 | * @param rootPkg package of the root node |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 316 | * @throws IOException IO operations fails |
| 317 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 318 | public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 319 | YangPluginConfig yangPluginConfig, String rootPkg) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 320 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 321 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
| 322 | // TODO:throw exception |
| 323 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 324 | updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg); |
| 325 | |
| 326 | if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) { |
| 327 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); |
| 328 | } |
| 329 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 330 | if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) { |
| 331 | if (!((YangJavaModule) javaCodeGeneratorInfo) |
| 332 | .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) { |
| 333 | updateCodeGenInfoForEvent(javaCodeGeneratorInfo); |
| 334 | } |
| 335 | } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) { |
| 336 | if (!((YangJavaSubModule) javaCodeGeneratorInfo) |
| 337 | .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) { |
| 338 | updateCodeGenInfoForEvent(javaCodeGeneratorInfo); |
| 339 | } |
| 340 | } |
| 341 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 342 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 343 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 344 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 345 | /*Updates java code generator info with events info.*/ |
| 346 | private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) { |
| 347 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS); |
| 348 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS); |
| 349 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE); |
| 350 | } |
| 351 | |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 352 | } |