You can write a new code generator class that inherits
from the IlrPOJOGenerator or IlrWebServiceGenerator class.
About this task
The steps are similar whether the new generator class
inherits from the IlrPOJOGenerator class or from
the IlrWebServiceGenerator class.
Procedure
- If you want to generate more files, redefine the generateProjectContent(IJavaProject) method.
Your implementation must call the parent method.
For example: public void generateProjectContent(IJavaProject javaProject) {
super.generateProjectContent(javaProject);
generateVelocityFile("myDestinationDirectory", "",
myAbsolutePathToTheTemplateDirectory,
"myTemplate.vm", null, ".properties",
"myTemplate.vm");
}
- To set the values of the velocity parameter
in your new .vm file, redefine the initializeContext method.
protected VelocityContext initializeContext(Object userData ,
VelocityContext context) {
if ( userData instanceof String ) {
String templateFile = (String) userData;
if ( templateFile.equals("myTemplate.vm") ) {
context.put("package", getPackagePrefix());
context.put("header", getFileHeader());
context.put("ruleapp-name",
getRuleAppProject().getDescriptor().getName());
context.put("ruleapp-version",
getRuleAppProject().getDescriptor().getVersion());
}
} else {
context = super.initializeContext(userData, context);
}
return context;
}
- If you want to change the default package where the classes
are generated, redefine the getPackagePrefix method.
By default, the package is the RuleApp project name.
- If you want your files to be generated with the same prefix,
redefine the getFilePrefix method.
By default, no prefix is added.
- If you want to change the file headers, redefine the getFileHeader method.