blob: 7bea5cdb524bb13c753e2ff65a987025de802df9 [file] [log] [blame]
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +05301/*
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
17package org.onosproject.yangutils.translator.tojava.utils;
18
19import java.io.IOException;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053020
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053021import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053022import org.onosproject.yangutils.datamodel.YangAugment;
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053023import org.onosproject.yangutils.datamodel.YangAugmentationHolder;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053024import org.onosproject.yangutils.datamodel.YangCase;
25import org.onosproject.yangutils.datamodel.YangChoice;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053026import org.onosproject.yangutils.datamodel.YangLeavesHolder;
27import org.onosproject.yangutils.datamodel.YangNode;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053028import org.onosproject.yangutils.datamodel.YangTypeHolder;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053029import org.onosproject.yangutils.translator.exception.TranslatorException;
30import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053031import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053032import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
33import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
Bharat saraswald72411a2016-04-19 01:00:16 +053034import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
Bharat saraswal33dfa012016-05-17 19:59:16 +053035import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
36import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053037
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053038import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
Bharat saraswal33dfa012016-05-17 19:59:16 +053039import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
40import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
41import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053042import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053043import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053044import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053045import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
46import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053047import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053048import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053049import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053050
51/**
52 * Represents utility class for YANG java model.
53 */
54public final class YangJavaModelUtils {
55
56 /**
Bharat saraswal33dfa012016-05-17 19:59:16 +053057 * Creates an instance of YANG java model utility.
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053058 */
59 private YangJavaModelUtils() {
60 }
61
62 /**
63 * Updates YANG java file package information.
64 *
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053065 * @param javaCodeGeneratorInfo YANG java file info node
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053066 * @param yangPluginConfig YANG plugin config
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053067 * @throws IOException IO operations fails
68 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053069 public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
70 YangPluginConfig yangPluginConfig)
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053071 throws IOException {
Bharat saraswal33dfa012016-05-17 19:59:16 +053072
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053073 javaCodeGeneratorInfo.getJavaFileInfo()
janani b4a6711a2016-05-17 13:12:22 +053074 .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
75 yangPluginConfig.getConflictResolver()));
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053076 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
77 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
78 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053079 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
Bharat saraswal33dfa012016-05-17 19:59:16 +053080 javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053081 }
82
83 /**
84 * Updates YANG java file package information for specified package.
85 *
86 * @param javaCodeGeneratorInfo YANG java file info node
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053087 * @param yangPlugin YANG plugin config
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053088 * @throws IOException IO operations fails
89 */
janani bde4ffab2016-04-15 16:18:30 +053090 private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053091 String pkg)
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053092 throws IOException {
93 javaCodeGeneratorInfo.getJavaFileInfo()
janani b4a6711a2016-05-17 13:12:22 +053094 .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
95 yangPlugin.getConflictResolver()));
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +053096 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
97 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
98 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
janani bde4ffab2016-04-15 16:18:30 +053099 javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
Bharat saraswal33dfa012016-05-17 19:59:16 +0530100 javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530101 }
102
103 /**
104 * Updates temporary java code fragment files.
105 *
106 * @param javaCodeGeneratorInfo YANG java file info node
107 * @throws IOException IO operations fails
108 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530109 private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
110 throws IOException {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530111 javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles(
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530112 new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo()));
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530113 }
114
115 /**
116 * Updates leaf information in temporary java code fragment files.
117 *
118 * @param javaCodeGeneratorInfo YANG java file info node
119 * @throws IOException IO operations fails
120 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530121 private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
122 YangPluginConfig yangPluginConfig)
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530123 throws IOException {
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530124 if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530125 /*
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530126 * Module / sub module node code generation.
127 */
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530128 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530129 .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530130 (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
Bharat saraswal33dfa012016-05-17 19:59:16 +0530131 if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
132 if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
133 updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
134 }
135 } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
136 if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
137 updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
138 }
139 }
140
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530141 } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530142 /*
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530143 * Container
144 * Case
145 * Grouping
146 * Input
147 * List
148 * Notification
149 * Output
150 */
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530151 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530152 .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530153 (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530154 } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530155 /*
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530156 * Typedef
157 * Union
158 */
159 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
Bharat saraswal33dfa012016-05-17 19:59:16 +0530160 .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
Bharat saraswald72411a2016-04-19 01:00:16 +0530161 } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530162 /*
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530163 * Enumeration
164 */
Bharat saraswalc0e04842016-05-12 13:16:57 +0530165 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
Bharat saraswal33dfa012016-05-17 19:59:16 +0530166 .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
167
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530168 } else if (javaCodeGeneratorInfo instanceof YangChoice) {
169 /*Do nothing, only the interface needs to be generated*/
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530170 } else {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530171 throw new TranslatorException("Unsupported Node Translation");
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530172 }
173 }
174
175 /**
176 * Process generate code entry of YANG node.
177 *
178 * @param javaCodeGeneratorInfo YANG java file info node
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530179 * @throws IOException IO operations fails
180 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530181 private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
182 YangPluginConfig yangPluginConfig)
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530183 throws IOException {
184 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530185 throw new TranslatorException("translation is not supported for the node");
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530186 }
187 createTempFragmentFile(javaCodeGeneratorInfo);
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530188 updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530189
190 }
191
192 /**
Bharat saraswal33dfa012016-05-17 19:59:16 +0530193 * Updates notification node info in service temporary file.
194 *
195 * @param javaCodeGeneratorInfo java code generator info
196 * @param yangPluginConfig plugin configurations
197 * @throws IOException when fails to do IO operations
198 */
199 private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
200 YangPluginConfig yangPluginConfig) throws IOException {
201 if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
202 for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
203 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
204 .getServiceTempFiles()
205 .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
206 }
207 }
208 if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
209 for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
210 .getNotificationNodes()) {
211 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
212 .getServiceTempFiles()
213 .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
214 }
215 }
216 }
217
218 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530219 * Generates code for the current ata model node and adds itself as an attribute in the parent.
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530220 *
221 * @param javaCodeGeneratorInfo YANG java file info node
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530222 * @param yangPlugin YANG plugin config
223 * @param isMultiInstance flag to indicate whether it's a list
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530224 * @throws IOException IO operations fails
225 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530226 public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
227 YangPluginConfig yangPlugin, boolean isMultiInstance)
228 throws IOException {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530229 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530230 throw new TranslatorException("Invalid node for translation");
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530231 }
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530232
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530233 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530234 * Generate the Java files corresponding to the current node.
235 */
236 generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin);
237
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530238 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530239 * Update the current nodes info in its parent nodes generated files.
240 */
Bharat saraswal33dfa012016-05-17 19:59:16 +0530241 addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530242 }
243
244 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530245 * Generates code for the current data model node and adds support for it to be augmented.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530246 *
247 * @param javaCodeGeneratorInfo YANG java file info node
248 * @param yangPlugin YANG plugin config
249 * @throws IOException IO operations fails
250 */
251 public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
252 YangPluginConfig yangPlugin)
253 throws IOException {
254 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
255 throw new TranslatorException("invalid node for translation");
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530256 }
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530257
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530258 generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
259
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530260 /*
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530261 * For augmentation of nodes.
262 */
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530263 if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
264 JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
265 augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
266 augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
267 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
268 .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo);
269
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530270 } else if (javaCodeGeneratorInfo instanceof YangAugment) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530271 JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo();
272 augmentedInfo.setClassInfo(AUGMENTED_INFO);
273 augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
274 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
275 .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
276
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530277 }
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530278
279 if (javaCodeGeneratorInfo instanceof YangCase) {
280 YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530281 JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
282 String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
283 String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
284 parentsInfo.setClassInfo(parentName);
285 parentsInfo.setPkgInfo(parentPkg);
286 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
287 .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
288
289 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
Bharat saraswal33dfa012016-05-17 19:59:16 +0530290 .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530291
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530292 }
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530293 }
294
295 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530296 * Generates code for the current data model node.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530297 *
298 * @param javaCodeGeneratorInfo YANG java file info node
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530299 * @param yangPluginConfig YANG plugin config
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530300 * @throws IOException IO operations fails
301 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530302 public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
303 YangPluginConfig yangPluginConfig)
Gaurav Agrawal56527662016-04-20 15:49:17 +0530304 throws IOException {
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530305 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
306 // TODO:throw exception
307 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530308 updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
309 generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530310 }
311
312 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530313 * Generates code for the root module/sub-module node.
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530314 *
315 * @param javaCodeGeneratorInfo YANG java file info node
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530316 * @param yangPluginConfig YANG plugin config
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530317 * @param rootPkg package of the root node
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530318 * @throws IOException IO operations fails
319 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530320 public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
321 YangPluginConfig yangPluginConfig, String rootPkg)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530322 throws IOException {
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530323 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
324 // TODO:throw exception
325 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530326 updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
327
328 if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
329 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
330 }
331
Bharat saraswal33dfa012016-05-17 19:59:16 +0530332 if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
333 if (!((YangJavaModule) javaCodeGeneratorInfo)
334 .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
335 updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
336 }
337 } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
338 if (!((YangJavaSubModule) javaCodeGeneratorInfo)
339 .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
340 updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
341 }
342 }
343
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530344 generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530345 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530346
Bharat saraswal33dfa012016-05-17 19:59:16 +0530347 /*Updates java code generator info with events info.*/
348 private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) {
349 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS);
350 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS);
351 javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
352 }
353
Gaurav Agrawal1c8f80c2016-04-12 13:30:16 +0530354}