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