Shankara-Huawei
Committed by Gerrit Code Review

[ONOS-4831] Implement op param class for apps

Change-Id: I88aee8a3009de84649c959e21ce83e3bbbf63c18
Showing 16 changed files with 319 additions and 27 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
......
...@@ -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) {
......
...@@ -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;
......
...@@ -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)));
......