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 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.translator.tojava; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 20 | import java.util.ArrayList; |
| 21 | import java.util.List; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 22 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangAugment; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangCase; |
| 27 | import org.onosproject.yangutils.datamodel.YangChoice; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 29 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangTranslatorOperatorNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.utils.DataModelUtils; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator; |
| 36 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator; |
| 37 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator; |
| 38 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.utils.io.YangPluginConfig; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 40 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent; |
| 42 | 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] | 43 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 47 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 48 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 49 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Represents utility class for YANG java model. |
| 54 | */ |
| 55 | public final class YangJavaModelUtils { |
| 56 | |
| 57 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 58 | * Creates an instance of YANG java model utility. |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 59 | */ |
| 60 | private YangJavaModelUtils() { |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Updates YANG java file package information. |
| 65 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 66 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 67 | * @param yangPluginConfig YANG plugin config |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 68 | * @throws IOException IO operations fails |
| 69 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 70 | public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 71 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 72 | throws IOException { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 73 | if (javaCodeGeneratorInfo instanceof YangJavaAugmentTranslator) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 74 | updatePackageForAugmentInfo(javaCodeGeneratorInfo, yangPluginConfig); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 75 | } else { |
| 76 | javaCodeGeneratorInfo.getJavaFileInfo() |
| 77 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 78 | yangPluginConfig.getConflictResolver())); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 79 | javaCodeGeneratorInfo.getJavaFileInfo().setJavaAttributeName(javaCodeGeneratorInfo |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 80 | .getJavaFileInfo().getJavaName()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 81 | javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo)); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 82 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 83 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
| 84 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
| 85 | |
| 86 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); |
| 87 | javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig); |
| 88 | |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Updates YANG java file package information. |
| 93 | * |
| 94 | * @param javaCodeGeneratorInfo YANG java file info node |
| 95 | * @param yangPluginConfig YANG plugin config |
| 96 | * @throws IOException IO operations fails |
| 97 | */ |
| 98 | private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 99 | YangPluginConfig yangPluginConfig) |
| 100 | throws IOException { |
| 101 | javaCodeGeneratorInfo.getJavaFileInfo() |
| 102 | .setJavaName(getAugmentClassName((YangJavaAugmentTranslator) javaCodeGeneratorInfo, |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 103 | yangPluginConfig)); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 104 | javaCodeGeneratorInfo.getJavaFileInfo().setPackage( |
| 105 | getAugmentsNodePackage((YangNode) javaCodeGeneratorInfo, yangPluginConfig)); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 106 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
| 107 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 108 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 109 | javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 113 | * Returns package for augment node. |
| 114 | * |
| 115 | * @param yangNode augment node |
| 116 | * @param yangPluginConfig plugin configurations |
| 117 | * @return package for augment node |
| 118 | */ |
| 119 | private static String getAugmentsNodePackage(YangNode yangNode, YangPluginConfig yangPluginConfig) { |
| 120 | YangAugment augment = (YangAugment) yangNode; |
| 121 | StringBuilder augmentPkg = new StringBuilder(); |
| 122 | augmentPkg.append(getCurNodePackage(augment)); |
| 123 | |
| 124 | String pkg = PERIOD; |
| 125 | for (YangAtomicPath atomicPath : augment.getTargetNode()) { |
| 126 | pkg = pkg + getCamelCase(atomicPath.getNodeIdentifier().getName(), yangPluginConfig.getConflictResolver()) |
| 127 | + PERIOD; |
| 128 | } |
| 129 | pkg = trimAtLast(pkg, PERIOD); |
| 130 | augmentPkg.append(pkg.toLowerCase()); |
| 131 | return augmentPkg.toString(); |
| 132 | } |
| 133 | |
| 134 | /** |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 135 | * Updates YANG java file package information for specified package. |
| 136 | * |
| 137 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 138 | * @param yangPlugin YANG plugin config |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 139 | * @throws IOException IO operations fails |
| 140 | */ |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 141 | private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 142 | String pkg) |
| 143 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 144 | javaCodeGeneratorInfo.getJavaFileInfo() |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 145 | .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 146 | yangPlugin.getConflictResolver())); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 147 | javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg); |
| 148 | javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( |
| 149 | getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 150 | javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 151 | javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Updates temporary java code fragment files. |
| 156 | * |
| 157 | * @param javaCodeGeneratorInfo YANG java file info node |
| 158 | * @throws IOException IO operations fails |
| 159 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 160 | private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo) |
| 161 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 162 | javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles( |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 163 | new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo())); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Updates leaf information in temporary java code fragment files. |
| 168 | * |
| 169 | * @param javaCodeGeneratorInfo YANG java file info node |
| 170 | * @throws IOException IO operations fails |
| 171 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 172 | private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 173 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 174 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 175 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 176 | if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) { |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 177 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().setRooNode(true); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 178 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 179 | * Module / sub module node code generation. |
| 180 | */ |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 181 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 182 | .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles( |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 183 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 184 | if (javaCodeGeneratorInfo instanceof YangJavaModuleTranslator) { |
| 185 | if (!((YangJavaModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { |
| 186 | updateNotificationNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 187 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 188 | } else if (javaCodeGeneratorInfo instanceof YangJavaSubModuleTranslator) { |
| 189 | if (!((YangJavaSubModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) { |
| 190 | updateNotificationNodeInfo(javaCodeGeneratorInfo, yangPluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 194 | } |
| 195 | if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 196 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 197 | * Container |
| 198 | * Case |
| 199 | * Grouping |
| 200 | * Input |
| 201 | * List |
| 202 | * Notification |
| 203 | * Output |
| 204 | */ |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 205 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 206 | .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles( |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 207 | (YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 208 | } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 209 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 210 | * Typedef |
| 211 | * Union |
| 212 | */ |
| 213 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 214 | .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 215 | } else if (javaCodeGeneratorInfo instanceof YangJavaEnumerationTranslator) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 216 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 217 | * Enumeration |
| 218 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 219 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 220 | .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig); |
| 221 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 222 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { |
| 223 | /*Do nothing, only the interface needs to be generated*/ |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 224 | } else { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 225 | throw new TranslatorException("Unsupported Node Translation " |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 226 | + javaCodeGeneratorInfo.getLineNumber() + " at " + |
| 227 | javaCodeGeneratorInfo.getCharPosition() |
| 228 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Process generate code entry of YANG node. |
| 234 | * |
| 235 | * @param javaCodeGeneratorInfo YANG java file info node |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 236 | * @param yangPluginConfig plugin configurations |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 237 | * @throws IOException IO operations fails |
| 238 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 239 | private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 240 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 241 | throws IOException { |
| 242 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 243 | throw new TranslatorException("translation is not supported for the node " |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 244 | + javaCodeGeneratorInfo.getLineNumber() + " at " + |
| 245 | javaCodeGeneratorInfo.getCharPosition() |
| 246 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 247 | } |
| 248 | createTempFragmentFile(javaCodeGeneratorInfo); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 249 | updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 250 | |
| 251 | } |
| 252 | |
| 253 | /** |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 254 | * Updates notification node info in service temporary file. |
| 255 | * |
| 256 | * @param javaCodeGeneratorInfo java code generator info |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 257 | * @param yangPluginConfig plugin configurations |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 258 | * @throws IOException when fails to do IO operations |
| 259 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 260 | private static void updateNotificationNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 261 | YangPluginConfig yangPluginConfig) |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 262 | throws IOException { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 263 | if (javaCodeGeneratorInfo instanceof YangJavaModuleTranslator) { |
| 264 | for (YangNode notification : ((YangJavaModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes()) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 265 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 266 | .getEventFragmentFiles() |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 267 | .addJavaSnippetOfEvent(notification, yangPluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 268 | } |
| 269 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 270 | if (javaCodeGeneratorInfo instanceof YangJavaSubModuleTranslator) { |
| 271 | for (YangNode notification : ((YangJavaSubModuleTranslator) javaCodeGeneratorInfo) |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 272 | .getNotificationNodes()) { |
| 273 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 274 | .getEventFragmentFiles() |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 275 | .addJavaSnippetOfEvent(notification, yangPluginConfig); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 281 | * 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] | 282 | * |
| 283 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 284 | * @param yangPlugin YANG plugin config |
| 285 | * @param isMultiInstance flag to indicate whether it's a list |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 286 | * @throws IOException IO operations fails |
| 287 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 288 | public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 289 | YangPluginConfig yangPlugin, boolean isMultiInstance) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 290 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 291 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 292 | throw new TranslatorException("Invalid node for translation " + |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 293 | javaCodeGeneratorInfo.getLineNumber() + " at " + |
| 294 | javaCodeGeneratorInfo.getCharPosition() |
| 295 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 296 | } |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 297 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 298 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 299 | * Generate the Java files corresponding to the current node. |
| 300 | */ |
| 301 | generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin); |
| 302 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 303 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 304 | * Update the current nodes info in its parent nodes generated files. |
| 305 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 306 | addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 310 | * 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] | 311 | * |
| 312 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 313 | * @param yangPlugin YANG plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 314 | * @throws IOException IO operations fails |
| 315 | */ |
| 316 | public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 317 | YangPluginConfig yangPlugin) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 318 | throws IOException { |
| 319 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 320 | throw new TranslatorException("invalid node for translation " + |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 321 | javaCodeGeneratorInfo.getLineNumber() + " at " + |
| 322 | javaCodeGeneratorInfo.getCharPosition() |
| 323 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 324 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 325 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 326 | generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 327 | TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 328 | |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 329 | if (javaCodeGeneratorInfo instanceof YangCase) { |
| 330 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 331 | JavaQualifiedTypeInfoTranslator parentsInfo = getQualifierInfoForCasesParent(parent, yangPlugin); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 332 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder() |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 333 | .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo, |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 334 | tempJavaCodeFragmentFiles.getBeanTempFiles()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 335 | |
| 336 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 337 | .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 338 | |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 339 | } |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 343 | * Returns cases parent's qualified info. |
| 344 | * |
| 345 | * @param parent parent node |
| 346 | * @param yangPluginConfig plugin configuration |
| 347 | * @return cases parent's qualified info |
| 348 | */ |
| 349 | public static JavaQualifiedTypeInfoTranslator getQualifierInfoForCasesParent(YangNode parent, |
| 350 | YangPluginConfig yangPluginConfig) { |
| 351 | String parentName; |
| 352 | String parentPkg; |
| 353 | JavaQualifiedTypeInfoTranslator parentsInfo = new JavaQualifiedTypeInfoTranslator(); |
| 354 | JavaFileInfoTranslator parentInfo; |
| 355 | if (parent instanceof YangChoice) { |
| 356 | parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo(); |
| 357 | } else { |
| 358 | parent = ((YangAugment) parent).getAugmentedNode(); |
| 359 | parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo(); |
| 360 | } |
| 361 | if (parentInfo.getPackage() != null) { |
| 362 | parentName = getCapitalCase(parentInfo.getJavaName()); |
| 363 | parentPkg = parentInfo.getPackage(); |
| 364 | } else { |
| 365 | parentName = getCapitalCase(getCamelCase(parent.getName(), yangPluginConfig.getConflictResolver())); |
| 366 | parentPkg = getNodesPackage(parent, yangPluginConfig); |
| 367 | } |
| 368 | parentsInfo.setClassInfo(parentName); |
| 369 | parentsInfo.setPkgInfo(parentPkg); |
| 370 | return parentsInfo; |
| 371 | |
| 372 | } |
| 373 | |
| 374 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 375 | * Generates code for the current data model node. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 376 | * |
| 377 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 378 | * @param yangPluginConfig YANG plugin config |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 379 | * @throws IOException IO operations fails |
| 380 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 381 | public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 382 | YangPluginConfig yangPluginConfig) |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 383 | throws IOException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 384 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 385 | throw new TranslatorException("invalid node for translation " |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 386 | + javaCodeGeneratorInfo.getLineNumber() + " at " + |
| 387 | javaCodeGeneratorInfo.getCharPosition() |
| 388 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 389 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 390 | updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig); |
| 391 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 395 | * Generates code for the root module/sub-module node. |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 396 | * |
| 397 | * @param javaCodeGeneratorInfo YANG java file info node |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 398 | * @param yangPluginConfig YANG plugin config |
| 399 | * @param rootPkg package of the root node |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 400 | * @throws IOException IO operations fails |
| 401 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 402 | public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 403 | YangPluginConfig yangPluginConfig, String rootPkg) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 404 | throws IOException { |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 405 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 406 | throw new TranslatorException("invalid node for translation " + javaCodeGeneratorInfo.getLineNumber() |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 407 | + " at " + |
| 408 | javaCodeGeneratorInfo.getCharPosition() |
| 409 | + " in " + javaCodeGeneratorInfo.getFileName()); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 410 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 411 | updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg); |
| 412 | |
| 413 | if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) { |
| 414 | javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER); |
| 415 | } |
| 416 | |
| 417 | generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig); |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 418 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 419 | |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 420 | /** |
| 421 | * Returns the node package string. |
| 422 | * |
| 423 | * @param curNode current java node whose package string needs to be set |
| 424 | * @return returns the root package string |
| 425 | */ |
| 426 | public static String getCurNodePackage(YangNode curNode) { |
| 427 | |
| 428 | String pkg; |
| 429 | if (!(curNode instanceof JavaFileInfoContainer) |
| 430 | || curNode.getParent() == null) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 431 | throw new TranslatorException("missing parent node to get current node's package " + |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 432 | curNode.getName() + " in " + |
| 433 | curNode.getLineNumber() + " at " + |
| 434 | curNode.getCharPosition() |
| 435 | + " in " + curNode.getFileName()); |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode); |
| 439 | if (!(parentNode instanceof JavaFileInfoContainer)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 440 | throw new TranslatorException("missing parent java node to get current node's package " + |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 441 | curNode.getName() + " in " + |
| 442 | curNode.getLineNumber() + " at " + |
| 443 | curNode.getCharPosition() |
| 444 | + " in " + curNode.getFileName()); |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 445 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 446 | JavaFileInfoTranslator parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo(); |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 447 | pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName(); |
| 448 | return pkg.toLowerCase(); |
| 449 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * Returns true if root node contains any data node. |
| 453 | * |
| 454 | * @param node root YANG node |
| 455 | * @return true if root node contains any data node |
| 456 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 457 | public static boolean isRootNodesCodeGenRequired(YangNode node) { |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 458 | YangLeavesHolder holder = (YangLeavesHolder) node; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 459 | |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 460 | if (holder.getListOfLeaf().isEmpty()) { |
| 461 | if (holder.getListOfLeafList().isEmpty()) { |
| 462 | YangNode tempNode = node.getChild(); |
| 463 | if (tempNode == null) { |
| 464 | return false; |
| 465 | } |
| 466 | while (tempNode != null) { |
| 467 | if (!(tempNode instanceof YangTranslatorOperatorNode)) { |
| 468 | return true; |
| 469 | } |
| 470 | tempNode = tempNode.getNextSibling(); |
| 471 | } |
| 472 | return false; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 473 | } else { |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 474 | return true; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 475 | } |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 476 | } else { |
| 477 | return true; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 478 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /** |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 482 | * Returns true if get/set method of root node are required. |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 483 | * |
| 484 | * @param curNode root node |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 485 | * @return true if get/set method of root node are required |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 486 | */ |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 487 | public static boolean isGetSetOfRootNodeRequired(YangNode curNode) { |
| 488 | YangLeavesHolder holder = (YangLeavesHolder) curNode; |
| 489 | |
| 490 | if (holder.getListOfLeaf().isEmpty()) { |
| 491 | if (holder.getListOfLeafList().isEmpty()) { |
| 492 | curNode = curNode.getChild(); |
| 493 | if (curNode == null) { |
| 494 | return false; |
| 495 | } |
| 496 | while (curNode != null) { |
| 497 | if (!(curNode instanceof YangAugment)) { |
| 498 | return true; |
| 499 | } |
| 500 | curNode = curNode.getNextSibling(); |
| 501 | } |
| 502 | return false; |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 503 | } else { |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 504 | return true; |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 505 | } |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 506 | } else { |
| 507 | return true; |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 508 | } |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 512 | * Returns nodes package. |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 513 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 514 | * @param node YANG node |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 515 | * @param yangPluginConfig plugin config |
| 516 | * @return java package |
| 517 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 518 | public static String getNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 519 | |
| 520 | List<String> clsInfo = new ArrayList<>(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 521 | while (node.getParent() != null) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 522 | if (node instanceof YangJavaAugmentTranslator) { |
| 523 | clsInfo.add(getAugmentClassName((YangAugment) node, yangPluginConfig)); |
| 524 | } else { |
| 525 | clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver())); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 526 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 527 | node = node.getParent(); |
| 528 | } |
| 529 | |
| 530 | StringBuilder pkg = new StringBuilder(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 531 | if (node instanceof YangJavaModuleTranslator) { |
| 532 | YangJavaModuleTranslator module = (YangJavaModuleTranslator) node; |
Gaurav Agrawal | e5057f0 | 2016-08-22 17:14:33 +0530 | [diff] [blame] | 533 | pkg.append(getRootPackage(module.getVersion(), module.getNameSpace(), module |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 534 | .getRevision(), yangPluginConfig.getConflictResolver())); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 535 | } else if (node instanceof YangJavaSubModuleTranslator) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 536 | YangJavaSubModuleTranslator subModule = (YangJavaSubModuleTranslator) node; |
| 537 | pkg.append(getRootPackage(subModule.getVersion(), |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 538 | subModule.getNameSpaceFromModule(), |
| 539 | subModule.getRevision(), yangPluginConfig.getConflictResolver())); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 540 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 541 | String concat = ""; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 542 | for (int i = 1; i <= clsInfo.size(); i++) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 543 | concat = concat + "." + clsInfo.get(clsInfo.size() - i); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 544 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 545 | pkg.append(concat); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 546 | return pkg.toString().toLowerCase(); |
| 547 | |
| 548 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 549 | |
| 550 | /** |
| 551 | * Returns augment class name. |
| 552 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 553 | * @param augment YANG augment |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 554 | * @param yangPluginConfig plugin configurations |
| 555 | * @return augment class name |
| 556 | */ |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 557 | private static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 558 | YangNodeIdentifier yangNodeIdentifier = augment.getTargetNode().get(augment.getTargetNode().size() - 1) |
| 559 | .getNodeIdentifier(); |
| 560 | String name = getCapitalCase(getCamelCase(yangNodeIdentifier.getName(), yangPluginConfig |
| 561 | .getConflictResolver())); |
| 562 | if (yangNodeIdentifier.getPrefix() != null) { |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 563 | return AUGMENTED + getCapitalCase(getCamelCase(yangNodeIdentifier.getPrefix(), yangPluginConfig |
| 564 | .getConflictResolver())) + name; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 565 | } else { |
| 566 | return AUGMENTED + name; |
| 567 | } |
| 568 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 569 | |
Gaurav Agrawal | 2639004 | 2016-04-12 13:30:16 +0530 | [diff] [blame] | 570 | } |