Shankara-Huawei
Committed by Gerrit Code Review

[ONOS-4831] Implement op param class for apps

Change-Id: I88aee8a3009de84649c959e21ce83e3bbbf63c18
Showing 16 changed files with 1097 additions and 46 deletions
...@@ -150,6 +150,12 @@ public class YangUtilManager ...@@ -150,6 +150,12 @@ public class YangUtilManager
150 @Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}") 150 @Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
151 private List<ArtifactRepository> remoteRepository; 151 private List<ArtifactRepository> remoteRepository;
152 152
153 + /**
154 + * Code generation is for nbi or sbi.
155 + */
156 + @Parameter(property = "generateJavaFileForsbi", defaultValue = "nbi")
157 + private String generateJavaFileForsbi;
158 +
153 @Override 159 @Override
154 public void execute() 160 public void execute()
155 throws MojoExecutionException, MojoFailureException { 161 throws MojoExecutionException, MojoFailureException {
...@@ -177,6 +183,7 @@ public class YangUtilManager ...@@ -177,6 +183,7 @@ public class YangUtilManager
177 yangPlugin.setManagerCodeGenDir(managerCodeGenDir); 183 yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
178 yangPlugin.setConflictResolver(conflictResolver); 184 yangPlugin.setConflictResolver(conflictResolver);
179 185
186 + yangPlugin.setCodeGenerateForsbi(generateJavaFileForsbi.toLowerCase());
180 /* 187 /*
181 * Obtain the YANG files at a path mentioned in plugin and creates 188 * Obtain the YANG files at a path mentioned in plugin and creates
182 * YANG file information set. 189 * YANG file information set.
......
...@@ -44,8 +44,7 @@ public final class GeneratedJavaFileType { ...@@ -44,8 +44,7 @@ public final class GeneratedJavaFileType {
44 /** 44 /**
45 * Interface and class file. 45 * Interface and class file.
46 */ 46 */
47 - public static final int GENERATE_INTERFACE_WITH_BUILDER = INTERFACE_MASK 47 + public static final int GENERATE_INTERFACE_WITH_BUILDER = 8207;
48 - | BUILDER_INTERFACE_MASK | BUILDER_CLASS_MASK | IMPL_CLASS_MASK;
49 48
50 /** 49 /**
51 * Java interface corresponding to rpc. 50 * Java interface corresponding to rpc.
...@@ -94,6 +93,16 @@ public final class GeneratedJavaFileType { ...@@ -94,6 +93,16 @@ public final class GeneratedJavaFileType {
94 public static final int GENERATE_IDENTITY_CLASS = 2048; 93 public static final int GENERATE_IDENTITY_CLASS = 2048;
95 94
96 /** 95 /**
96 + * Operation class file.
97 + */
98 + public static final int OPERATION_CLASS_MASK = 4096;
99 +
100 + /**
101 + * Operation class builder file.
102 + */
103 + public static final int OPERATION_BUILDER_CLASS_MASK = 8192;
104 +
105 + /**
97 * Creates an instance of generate java file type. 106 * Creates an instance of generate java file type.
98 */ 107 */
99 private GeneratedJavaFileType() { 108 private GeneratedJavaFileType() {
......
...@@ -32,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP; ...@@ -32,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
32 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; 32 import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
33 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; 33 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
34 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; 34 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
35 +import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
35 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; 36 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
36 import static org.onosproject.yangutils.utils.UtilConstants.LIST; 37 import static org.onosproject.yangutils.utils.UtilConstants.LIST;
37 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG; 38 import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
...@@ -209,6 +210,15 @@ public class JavaImportData { ...@@ -209,6 +210,15 @@ public class JavaImportData {
209 } 210 }
210 211
211 /** 212 /**
213 + * Returns import for to bitset method.
214 + *
215 + * @return import for to bitset method
216 + */
217 + public String getImportForToBitSet() {
218 + return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + BITSET + SEMI_COLAN + NEW_LINE;
219 + }
220 +
221 + /**
212 * Returns import for list attribute. 222 * Returns import for list attribute.
213 * 223 *
214 * @return import for list attribute 224 * @return import for list attribute
......
...@@ -47,6 +47,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -47,6 +47,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
47 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
49 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
50 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK; 52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 53 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
...@@ -69,6 +70,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato ...@@ -69,6 +70,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
69 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; 70 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
70 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; 71 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
71 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports; 72 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
73 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamBuilderClassFile;
74 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamImplClassFile;
72 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; 75 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
73 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; 76 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
74 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor; 77 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor;
...@@ -102,6 +105,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT ...@@ -102,6 +105,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT
102 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 105 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
103 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; 106 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
104 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 107 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
108 +import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
109 +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
110 +import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
105 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; 111 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
106 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; 112 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
107 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 113 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
...@@ -246,11 +252,39 @@ public class TempJavaFragmentFiles { ...@@ -246,11 +252,39 @@ public class TempJavaFragmentFiles {
246 private File builderClassJavaFileHandle; 252 private File builderClassJavaFileHandle;
247 253
248 /** 254 /**
255 + * Retrieves the temporary file handle of op param builder class.
256 + *
257 + * @return op param builder temporary file handle
258 + */
259 + public File getBuilderOpParmClassJavaFileHandle() {
260 + return builderOpParmClassJavaFileHandle;
261 + }
262 +
263 + /**
264 + * Sets the java file handle for op param builder class.
265 + *
266 + * @param builderOpParmClassJavaFileHandle java file handle
267 + */
268 + public void setBuilderOpParmClassJavaFileHandle(File builderOpParmClassJavaFileHandle) {
269 + this.builderOpParmClassJavaFileHandle = builderOpParmClassJavaFileHandle;
270 + }
271 +
272 + /**
273 + * Java file handle for builder op param class file.
274 + */
275 + private File builderOpParmClassJavaFileHandle;
276 +
277 + /**
249 * Java file handle for impl class file. 278 * Java file handle for impl class file.
250 */ 279 */
251 private File implClassJavaFileHandle; 280 private File implClassJavaFileHandle;
252 281
253 /** 282 /**
283 + * Java file handle for op param class file.
284 + */
285 + private File opParamClassJavaFileHandle;
286 +
287 + /**
254 * Temporary file handle for attribute. 288 * Temporary file handle for attribute.
255 */ 289 */
256 private File attributesTempFileHandle; 290 private File attributesTempFileHandle;
...@@ -1192,13 +1226,17 @@ public class TempJavaFragmentFiles { ...@@ -1192,13 +1226,17 @@ public class TempJavaFragmentFiles {
1192 * TODO: check if this utility needs to be called or move to the caller 1226 * TODO: check if this utility needs to be called or move to the caller
1193 */ 1227 */
1194 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver()); 1228 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
1229 + String attributeAccessType = PRIVATE;
1230 + if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
1231 + attributeAccessType = PROTECTED;
1232 + }
1195 if (attr.isQualifiedName()) { 1233 if (attr.isQualifiedName()) {
1196 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), 1234 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
1197 attr.getImportInfo().getClassInfo(), 1235 attr.getImportInfo().getClassInfo(),
1198 - attributeName, attr.isListAttr()); 1236 + attributeName, attr.isListAttr(), attributeAccessType);
1199 } else { 1237 } else {
1200 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName, 1238 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
1201 - attr.isListAttr()); 1239 + attr.isListAttr(), attributeAccessType);
1202 } 1240 }
1203 } 1241 }
1204 1242
...@@ -1260,7 +1298,7 @@ public class TempJavaFragmentFiles { ...@@ -1260,7 +1298,7 @@ public class TempJavaFragmentFiles {
1260 if (!(leaf instanceof JavaLeafInfoContainer)) { 1298 if (!(leaf instanceof JavaLeafInfoContainer)) {
1261 throw new TranslatorException("Leaf does not have java information"); 1299 throw new TranslatorException("Leaf does not have java information");
1262 } 1300 }
1263 - addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(leaf, yangPluginConfig), 1301 + addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
1264 yangPluginConfig); 1302 yangPluginConfig);
1265 } 1303 }
1266 } 1304 }
...@@ -1269,12 +1307,13 @@ public class TempJavaFragmentFiles { ...@@ -1269,12 +1307,13 @@ public class TempJavaFragmentFiles {
1269 /** 1307 /**
1270 * Returns java attribute for leaf. 1308 * Returns java attribute for leaf.
1271 * 1309 *
1310 + * @param tempJavaFragmentFiles temporary generated file
1272 * @param leaf YANG leaf 1311 * @param leaf YANG leaf
1273 * @param yangPluginConfig plugin configurations 1312 * @param yangPluginConfig plugin configurations
1274 * @return java attribute for leaf 1313 * @return java attribute for leaf
1275 */ 1314 */
1276 - private JavaAttributeInfo getJavaAttributeOfLeaf(YangLeaf leaf, 1315 + public static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
1277 - YangPluginConfig yangPluginConfig) { 1316 + YangPluginConfig yangPluginConfig) {
1278 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; 1317 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
1279 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); 1318 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1280 javaLeaf.updateJavaQualifiedInfo(); 1319 javaLeaf.updateJavaQualifiedInfo();
...@@ -1282,7 +1321,7 @@ public class TempJavaFragmentFiles { ...@@ -1282,7 +1321,7 @@ public class TempJavaFragmentFiles {
1282 javaLeaf.getJavaQualifiedInfo(), 1321 javaLeaf.getJavaQualifiedInfo(),
1283 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), 1322 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1284 javaLeaf.getDataType(), 1323 javaLeaf.getDataType(),
1285 - getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), 1324 + tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1286 false); 1325 false);
1287 } 1326 }
1288 1327
...@@ -1300,7 +1339,7 @@ public class TempJavaFragmentFiles { ...@@ -1300,7 +1339,7 @@ public class TempJavaFragmentFiles {
1300 if (!(leafList instanceof JavaLeafInfoContainer)) { 1339 if (!(leafList instanceof JavaLeafInfoContainer)) {
1301 throw new TranslatorException("Leaf-list does not have java information"); 1340 throw new TranslatorException("Leaf-list does not have java information");
1302 } 1341 }
1303 - addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(leafList, yangPluginConfig), 1342 + addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this, leafList, yangPluginConfig),
1304 yangPluginConfig); 1343 yangPluginConfig);
1305 } 1344 }
1306 } 1345 }
...@@ -1309,25 +1348,28 @@ public class TempJavaFragmentFiles { ...@@ -1309,25 +1348,28 @@ public class TempJavaFragmentFiles {
1309 /** 1348 /**
1310 * Returns java attribute for leaf-list. 1349 * Returns java attribute for leaf-list.
1311 * 1350 *
1351 + * @param tempJavaFragmentFiles temporary generated file
1312 * @param leafList YANG leaf-list 1352 * @param leafList YANG leaf-list
1313 * @param yangPluginConfig plugin configurations 1353 * @param yangPluginConfig plugin configurations
1314 * @return java attribute for leaf-list 1354 * @return java attribute for leaf-list
1315 */ 1355 */
1316 - private JavaAttributeInfo getJavaAttributeOfLeafList(YangLeafList leafList, YangPluginConfig yangPluginConfig) { 1356 + public static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
1357 + YangLeafList leafList, YangPluginConfig yangPluginConfig) {
1317 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; 1358 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
1318 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); 1359 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1319 javaLeaf.updateJavaQualifiedInfo(); 1360 javaLeaf.updateJavaQualifiedInfo();
1320 - getJavaImportData().setIfListImported(true); 1361 + tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
1321 return getAttributeInfoForTheData( 1362 return getAttributeInfoForTheData(
1322 javaLeaf.getJavaQualifiedInfo(), 1363 javaLeaf.getJavaQualifiedInfo(),
1323 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), 1364 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1324 javaLeaf.getDataType(), 1365 javaLeaf.getDataType(),
1325 - getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), 1366 + tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1326 true); 1367 true);
1327 } 1368 }
1328 1369
1329 /** 1370 /**
1330 - * Adds all the leaves in the current data model node as part of the generated temporary file. 1371 + * Adds all the leaves in the current data model node as part of the
1372 + * generated temporary file.
1331 * 1373 *
1332 * @param curNode java file info of the generated file 1374 * @param curNode java file info of the generated file
1333 * @param yangPluginConfig plugin config 1375 * @param yangPluginConfig plugin config
...@@ -1419,6 +1461,24 @@ public class TempJavaFragmentFiles { ...@@ -1419,6 +1461,24 @@ public class TempJavaFragmentFiles {
1419 } 1461 }
1420 1462
1421 /** 1463 /**
1464 + * Returns op param java class name.
1465 + *
1466 + * @return op param java class name
1467 + */
1468 + String getOpParamImplClassName() {
1469 + return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION;
1470 + }
1471 +
1472 + /**
1473 + * Returns op param builder java class name.
1474 + *
1475 + * @return op param builder java class name
1476 + */
1477 + String getOpParamBuilderImplClassName() {
1478 + return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION + BUILDER;
1479 + }
1480 +
1481 + /**
1422 * Returns the directory path. 1482 * Returns the directory path.
1423 * 1483 *
1424 * @return directory path 1484 * @return directory path
...@@ -1494,7 +1554,7 @@ public class TempJavaFragmentFiles { ...@@ -1494,7 +1554,7 @@ public class TempJavaFragmentFiles {
1494 } 1554 }
1495 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) { 1555 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
1496 if (isAttributePresent()) { 1556 if (isAttributePresent()) {
1497 - addImportsToStringAndHasCodeMethods(imports); 1557 + addImportsToStringAndHasCodeMethods(imports, true);
1498 } 1558 }
1499 if (curNode instanceof YangAugmentableNode) { 1559 if (curNode instanceof YangAugmentableNode) {
1500 addImportsForAugmentableClass(imports); 1560 addImportsForAugmentableClass(imports);
...@@ -1522,6 +1582,39 @@ public class TempJavaFragmentFiles { ...@@ -1522,6 +1582,39 @@ public class TempJavaFragmentFiles {
1522 validateLineLength(getImplClassJavaFileHandle()); 1582 validateLineLength(getImplClassJavaFileHandle());
1523 } 1583 }
1524 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose()); 1584 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
1585 +
1586 + if (!(curNode instanceof YangModule)) {
1587 + if (isAttributePresent()) {
1588 + addImportsToStringAndHasCodeMethods(imports, false);
1589 + }
1590 + addBitsetImport(imports, true);
1591 + /*
1592 + * Create impl class file.
1593 + */
1594 + setOpParamClassJavaFileHandle(getJavaFileHandle(getOpParamImplClassName()));
1595 + setOpParamClassJavaFileHandle(
1596 + generateOpParamImplClassFile(getOpParamClassJavaFileHandle(), curNode,
1597 + isAttributePresent(), imports));
1598 +
1599 + /*
1600 + * Create builder class file.
1601 + */
1602 + if ((fileType & BUILDER_CLASS_MASK) != 0) {
1603 + setBuilderOpParmClassJavaFileHandle(getJavaFileHandle(getOpParamBuilderImplClassName()));
1604 + setBuilderOpParmClassJavaFileHandle(
1605 + generateOpParamBuilderClassFile(getBuilderOpParmClassJavaFileHandle(), curNode,
1606 + isAttributePresent()));
1607 + /*
1608 + * Append impl class to builder class and close it.
1609 + */
1610 + mergeJavaFiles(getBuilderOpParmClassJavaFileHandle(), getOpParamClassJavaFileHandle());
1611 + validateLineLength(getOpParamClassJavaFileHandle());
1612 +
1613 + addBitsetImport(imports, false);
1614 + }
1615 + insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose());
1616 +
1617 + }
1525 } 1618 }
1526 /* 1619 /*
1527 * Close all the file handles. 1620 * Close all the file handles.
...@@ -1547,15 +1640,15 @@ public class TempJavaFragmentFiles { ...@@ -1547,15 +1640,15 @@ public class TempJavaFragmentFiles {
1547 YangLeavesHolder holder = (YangLeavesHolder) augmentedNode; 1640 YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
1548 if (holder.getListOfLeaf() != null) { 1641 if (holder.getListOfLeaf() != null) {
1549 for (YangLeaf leaf : holder.getListOfLeaf()) { 1642 for (YangLeaf leaf : holder.getListOfLeaf()) {
1550 - addAugmentConstructor(getJavaAttributeOfLeaf(leaf, 1643 + addAugmentConstructor(getJavaAttributeOfLeaf(this, leaf,
1551 - pluginConfig), pluginConfig); 1644 + pluginConfig), pluginConfig);
1552 } 1645 }
1553 1646
1554 } 1647 }
1555 if (holder.getListOfLeafList() != null) { 1648 if (holder.getListOfLeafList() != null) {
1556 for (YangLeafList leafList : holder.getListOfLeafList()) { 1649 for (YangLeafList leafList : holder.getListOfLeafList()) {
1557 - addAugmentConstructor(getJavaAttributeOfLeafList(leafList, 1650 + addAugmentConstructor(getJavaAttributeOfLeafList(this, leafList,
1558 - pluginConfig), pluginConfig); 1651 + pluginConfig), pluginConfig);
1559 } 1652 }
1560 1653
1561 } 1654 }
...@@ -1579,10 +1672,30 @@ public class TempJavaFragmentFiles { ...@@ -1579,10 +1672,30 @@ public class TempJavaFragmentFiles {
1579 * Adds imports for ToString and HashCodeMethod. 1672 * Adds imports for ToString and HashCodeMethod.
1580 * 1673 *
1581 * @param imports import list 1674 * @param imports import list
1675 + * @param operation add or remove
1582 */ 1676 */
1583 - public void addImportsToStringAndHasCodeMethods(List<String> imports) { 1677 + public void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
1584 - imports.add(getJavaImportData().getImportForHashAndEquals()); 1678 + if (operation) {
1585 - imports.add(getJavaImportData().getImportForToString()); 1679 + imports.add(getJavaImportData().getImportForHashAndEquals());
1680 + imports.add(getJavaImportData().getImportForToString());
1681 + } else {
1682 + imports.remove(getJavaImportData().getImportForHashAndEquals());
1683 + imports.remove(getJavaImportData().getImportForToString());
1684 + }
1685 + }
1686 +
1687 + /**
1688 + * Adds imports for bitset method.
1689 + *
1690 + * @param imports import list
1691 + * @param operation add or remove
1692 + */
1693 + public void addBitsetImport(List<String> imports, boolean operation) {
1694 + if (operation) {
1695 + imports.add(getJavaImportData().getImportForToBitSet());
1696 + } else {
1697 + imports.remove(getJavaImportData().getImportForToBitSet());
1698 + }
1586 } 1699 }
1587 1700
1588 1701
...@@ -1653,6 +1766,9 @@ public class TempJavaFragmentFiles { ...@@ -1653,6 +1766,9 @@ public class TempJavaFragmentFiles {
1653 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { 1766 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
1654 closeFile(getBuilderClassJavaFileHandle(), true); 1767 closeFile(getBuilderClassJavaFileHandle(), true);
1655 } 1768 }
1769 + if ((getGeneratedJavaFiles() & OPERATION_BUILDER_CLASS_MASK) != 0) {
1770 + closeFile(getBuilderOpParmClassJavaFileHandle(), true);
1771 + }
1656 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { 1772 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1657 closeFile(getBuilderInterfaceJavaFileHandle(), true); 1773 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1658 } 1774 }
...@@ -1700,4 +1816,21 @@ public class TempJavaFragmentFiles { ...@@ -1700,4 +1816,21 @@ public class TempJavaFragmentFiles {
1700 getJavaFileInfo().getPackage()); 1816 getJavaFileInfo().getPackage());
1701 } 1817 }
1702 1818
1819 + /**
1820 + * Returns java file handle for op param class file.
1821 + *
1822 + * @return java file handle for op param class file
1823 + */
1824 + public File getOpParamClassJavaFileHandle() {
1825 + return opParamClassJavaFileHandle;
1826 + }
1827 +
1828 + /**
1829 + * Sets the java file handle for op param class file.
1830 + *
1831 + * @param opParamClassJavaFileHandle java file handle
1832 + */
1833 + public void setOpParamClassJavaFileHandle(File opParamClassJavaFileHandle) {
1834 + this.opParamClassJavaFileHandle = opParamClassJavaFileHandle;
1835 + }
1703 } 1836 }
......
...@@ -332,7 +332,7 @@ public class TempJavaTypeFragmentFiles ...@@ -332,7 +332,7 @@ public class TempJavaTypeFragmentFiles
332 * Creates type def class file. 332 * Creates type def class file.
333 */ 333 */
334 if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { 334 if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
335 - addImportsToStringAndHasCodeMethods(imports); 335 + addImportsToStringAndHasCodeMethods(imports, true);
336 setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX))); 336 setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
337 generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports); 337 generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
338 } 338 }
...@@ -340,7 +340,7 @@ public class TempJavaTypeFragmentFiles ...@@ -340,7 +340,7 @@ public class TempJavaTypeFragmentFiles
340 * Creates type class file. 340 * Creates type class file.
341 */ 341 */
342 if ((fileType & GENERATE_UNION_CLASS) != 0) { 342 if ((fileType & GENERATE_UNION_CLASS) != 0) {
343 - addImportsToStringAndHasCodeMethods(imports); 343 + addImportsToStringAndHasCodeMethods(imports, true);
344 setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX))); 344 setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
345 generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports); 345 generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
346 } 346 }
......
...@@ -39,6 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isM ...@@ -39,6 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isM
39 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq; 39 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
40 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 40 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
41 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; 41 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
42 +import static org.onosproject.yangutils.utils.UtilConstants.SBI;
42 43
43 /** 44 /**
44 * Represents module information extended to support java code generation. 45 * Represents module information extended to support java code generation.
...@@ -159,10 +160,13 @@ public class YangJavaModule ...@@ -159,10 +160,13 @@ public class YangJavaModule
159 160
160 try { 161 try {
161 if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) { 162 if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
162 - getTempJavaCodeFragmentFiles() 163 + if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
163 - .generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 164 + (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
164 - getTempJavaCodeFragmentFiles() 165 + getTempJavaCodeFragmentFiles()
165 - .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 166 + .generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
167 + getTempJavaCodeFragmentFiles()
168 + .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
169 + }
166 } 170 }
167 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + 171 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
168 getJavaFileInfo().getPackageFilePath()); 172 getJavaFileInfo().getPackageFilePath());
......
...@@ -40,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen ...@@ -40,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen
40 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired; 40 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
41 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq; 41 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
42 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 42 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
43 +import static org.onosproject.yangutils.utils.UtilConstants.SBI;
43 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; 44 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
44 45
45 /** 46 /**
...@@ -127,8 +128,7 @@ public class YangJavaSubModule ...@@ -127,8 +128,7 @@ public class YangJavaSubModule
127 /** 128 /**
128 * Returns the name space of the module to which the sub module belongs to. 129 * Returns the name space of the module to which the sub module belongs to.
129 * 130 *
130 - * @param belongsToInfo Information of the module to which the sub module 131 + * @param belongsToInfo Information of the module to which the sub module belongs
131 - * belongs
132 * @return the name space string of the module. 132 * @return the name space string of the module.
133 */ 133 */
134 public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { 134 public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
...@@ -136,8 +136,7 @@ public class YangJavaSubModule ...@@ -136,8 +136,7 @@ public class YangJavaSubModule
136 } 136 }
137 137
138 /** 138 /**
139 - * Prepares the information for java code generation corresponding to YANG 139 + * Prepares the information for java code generation corresponding to YANG submodule info.
140 - * submodule info.
141 * 140 *
142 * @param yangPlugin YANG plugin config 141 * @param yangPlugin YANG plugin config
143 * @throws TranslatorException when fails to translate 142 * @throws TranslatorException when fails to translate
...@@ -171,9 +170,11 @@ public class YangJavaSubModule ...@@ -171,9 +170,11 @@ public class YangJavaSubModule
171 */ 170 */
172 try { 171 try {
173 if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) { 172 if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
174 - 173 + if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
175 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 174 + (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
176 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 175 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
176 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
177 + }
177 } 178 }
178 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + 179 searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
179 getJavaFileInfo().getPackageFilePath()); 180 getJavaFileInfo().getPackageFilePath());
......
...@@ -38,11 +38,14 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -38,11 +38,14 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
41 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
42 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
41 import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT; 43 import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
42 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 44 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
43 import static org.onosproject.yangutils.utils.UtilConstants.CLASS; 45 import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
44 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 46 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
45 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; 47 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
48 +import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
46 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; 49 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
47 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; 50 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
48 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; 51 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
...@@ -123,8 +126,12 @@ public final class ClassDefinitionGenerator { ...@@ -123,8 +126,12 @@ public final class ClassDefinitionGenerator {
123 return getInterfaceDefinition(yangName, curNode); 126 return getInterfaceDefinition(yangName, curNode);
124 case BUILDER_CLASS_MASK: 127 case BUILDER_CLASS_MASK:
125 return getBuilderClassDefinition(yangName, curNode); 128 return getBuilderClassDefinition(yangName, curNode);
129 + case OPERATION_BUILDER_CLASS_MASK:
130 + return getOpParamBuilderClassDefinition(yangName, curNode);
126 case IMPL_CLASS_MASK: 131 case IMPL_CLASS_MASK:
127 return getImplClassDefinition(yangName, curNode); 132 return getImplClassDefinition(yangName, curNode);
133 + case OPERATION_CLASS_MASK:
134 + return getOperClassDefinition(yangName, curNode);
128 case BUILDER_INTERFACE_MASK: 135 case BUILDER_INTERFACE_MASK:
129 return getBuilderInterfaceDefinition(yangName, curNode); 136 return getBuilderInterfaceDefinition(yangName, curNode);
130 case GENERATE_SERVICE_AND_MANAGER: 137 case GENERATE_SERVICE_AND_MANAGER:
...@@ -205,6 +212,26 @@ public final class ClassDefinitionGenerator { ...@@ -205,6 +212,26 @@ public final class ClassDefinitionGenerator {
205 } 212 }
206 213
207 /** 214 /**
215 + * Returns operation param builder file class definition.
216 + *
217 + * @param yangName class name
218 + * @param curNode YANG node
219 + * @return definition returns operation param builder file class definition
220 + */
221 + private static String getOpParamBuilderClassDefinition(String yangName, YangNode curNode) {
222 + String clsDef = "";
223 + if (curNode instanceof YangAugment) {
224 + clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_BUILDER_CLASS_MASK);
225 + if (clsDef != null) {
226 + return clsDef;
227 + }
228 + }
229 + return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + BUILDER + SPACE + EXTEND +
230 + SPACE + getCapitalCase(DEFAULT) + yangName + PERIOD + yangName + BUILDER + SPACE +
231 + OPEN_CURLY_BRACKET + NEW_LINE;
232 + }
233 +
234 + /**
208 * Returns impl file class definition. 235 * Returns impl file class definition.
209 * 236 *
210 * @param yangName file name 237 * @param yangName file name
...@@ -223,6 +250,26 @@ public final class ClassDefinitionGenerator { ...@@ -223,6 +250,26 @@ public final class ClassDefinitionGenerator {
223 } 250 }
224 251
225 /** 252 /**
253 + * Returns operation param file class definition.
254 + *
255 + * @param yangName class name
256 + * @param curNode YANG node
257 + * @return definition returns operation param file class definition
258 + */
259 + private static String getOperClassDefinition(String yangName, YangNode curNode) {
260 + String clsDef = "";
261 + if (curNode instanceof YangAugment) {
262 + clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_CLASS_MASK);
263 + if (clsDef != null) {
264 + return clsDef;
265 + }
266 + }
267 +
268 + return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE
269 + + getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
270 + }
271 +
272 + /**
226 * Returns impl file class definition. 273 * Returns impl file class definition.
227 * 274 *
228 * @param yangName file name 275 * @param yangName file name
...@@ -413,6 +460,19 @@ public final class ClassDefinitionGenerator { ...@@ -413,6 +460,19 @@ public final class ClassDefinitionGenerator {
413 return def + SPACE + IMPLEMENTS + SPACE 460 return def + SPACE + IMPLEMENTS + SPACE
414 + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 461 + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
415 462
463 + case OPERATION_CLASS_MASK:
464 + def = def + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE;
465 + for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
466 + if (!info.getClassInfo().contains(BUILDER)
467 + && info.getClassInfo().contains(OPERATION)) {
468 + def = getDefinitionString(def, info, holder);
469 + }
470 + }
471 +
472 + def = trimAtLast(def, COMMA);
473 +
474 + return def + SPACE + EXTEND + SPACE
475 + + getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
416 default: 476 default:
417 return null; 477 return null;
418 } 478 }
......
...@@ -105,16 +105,17 @@ public final class JavaCodeSnippetGen { ...@@ -105,16 +105,17 @@ public final class JavaCodeSnippetGen {
105 /** 105 /**
106 * Returns the textual java code for attribute definition in class. 106 * Returns the textual java code for attribute definition in class.
107 * 107 *
108 - * @param javaAttributeTypePkg Package of the attribute type 108 + * @param javaAttributeTypePkg Package of the attribute type
109 - * @param javaAttributeType java attribute type 109 + * @param javaAttributeType java attribute type
110 - * @param javaAttributeName name of the attribute 110 + * @param javaAttributeName name of the attribute
111 - * @param isList is list attribute 111 + * @param isList is list attribute
112 - * @return the textual java code for attribute definition in class 112 + * @param attributeAccessType attribute access type
113 + * @return the textual java code for attribute definition in class
113 */ 114 */
114 public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, 115 public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
115 - String javaAttributeName, boolean isList) { 116 + String javaAttributeName, boolean isList, String attributeAccessType) {
116 117
117 - String attributeDefination = PRIVATE + SPACE; 118 + String attributeDefination = attributeAccessType + SPACE;
118 119
119 if (!isList) { 120 if (!isList) {
120 if (javaAttributeTypePkg != null) { 121 if (javaAttributeTypePkg != null) {
......
...@@ -22,6 +22,9 @@ import java.util.ArrayList; ...@@ -22,6 +22,9 @@ import java.util.ArrayList;
22 import java.util.List; 22 import java.util.List;
23 23
24 import org.onosproject.yangutils.datamodel.YangAugment; 24 import org.onosproject.yangutils.datamodel.YangAugment;
25 +import org.onosproject.yangutils.datamodel.YangLeaf;
26 +import org.onosproject.yangutils.datamodel.YangLeafList;
27 +import org.onosproject.yangutils.datamodel.YangLeavesHolder;
25 import org.onosproject.yangutils.datamodel.YangAugmentableNode; 28 import org.onosproject.yangutils.datamodel.YangAugmentableNode;
26 import org.onosproject.yangutils.datamodel.YangNode; 29 import org.onosproject.yangutils.datamodel.YangNode;
27 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; 30 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
...@@ -44,6 +47,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -44,6 +47,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
44 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
50 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
51 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK; 53 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 54 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
...@@ -91,11 +96,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -91,11 +96,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
91 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; 96 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
92 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; 97 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
93 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; 98 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
99 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart;
100 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter;
101 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypegetter;
94 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; 102 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
95 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; 103 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
104 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeaf;
105 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeafList;
96 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; 106 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
107 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafListgetter;
108 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafgetter;
97 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; 109 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
98 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; 110 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
111 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter;
112 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter;
113 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch;
99 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 114 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
100 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; 115 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
101 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 116 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
...@@ -118,6 +133,27 @@ import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; ...@@ -118,6 +133,27 @@ import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
118 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 133 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
119 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; 134 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
120 import static org.onosproject.yangutils.utils.UtilConstants.SUPER; 135 import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
136 +import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
137 +import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
138 +import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
139 +import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
140 +import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
141 +import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
142 +import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
143 +import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
144 +import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
145 +import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
146 +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
147 +import static org.onosproject.yangutils.utils.UtilConstants.NEW;
148 +import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
149 +import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
150 +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
151 +import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
152 +import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
153 +import static org.onosproject.yangutils.utils.UtilConstants.CREATE;
154 +import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
155 +import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
156 +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
121 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 157 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
122 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 158 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
123 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; 159 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
...@@ -328,6 +364,119 @@ public final class JavaFileGenerator { ...@@ -328,6 +364,119 @@ public final class JavaFileGenerator {
328 } 364 }
329 365
330 /** 366 /**
367 + * Returns generated op param builder class file for current node.
368 + * @param file file handle
369 + * @param curNode current YANG node
370 + * @param isAttrPresent if any attribute is present or not
371 + * @return builder class file
372 + * @throws IOException when fails to write in file
373 + */
374 + public static File generateOpParamBuilderClassFile(File file, YangNode curNode,
375 + boolean isAttrPresent) throws IOException {
376 +
377 + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
378 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
379 +
380 + String className = getCapitalCase(javaFileInfo.getJavaName());
381 +
382 + initiateJavaFileGeneration(file, OPERATION_BUILDER_CLASS_MASK, null, curNode, className);
383 + List<String> methods = new ArrayList<>();
384 +
385 + if (isAttrPresent) {
386 + /**
387 + * Add attribute strings.
388 + */
389 + try {
390 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
391 + OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
392 +
393 + } catch (IOException e) {
394 + throw new IOException("No data found in temporary java code fragment files for " + className
395 + + " while impl class file generation");
396 + }
397 +
398 + try {
399 + if (curNode instanceof YangLeavesHolder) {
400 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
401 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
402 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
403 +
404 + if (leaves != null && !leaves.isEmpty()) {
405 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
406 + BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
407 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
408 + + NEW_LINE);
409 +
410 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
411 + BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
412 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
413 + + SEMI_COLAN + NEW_LINE);
414 + }
415 +
416 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
417 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
418 + BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
419 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
420 + + SEMI_COLAN + NEW_LINE);
421 +
422 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
423 + BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
424 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
425 + + SEMI_COLAN + NEW_LINE);
426 + }
427 + }
428 +
429 + } catch (IOException e) {
430 + throw new IOException("No data found in temporary java code fragment files for " + className
431 + + " while impl class file generation");
432 + }
433 +
434 + try {
435 + /**
436 + * Setter methods.
437 + */
438 + methods.add(getSetterForLeaf(className, curNode, pluginConfig));
439 + methods.add(getSetterForLeafList(className, curNode, pluginConfig));
440 +
441 + if (curNode instanceof YangLeavesHolder) {
442 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
443 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
444 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
445 +
446 + if (leaves != null && !leaves.isEmpty()) {
447 + methods.add(getToStringLeafgetter());
448 + methods.add(getToStringSelectLeafgetter());
449 + }
450 +
451 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
452 + methods.add(getToStringLeafListgetter());
453 + methods.add(getToStringSelectLeafListgetter());
454 + }
455 + }
456 +
457 + methods.add(getOperationTypegetter());
458 + methods.add(getOperationTypeSetter());
459 + insertDataIntoJavaFile(file, NEW_LINE);
460 + } catch (IOException e) {
461 + throw new IOException("No data found in temporary java code fragment files for " + className
462 + + " while builder class file generation");
463 + }
464 + } else {
465 + insertDataIntoJavaFile(file, NEW_LINE);
466 + }
467 +
468 + /**
469 + * Add methods in builder class.
470 + */
471 + for (String method : methods) {
472 + insertDataIntoJavaFile(file, method);
473 + }
474 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
475 + return validateLineLength(file);
476 + }
477 +
478 +
479 + /**
331 * Returns generated manager class file for current node. 480 * Returns generated manager class file for current node.
332 * 481 *
333 * @param file file 482 * @param file file
...@@ -513,6 +662,160 @@ public final class JavaFileGenerator { ...@@ -513,6 +662,160 @@ public final class JavaFileGenerator {
513 } 662 }
514 663
515 /** 664 /**
665 + * Returns generated op param class file for current node.
666 + *
667 + * @param file file handle
668 + * @param curNode current YANG node
669 + * @param isAttrPresent if any attribute is present or not
670 + * @param imports import list
671 + * @return returns generated op param class file for current node
672 + * @throws IOException when fails to write in file
673 + */
674 + public static File generateOpParamImplClassFile(File file, YangNode curNode,
675 + boolean isAttrPresent, List<String> imports)
676 + throws IOException {
677 +
678 + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
679 + YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
680 +
681 + String className = getCapitalCase(javaFileInfo.getJavaName());
682 + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
683 +
684 + initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className);
685 +
686 + List<String> methods = new ArrayList<>();
687 +
688 + if (isAttrPresent) {
689 + /**
690 + * Add attribute strings.
691 + */
692 + try {
693 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC +
694 + SPACE + ENUM + SPACE + OPERATION_ENUM + SPACE + OPEN_CURLY_BRACKET +
695 + NEW_LINE + EIGHT_SPACE_INDENTATION + MERGE +
696 + NEW_LINE + EIGHT_SPACE_INDENTATION + REPLACE +
697 + NEW_LINE + EIGHT_SPACE_INDENTATION + CREATE +
698 + NEW_LINE + EIGHT_SPACE_INDENTATION + DELETE +
699 + NEW_LINE + EIGHT_SPACE_INDENTATION + REMOVE +
700 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
701 +
702 + } catch (IOException e) {
703 + throw new IOException("No data found in temporary java code fragment files for " + className
704 + + " while impl class file generation");
705 + }
706 +
707 + /**
708 + * Add attribute strings.
709 + */
710 + try {
711 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
712 + OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
713 +
714 + } catch (IOException e) {
715 + throw new IOException("No data found in temporary java code fragment files for " + className
716 + + " while impl class file generation");
717 + }
718 +
719 + try {
720 + if (curNode instanceof YangLeavesHolder) {
721 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
722 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
723 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
724 +
725 + if (leaves != null && !leaves.isEmpty()) {
726 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
727 + BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
728 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
729 + + SEMI_COLAN + NEW_LINE);
730 +
731 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
732 + BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
733 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
734 + + SEMI_COLAN + NEW_LINE);
735 + }
736 +
737 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
738 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
739 + BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
740 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
741 + + SEMI_COLAN + NEW_LINE);
742 +
743 + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
744 + BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
745 + NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
746 + + SEMI_COLAN + NEW_LINE);
747 + }
748 + }
749 +
750 + } catch (IOException e) {
751 + throw new IOException("No data found in temporary java code fragment files for " + className
752 + + " while impl class file generation");
753 + }
754 +
755 + if (curNode instanceof YangLeavesHolder) {
756 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
757 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
758 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
759 +
760 + if (leaves != null && !leaves.isEmpty()) {
761 + methods.add(getToStringLeafgetter());
762 + methods.add(getToStringSelectLeafgetter());
763 + }
764 +
765 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
766 + methods.add(getToStringLeafListgetter());
767 + methods.add(getToStringSelectLeafListgetter());
768 + }
769 + }
770 +
771 + methods.add(getOperationTypegetter());
772 + methods.add(getisFilterContentMatch(className, curNode, pluginConfig));
773 +
774 + } else {
775 + insertDataIntoJavaFile(file, NEW_LINE);
776 + }
777 + String constructor = getOpParamConstructorStart(className, pluginConfig);
778 +
779 + constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS
780 + + BUILDER.toLowerCase() + OBJECT
781 + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
782 +
783 + if (curNode instanceof YangLeavesHolder) {
784 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
785 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
786 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
787 + String filterLeaf = "";
788 + String filterLeafList = "";
789 +
790 + if (leaves != null && !leaves.isEmpty()) {
791 + filterLeaf = EIGHT_SPACE_INDENTATION + FILTER_LEAF + SPACE + EQUAL + SPACE
792 + + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF + OPEN_PARENTHESIS
793 + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
794 + }
795 +
796 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
797 + filterLeafList = EIGHT_SPACE_INDENTATION + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE
798 + + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS
799 + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
800 + }
801 +
802 + constructor = constructor + filterLeaf + filterLeafList;
803 + }
804 +
805 + methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
806 +
807 + /**
808 + * Add methods in impl class.
809 + */
810 + for (String method : methods) {
811 + insertDataIntoJavaFile(file, method);
812 + }
813 +
814 +
815 + return validateLineLength(file);
816 + }
817 +
818 + /**
516 * Generates class file for type def. 819 * Generates class file for type def.
517 * 820 *
518 * @param file generated file 821 * @param file generated file
......
...@@ -55,6 +55,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -55,6 +55,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
55 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 55 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
56 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 56 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
57 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 57 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
58 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
59 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
58 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 60 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
59 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK; 61 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
60 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 62 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
...@@ -95,6 +97,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENU ...@@ -95,6 +97,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENU
95 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT; 97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER; 98 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS; 99 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
100 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OPERATION_CLASS;
98 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 101 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
99 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 102 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
100 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; 103 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
...@@ -371,9 +374,16 @@ public final class JavaFileGeneratorUtils { ...@@ -371,9 +374,16 @@ public final class JavaFileGeneratorUtils {
371 appendHeaderContents(file, pkgString, importsList); 374 appendHeaderContents(file, pkgString, importsList);
372 write(file, genType, IMPL_CLASS, curNode, className); 375 write(file, genType, IMPL_CLASS, curNode, className);
373 break; 376 break;
377 + case OPERATION_CLASS_MASK:
378 + appendHeaderContents(file, pkgString, importsList);
379 + write(file, genType, OPERATION_CLASS, curNode, className);
380 + break;
374 case BUILDER_CLASS_MASK: 381 case BUILDER_CLASS_MASK:
375 write(file, genType, BUILDER_CLASS, curNode, className); 382 write(file, genType, BUILDER_CLASS, curNode, className);
376 break; 383 break;
384 + case OPERATION_BUILDER_CLASS_MASK:
385 + write(file, genType, BUILDER_CLASS, curNode, className);
386 + break;
377 case BUILDER_INTERFACE_MASK: 387 case BUILDER_INTERFACE_MASK:
378 write(file, genType, BUILDER_INTERFACE, curNode, className); 388 write(file, genType, BUILDER_INTERFACE, curNode, className);
379 break; 389 break;
......
...@@ -19,6 +19,9 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,6 +19,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import java.util.List; 19 import java.util.List;
20 import java.util.Map; 20 import java.util.Map;
21 21
22 +import org.onosproject.yangutils.datamodel.YangLeaf;
23 +import org.onosproject.yangutils.datamodel.YangLeafList;
24 +import org.onosproject.yangutils.datamodel.YangLeavesHolder;
22 import org.onosproject.yangutils.datamodel.YangAtomicPath; 25 import org.onosproject.yangutils.datamodel.YangAtomicPath;
23 import org.onosproject.yangutils.datamodel.YangAugment; 26 import org.onosproject.yangutils.datamodel.YangAugment;
24 import org.onosproject.yangutils.datamodel.YangNode; 27 import org.onosproject.yangutils.datamodel.YangNode;
...@@ -27,15 +30,29 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; ...@@ -27,15 +30,29 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
27 import org.onosproject.yangutils.translator.exception.TranslatorException; 30 import org.onosproject.yangutils.translator.exception.TranslatorException;
28 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; 31 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
29 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; 32 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
33 +import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
34 +import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
30 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 35 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
31 import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; 36 import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
32 37
38 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
39 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
40 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
41 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
42 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
43 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
44 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
45 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
46 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
47 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
35 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods; 50 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
36 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods; 51 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
37 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getResolvedAugmentsForManager; 52 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getResolvedAugmentsForManager;
38 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers; 53 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
54 +import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeaf;
55 +import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeafList;
39 import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE; 56 import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
40 import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION; 57 import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
41 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; 58 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
...@@ -134,6 +151,25 @@ import static org.onosproject.yangutils.utils.UtilConstants.VALUE; ...@@ -134,6 +151,25 @@ import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
134 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 151 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
135 import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; 152 import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
136 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; 153 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
154 +import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
155 +import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
156 +import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
157 +import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
158 +import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF;
159 +import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
160 +import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
161 +import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
162 +import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_LIST;
163 +import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
164 +import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
165 +import static org.onosproject.yangutils.utils.UtilConstants.GET_OPERATION_TYPE;
166 +import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
167 +import static org.onosproject.yangutils.utils.UtilConstants.SET_OPERATION_TYPE;
168 +import static org.onosproject.yangutils.utils.UtilConstants.RECEIVED_OBJECT;
169 +import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH;
170 +import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
171 +import static org.onosproject.yangutils.utils.UtilConstants.NOT;
172 +import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
137 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; 173 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
138 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; 174 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
139 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; 175 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
...@@ -537,6 +573,21 @@ public final class MethodsGenerator { ...@@ -537,6 +573,21 @@ public final class MethodsGenerator {
537 } 573 }
538 574
539 /** 575 /**
576 + * Returns constructor string for op param class.
577 + *
578 + * @param yangName class name
579 + * @param pluginConfig plugin configurations
580 + * @return constructor string
581 + */
582 + public static String getOpParamConstructorStart(String yangName, YangPluginConfig pluginConfig) {
583 +
584 + String javadoc = getConstructorString(yangName, pluginConfig);
585 + String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + OPERATION +
586 + OPEN_PARENTHESIS + yangName + OPERATION + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
587 + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
588 + return javadoc + constructor;
589 + }
590 + /**
540 * Returns the constructor strings for class file. 591 * Returns the constructor strings for class file.
541 * 592 *
542 * @param attr attribute info 593 * @param attr attribute info
...@@ -652,6 +703,278 @@ public final class MethodsGenerator { ...@@ -652,6 +703,278 @@ public final class MethodsGenerator {
652 } 703 }
653 704
654 /** 705 /**
706 + * Returns to string leaf for get method.
707 + *
708 + * @return string leaf for get method
709 + */
710 + public static String getToStringLeafgetter() {
711 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF
712 + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
713 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF + SEMI_COLAN + NEW_LINE
714 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
715 + }
716 +
717 + /**
718 + * Returns to string select leaf for get method.
719 + *
720 + * @return select leaf string for get method
721 + */
722 + public static String getToStringSelectLeafgetter() {
723 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF
724 + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
725 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF + SEMI_COLAN + NEW_LINE
726 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
727 + }
728 +
729 + /**
730 + * Returns to string leaf list for get method.
731 + *
732 + * @return string leaf list for get method
733 + */
734 + public static String getToStringLeafListgetter() {
735 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF_LIST
736 + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
737 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF_LIST + SEMI_COLAN + NEW_LINE
738 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
739 + }
740 +
741 + /**
742 + * Returns to string select leaf list for get.
743 + *
744 + * @return select leaf list list for get
745 + */
746 + public static String getToStringSelectLeafListgetter() {
747 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF_LIST
748 + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
749 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF_LIST + SEMI_COLAN + NEW_LINE
750 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
751 + }
752 +
753 + /**
754 + * Returns to string operation type for get method.
755 + *
756 + * @return operation type for get method
757 + */
758 + public static String getOperationTypegetter() {
759 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + OPERATION_ENUM
760 + + SPACE + GET_OPERATION_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
761 + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
762 + + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
763 + }
764 +
765 + /**
766 + * Returns to string operation type for set.
767 + *
768 + * @return operation type set method
769 + */
770 + public static String getOperationTypeSetter() {
771 + return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_OPERATION_TYPE
772 + + OPEN_PARENTHESIS + OPERATION_ENUM + SPACE + getSmallCase(OPERATION_ENUM) + CLOSE_PARENTHESIS
773 + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
774 + + OP_PARAM_TYPE + SPACE + EQUAL + SPACE + getSmallCase(OPERATION_ENUM) + SEMI_COLAN + NEW_LINE
775 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
776 + }
777 +
778 + /**
779 + * Returns string for leaf set method.
780 + *
781 + * @param className class name
782 + * @param curnode current YANG node
783 + * @param pluginConfig plugin configurations
784 + * @return string for leaf set method
785 + */
786 + public static String getSetterForLeaf(String className, YangNode curnode, YangPluginConfig pluginConfig) {
787 +
788 + int numleaf = 1;
789 + String filterMethod = "";
790 + TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
791 + .getTempJavaCodeFragmentFiles().getBeanTempFiles();
792 + if (curnode instanceof YangLeavesHolder) {
793 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
794 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
795 + if (leaves != null && !leaves.isEmpty()) {
796 + for (YangLeaf leaf : leaves) {
797 + JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf, pluginConfig);
798 + String attrQuaifiedType = getReturnType(javaAttributeInfo);
799 + String attributeName = javaAttributeInfo.getAttributeName();
800 +
801 + filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
802 + + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
803 + + attributeName + OPEN_PARENTHESIS + attrQuaifiedType
804 + + SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
805 + + NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
806 + + RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
807 + + GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
808 + + OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
809 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
810 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
811 + numleaf++;
812 + }
813 + }
814 + }
815 + return filterMethod;
816 + }
817 +
818 + /**
819 + * Returns string for leaf list set method.
820 + *
821 + * @param className class name
822 + * @param curnode current YANG node
823 + * @param pluginConfig plugin configurations
824 + * @return string for leaf list set method
825 + */
826 + public static String getSetterForLeafList(String className, YangNode curnode, YangPluginConfig pluginConfig) {
827 +
828 + int numleaf = 1;
829 + String filterMethod = "";
830 + TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
831 + .getTempJavaCodeFragmentFiles().getBeanTempFiles();
832 + if (curnode instanceof YangLeavesHolder) {
833 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
834 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
835 +
836 + if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
837 + for (YangLeafList leafList : listOfLeafList) {
838 + JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
839 + pluginConfig);
840 + String attributeName = javaAttributeInfo.getAttributeName();
841 + String attrQuaifiedType = getReturnType(javaAttributeInfo);
842 + if (javaAttributeInfo.isListAttr()) {
843 + attrQuaifiedType = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
844 + }
845 + filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
846 + + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
847 + + attributeName + OPEN_PARENTHESIS + attrQuaifiedType
848 + + SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
849 + + NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
850 + + RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
851 + + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
852 + + OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
853 + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
854 + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
855 + numleaf++;
856 + }
857 + }
858 + }
859 + return filterMethod;
860 + }
861 +
862 + /**
863 + * Returns whether the data type is of primitive data type.
864 + *
865 + * @param dataType data type to be checked
866 + * @return true, if data type can have primitive data type, false otherwise
867 + */
868 + public static boolean isPrimitiveDataType(YangDataTypes dataType) {
869 + return dataType == INT8
870 + || dataType == INT16
871 + || dataType == INT32
872 + || dataType == INT64
873 + || dataType == UINT8
874 + || dataType == UINT16
875 + || dataType == UINT32
876 + || dataType == UINT64
877 + || dataType == DECIMAL64
878 + || dataType == BOOLEAN;
879 + }
880 +
881 + /**
882 + * Returns string for is filter content match method.
883 + *
884 + * @param className class name
885 + * @param curnode current YANG node
886 + * @param pluginConfig plugin configurations
887 + * @return string for is filter content match method
888 + */
889 + public static String getisFilterContentMatch(String className, YangNode curnode, YangPluginConfig pluginConfig) {
890 +
891 + int numleaf = 1;
892 + String filterMethod = "";
893 + TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
894 + .getTempJavaCodeFragmentFiles().getBeanTempFiles();
895 +
896 + if (curnode instanceof YangLeavesHolder) {
897 + YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
898 + List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
899 + List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
900 + if (leaves != null || listOfLeafList != null) {
901 + filterMethod = NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
902 + + SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(DEFAULT)
903 + + getCapitalCase(className) + SPACE + APP_INSTANCE + CLOSE_PARENTHESIS + SPACE
904 + + OPEN_CURLY_BRACKET + NEW_LINE;
905 + }
906 + if (leaves != null) {
907 + for (YangLeaf leaf : leaves) {
908 + JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf,
909 + pluginConfig);
910 + String attributeName = javaAttributeInfo.getAttributeName();
911 +
912 + String attrQuaifiedType = "";
913 + if (isPrimitiveDataType(leaf.getDataType().getDataType())) {
914 + attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
915 + + SPACE + NOT + EQUAL + SPACE + attributeName + OPEN_PARENTHESIS
916 + + CLOSE_PARENTHESIS;
917 + } else {
918 + attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
919 + + SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + OR_OPERATION + SPACE + OPEN_PARENTHESIS
920 + + NOT + OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
921 + + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
922 + + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
923 + + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS;
924 + }
925 +
926 + filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
927 + + GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
928 + + OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
929 + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
930 + + OPEN_PARENTHESIS + attrQuaifiedType + CLOSE_PARENTHESIS + SPACE
931 + + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
932 + + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
933 + + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
934 + numleaf++;
935 + }
936 + }
937 +
938 + if (listOfLeafList != null) {
939 + numleaf = 1;
940 + for (YangLeafList leafList : listOfLeafList) {
941 + JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
942 + pluginConfig);
943 + String attributeName = javaAttributeInfo.getAttributeName();
944 + String attrQuaifiedType = "";
945 + if (isPrimitiveDataType(leafList.getDataType().getDataType())) {
946 + attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
947 + + SPACE + NOT + EQUAL + SPACE + attributeName + OPEN_PARENTHESIS
948 + + CLOSE_PARENTHESIS;
949 + } else {
950 + attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
951 + + SPACE + EQUAL + EQUAL + SPACE + NULL + OR_OPERATION + OPEN_PARENTHESIS + NOT
952 + + OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
953 + + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
954 + + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
955 + }
956 +
957 + filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
958 + + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
959 + + OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
960 + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
961 + + OPEN_PARENTHESIS + attrQuaifiedType + CLOSE_PARENTHESIS + SPACE
962 + + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
963 + + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
964 + + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
965 + numleaf++;
966 + }
967 + }
968 +
969 + if (leaves != null || listOfLeafList != null) {
970 + filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
971 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
972 + }
973 + }
974 + return filterMethod;
975 + }
976 +
977 + /**
655 * Returns omit null value string. 978 * Returns omit null value string.
656 * 979 *
657 * @return omit null value string 980 * @return omit null value string
......
...@@ -47,6 +47,11 @@ public final class UtilConstants { ...@@ -47,6 +47,11 @@ public final class UtilConstants {
47 public static final String EVENT_JAVA_DOC = " * Represents event implementation of "; 47 public static final String EVENT_JAVA_DOC = " * Represents event implementation of ";
48 48
49 /** 49 /**
50 + * JavaDocs for op param class.
51 + */
52 + public static final String OP_PARAM_JAVA_DOC = " * Represents operation parameter implementation of ";
53 +
54 + /**
50 * JavaDocs for event listener. 55 * JavaDocs for event listener.
51 */ 56 */
52 public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of "; 57 public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
...@@ -167,6 +172,21 @@ public final class UtilConstants { ...@@ -167,6 +172,21 @@ public final class UtilConstants {
167 public static final String DEFAULT = "default"; 172 public static final String DEFAULT = "default";
168 173
169 /** 174 /**
175 + * Static attribute for op param class.
176 + */
177 + public static final String OPERATION = "OpParam";
178 +
179 + /**
180 + * Static attribute for operation type.
181 + */
182 + public static final String OPERATION_ENUM = "OperationType";
183 +
184 + /**
185 + * Static attribute for java code generation for sbi.
186 + */
187 + public static final String SBI = "sbi";
188 +
189 + /**
170 * Static attribute for multiple new line. 190 * Static attribute for multiple new line.
171 */ 191 */
172 public static final String MULTIPLE_NEW_LINE = "\n\n"; 192 public static final String MULTIPLE_NEW_LINE = "\n\n";
...@@ -512,6 +532,11 @@ public final class UtilConstants { ...@@ -512,6 +532,11 @@ public final class UtilConstants {
512 public static final String OPEN_PARENTHESIS = "("; 532 public static final String OPEN_PARENTHESIS = "(";
513 533
514 /** 534 /**
535 + * Static attribute for received syntax.
536 + */
537 + public static final String RECEIVED_OBJECT = "recv";
538 +
539 + /**
515 * Static attribute for switch syntax. 540 * Static attribute for switch syntax.
516 */ 541 */
517 public static final String SWITCH = "switch"; 542 public static final String SWITCH = "switch";
...@@ -562,11 +587,76 @@ public final class UtilConstants { ...@@ -562,11 +587,76 @@ public final class UtilConstants {
562 public static final String SET_METHOD_PREFIX = "set"; 587 public static final String SET_METHOD_PREFIX = "set";
563 588
564 /** 589 /**
590 + * Static attribute for get filter leaf flags.
591 + */
592 + public static final String GET_FILTER_LEAF = "getFilterLeafFlags";
593 +
594 + /**
595 + * Static attribute for get filter leaf list flags.
596 + */
597 + public static final String GET_FILTER_LEAF_LIST = "getFilterLeafListFlags";
598 +
599 + /**
600 + * Static attribute for filter leaf flags.
601 + */
602 + public static final String FILTER_LEAF = "filterLeafFlags";
603 +
604 + /**
605 + * Static attribute for filter leaf list flags.
606 + */
607 + public static final String FILTER_LEAF_LIST = "filterLeafListFlags";
608 +
609 + /**
610 + * Static attribute for get select leaf flags.
611 + */
612 + public static final String GET_SELECT_LEAF = "getSelectLeafFlags";
613 +
614 + /**
615 + * Static attribute for get select leaf list flags.
616 + */
617 + public static final String GET_SELECT_LEAF_LIST = "getSelectLeafListFlags";
618 +
619 + /**
620 + * Static attribute for get operation type.
621 + */
622 + public static final String GET_OPERATION_TYPE = "getOpertionType";
623 +
624 + /**
625 + * Static attribute for set operation type.
626 + */
627 + public static final String SET_OPERATION_TYPE = "setOpertionType";
628 +
629 + /**
630 + * Static attribute for select leaf flags.
631 + */
632 + public static final String SELECT_LEAF = "selectLeafFlags";
633 +
634 + /**
635 + * Static attribute for select leaf list flags.
636 + */
637 + public static final String SELECT_LEAF_LIST = "selectLeafListFlags";
638 +
639 + /**
640 + * Static attribute for op param type.
641 + */
642 + public static final String OP_PARAM_TYPE = "opParamType";
643 +
644 + /**
645 + * Static attribute for is filter content match method prefix.
646 + */
647 + public static final String FILTER_CONTENT_MATCH = "isFilterContentMatch";
648 +
649 + /**
565 * Static attribute for four space indentation. 650 * Static attribute for four space indentation.
566 */ 651 */
567 public static final String FOUR_SPACE_INDENTATION = " "; 652 public static final String FOUR_SPACE_INDENTATION = " ";
568 653
569 /** 654 /**
655 + * Static attribute for not syntax.
656 + */
657 + public static final String NOT = "!";
658 +
659 + /**
570 * Static attribute for try syntax. 660 * Static attribute for try syntax.
571 */ 661 */
572 public static final String TRY = "try"; 662 public static final String TRY = "try";
...@@ -582,6 +672,31 @@ public final class UtilConstants { ...@@ -582,6 +672,31 @@ public final class UtilConstants {
582 public static final String SUPER = "super"; 672 public static final String SUPER = "super";
583 673
584 /** 674 /**
675 + * Static attribute for merge syntax.
676 + */
677 + public static final String MERGE = "MERGE,";
678 +
679 + /**
680 + * Static attribute for replace syntax.
681 + */
682 + public static final String REPLACE = "REPLACE,";
683 +
684 + /**
685 + * Static attribute for create syntax.
686 + */
687 + public static final String CREATE = "CREATE,";
688 +
689 + /**
690 + * Static attribute for delete syntax.
691 + */
692 + public static final String DELETE = "DELETE,";
693 +
694 + /**
695 + * Static attribute for remove syntax.
696 + */
697 + public static final String REMOVE = "REMOVE";
698 +
699 + /**
585 * Static attribute for eight space indentation. 700 * Static attribute for eight space indentation.
586 */ 701 */
587 public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION; 702 public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
...@@ -637,6 +752,11 @@ public final class UtilConstants { ...@@ -637,6 +752,11 @@ public final class UtilConstants {
637 public static final String ABSTRACT = "abstract"; 752 public static final String ABSTRACT = "abstract";
638 753
639 /** 754 /**
755 + * Static attribute for protected modifier.
756 + */
757 + public static final String PROTECTED = "protected";
758 +
759 + /**
640 * Void java type. 760 * Void java type.
641 */ 761 */
642 public static final String VOID = "void"; 762 public static final String VOID = "void";
...@@ -927,6 +1047,11 @@ public final class UtilConstants { ...@@ -927,6 +1047,11 @@ public final class UtilConstants {
927 public static final String OBJECT = "Object"; 1047 public static final String OBJECT = "Object";
928 1048
929 /** 1049 /**
1050 + * Static attribute for app instance.
1051 + */
1052 + public static final String APP_INSTANCE = "appInstance";
1053 +
1054 + /**
930 * Static attribute for override annotation. 1055 * Static attribute for override annotation.
931 */ 1056 */
932 public static final String OVERRIDE = "@Override"; 1057 public static final String OVERRIDE = "@Override";
...@@ -968,6 +1093,11 @@ public final class UtilConstants { ...@@ -968,6 +1093,11 @@ public final class UtilConstants {
968 public static final String JAVA_UTIL_OBJECTS_IMPORT_PKG = "java.util"; 1093 public static final String JAVA_UTIL_OBJECTS_IMPORT_PKG = "java.util";
969 1094
970 /** 1095 /**
1096 + * Static attribute for bitset.
1097 + */
1098 + public static final String BITSET = "BitSet";
1099 +
1100 + /**
971 * Static attribute for java utilities objects import class. 1101 * Static attribute for java utilities objects import class.
972 */ 1102 */
973 public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; 1103 public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
...@@ -1111,6 +1241,11 @@ public final class UtilConstants { ...@@ -1111,6 +1241,11 @@ public final class UtilConstants {
1111 public static final String EVENT_LISTENER = "EventListener"; 1241 public static final String EVENT_LISTENER = "EventListener";
1112 1242
1113 /** 1243 /**
1244 + * Static attribute for or operator.
1245 + */
1246 + public static final String OR_OPERATION = "||";
1247 +
1248 + /**
1114 * Static attribute for YANG file error. 1249 * Static attribute for YANG file error.
1115 */ 1250 */
1116 public static final String YANG_FILE_ERROR = "YANG file error : "; 1251 public static final String YANG_FILE_ERROR = "YANG file error : ";
......
...@@ -20,6 +20,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; ...@@ -20,6 +20,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
20 import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; 20 import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
21 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 21 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; 22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
23 +import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; 25 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
25 import static org.onosproject.yangutils.utils.UtilConstants.CLASS; 26 import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
...@@ -97,6 +98,12 @@ public final class JavaDocGen { ...@@ -97,6 +98,12 @@ public final class JavaDocGen {
97 case BUILDER_CLASS: { 98 case BUILDER_CLASS: {
98 return generateForBuilderClass(name); 99 return generateForBuilderClass(name);
99 } 100 }
101 + case OPERATION_CLASS: {
102 + return generateForOpParamClass(name);
103 + }
104 + case OPERATION_BUILDER_CLASS: {
105 + return generateForOpParamClass(name);
106 + }
100 case INTERFACE: { 107 case INTERFACE: {
101 return generateForInterface(name); 108 return generateForInterface(name);
102 } 109 }
...@@ -401,6 +408,17 @@ public final class JavaDocGen { ...@@ -401,6 +408,17 @@ public final class JavaDocGen {
401 } 408 }
402 409
403 /** 410 /**
411 + * Generates javaDocs for the op param class.
412 + *
413 + * @param className class name
414 + * @return javaDocs
415 + */
416 + private static String generateForOpParamClass(String className) {
417 + return NEW_LINE + JAVA_DOC_FIRST_LINE + OP_PARAM_JAVA_DOC + className + PERIOD + NEW_LINE
418 + + JAVA_DOC_END_LINE;
419 + }
420 +
421 + /**
404 * Generates javaDoc for the interface. 422 * Generates javaDoc for the interface.
405 * 423 *
406 * @param interfaceName interface name 424 * @param interfaceName interface name
...@@ -623,6 +641,16 @@ public final class JavaDocGen { ...@@ -623,6 +641,16 @@ public final class JavaDocGen {
623 /** 641 /**
624 * For event subject. 642 * For event subject.
625 */ 643 */
626 - EVENT_SUBJECT_CLASS 644 + EVENT_SUBJECT_CLASS,
645 +
646 + /**
647 + * For operation.
648 + */
649 + OPERATION_CLASS,
650 +
651 + /**
652 + * For operation builder.
653 + */
654 + OPERATION_BUILDER_CLASS
627 } 655 }
628 } 656 }
......
...@@ -43,6 +43,29 @@ public final class YangPluginConfig { ...@@ -43,6 +43,29 @@ public final class YangPluginConfig {
43 } 43 }
44 44
45 /** 45 /**
46 + * Java code generation is for sbi.
47 + */
48 + private String codeGenerateForsbi;
49 +
50 + /**
51 + * Returns the string for code generation.
52 + *
53 + * @return returns the string for code generation.
54 + */
55 + public String getCodeGenerateForsbi() {
56 + return codeGenerateForsbi;
57 + }
58 +
59 + /**
60 + * Sets the string sbi or nbi for code generation.
61 + *
62 + * @par code generation is for sbi
63 + */
64 + public void setCodeGenerateForsbi(String codeGenerateForsbi) {
65 + this.codeGenerateForsbi = codeGenerateForsbi;
66 + }
67 +
68 + /**
46 * Sets the path of the java code where it has to be generated. 69 * Sets the path of the java code where it has to be generated.
47 * 70 *
48 * @param codeGenDir path of the directory 71 * @param codeGenDir path of the directory
......
...@@ -102,20 +102,24 @@ public class JavaCodeSnippetGenTest { ...@@ -102,20 +102,24 @@ public class JavaCodeSnippetGenTest {
102 @Test 102 @Test
103 public void testForJavaAttributeInfo() { 103 public void testForJavaAttributeInfo() {
104 104
105 - String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, false); 105 + String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
106 + false, PRIVATE);
106 assertThat(true, is(attributeWithoutTypePkg.equals( 107 assertThat(true, is(attributeWithoutTypePkg.equals(
107 PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); 108 PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
108 109
109 - String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, false); 110 + String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
111 + false, PRIVATE);
110 assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD 112 assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD
111 + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); 113 + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
112 114
113 - String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, true); 115 + String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
116 + true, PRIVATE);
114 assertThat(true, is(attributeWithListPkg.equals( 117 assertThat(true, is(attributeWithListPkg.equals(
115 PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE 118 PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE
116 + DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); 119 + DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
117 120
118 - String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, true); 121 + String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
122 + true, PRIVATE);
119 assertThat(true, is(attributeWithListWithoutPkg.equals( 123 assertThat(true, is(attributeWithListWithoutPkg.equals(
120 PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE 124 PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE
121 + YANG_NAME + SEMI_COLAN + NEW_LINE))); 125 + YANG_NAME + SEMI_COLAN + NEW_LINE)));
......