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