| ILOG JRules User Guide > Executing Rules > Tasks > Executing a Ruleset Using Rule Execution Server > Maintaining Execution Code Generators > Writing a New Generator Class |
Writing a New Generator Class |
PREVIOUS NEXT |
To create a new generator class, you can inherit from the following classes:
ilog.rules.studio.res.generator.IlrFileGenerator
ilog.rules.studio.res.generator.IlrVelocityGenerator
ilog.rules.studio.res.generator.IlrTraceFileGenerator
ilog.rules.studio.res.generator.impl.IlrPOJOGenerator
ilog.rules.studio.res.generator.impl.IlrWebServiceGenerator
To write a new generator class if you inherit from the IlrFileGenerator class:
The following procedure describes what to do if you inherit from the IlrVelocityGenerator class and you want to use velocity as the engine to write the generated files.
To write a new generator class if you inherit from the IlrVelocityGenerator class:
generateProjectContent(IJavaProject) or generateProjectContent(IProject):
generateProjectContent method to generate all the files that you want. The following useful methods are provided:
generateVelocityFile(String path, String filePrefix, String templatePath, String newFilename, String extension, Object userData): to generate a file in the project. The getTemplateDirectory method is used to locate the template file.
generateVelocityFileInSrc(String packagePrefix, String filePrefix, String templatePath, String newFilename, String extension, Object userData): to generate a file in the src directory of the project. The getTemplateDirectory method is used to locate the template file.
generateVelocityFile(String path, String filePrefix, String templateDirectory, String templatePath, String newFilename, String extension, Object userData): to generate a file in the project. The template directory is specified by the templateDirectory parameter.
generateVelocityFileInSrc(String packagePrefix, String filePrefix, String templateDirectory, String templatePath, String newFilename, String extension, Object userData): to generate a file in the src directory of the project. The template directory is specified by the templateDirectory parameter.
getTemplateDirectory method: this method indicates the path for the velocity template files. If you only use the generateVelocityFile(String path, String filePrefix, String templateDirectory, String templatePath, String newFilename, String extension, Object userData) method or the generateVelocityFileInSrc(String packagePrefix, String filePrefix, String templateDirectory, String templatePath, String newFilename, String extension, Object userData) method, which use the templateDirectory parameter to get the path of the velocity template files, then these methods can return null.
initializeContext(Object userData , VelocityContext context) method: this method will be called each time you call a generateVelocityFile or generateVelocityFileInSrc method in the generateProjectContent method. It sets your parameters relative to the RuleApp project in the generated file. Some get methods are provided to help you get and format the information in the generated file.
The following procedure describes what to do if you inherit from the IlrTraceFileGenerator class and you want to use velocity as the engine to write the generated files and use the trace filter properties file.
To write a new generator class if you inherit from the IlrTraceFileGenerator class:
IlrVelocityGenerator class.
generateProjectContent method the parent method.
initializeContext method, as follows:
The following procedure describes what to do if you inherit from either the IlrPOJOGenerator class or the IlrWebServiceGenerator class. The steps are the same in each case.
To write a new generator class if you inherit from the IlrPOJOGenerator class or the IlrWebServiceGenerator class:
initializeContext(Object userData , VelocityContext context) method to set the values of the velocity parameter in your new .vm file, as follows:
getPackagePrefix() method if you want to change the default package where the classes will be generated.
getFilePrefix() method if you want your files to be generated with the same prefix.
getFileHeader() method if you want to change the header of the files.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |