From the IlrVelocityGenerator class

You can write a new code generator class that inherits from the IlrVelocityGenerator class by redefining the method that matches your project and then generating the necessary files.

About this task

You can use velocity as the engine to write the generated files.

Procedure

  1. To generate all the files that you need, redefine the generateProjectContent(IJavaProject) or generateProjectContent(IProject) method, depending on the kind of project that you want to generate.
    The following methods are available:

    Start the implementation by calling the parent method.

    For example:
    public void generateProjectContent(IJavaProject javaProject) {
       super.generateProjectContent(javaProject);   
       generateVelocityFile("myDestinationDirectory", "",
          myAbsolutePathToTheTemplateDirectory, "myTemplate.vm",
          null, ".properties", "myTemplate.vm"); 
    }
  2. Redefine the getTemplateDirectory method.

    This method indicates the path for the velocity template files. If you use only the method generateVelocityFile or generateVelocityFileInSrc, these methods can return null. These methods use the templateDirectory parameter to get the path of the velocity template files.

  3. Redefine the initializeContext method.

    This method is called each time you call a generateVelocityFile or generateVelocityFileInSrc method in the generateProjectContent method. The initializeContext method sets your parameters relative to the RuleApp project in the generated file. Some accessors are provided to help you retrieve and format the information in the generated file.

    You must call a context.put method for each velocity parameter in your .vm file.

    For example:
    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());
          }
       }  
       return context;
    }