Thank you Stefan for your reply.
I am new at writing Roo Addon, I am still learning ITD stuff...
Basically, in my OperationImpl class, I have this method, which is called when the user issues the command in Roo shell:
Code:
/** {@inheritDoc} */
public void addString(String name, String value) {
Assert.notNull(name, "property name cannot be null.");
JavaPackage topLevelPackage = getProjectMetadata().getTopLevelPackage();
JavaType propertiesManagerType = new JavaType(topLevelPackage.getFullyQualifiedPackageName()+".utils.SayHello");
String mgrIdentifier = typeLocationService.getPhysicalLocationCanonicalPath(propertiesManagerType, Path.SRC_MAIN_JAVA);
String declaredByMetadataId = null;
if (fileManager.exists(mgrIdentifier)) {
ClassOrInterfaceTypeDetails mgrCls = typeLocationService.findClassOrInterface(propertiesManagerType);
//System.out.println("Metadata ID: "+mgrCls.getDeclaredByMetadataId());
//Question here: how do I add a simple method, i.e. void sayHappy(); to mgrCls.
}else{
declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(propertiesManagerType, Path.SRC_MAIN_JAVA);
ClassOrInterfaceTypeDetailsBuilder typeDetailsBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, propertiesManagerType, PhysicalTypeCategory.CLASS);
List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
InvocableMemberBodyBuilder bodyBuilder=new InvocableMemberBodyBuilder();
bodyBuilder.appendIndent();
bodyBuilder.appendFormalLine("return \"hello world!\";");
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName("sayHello"), JavaType.STRING_OBJECT, bodyBuilder);
methods.add(methodBuilder);
typeDetailsBuilder.setDeclaredMethods(methods);
typeManagementService.generateClassFile(typeDetailsBuilder.build());
}
}
I am stuck at the if branch, the else part works. I hope to add a new method to SayHello class through Roo shell after the SayHello was created.
Also, note that the class I try to modify (utils.SayHello) is not an entity or anything. It is simply a POJO class, it has no annotations.
Which Roo Addon will be a good example for me to study? Thanks again.