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