Template structure

For each target you can have several files which are generated. There is a ini file which contains the list of files which need to be generated.
This ini file is called "target-name.ini" and is searched on the classpath.

The file has the following format (excerpt from the ejb3.ini)


[config]
path=ejb3

[global]

output1=${outputDir}${packageDir}client/LazyEJBList.java
template1=LazyEJBList.java.vm

output2=${outputDir}${packageDir}client/LazyProxyList.java
template2=LazyProxyList.java.vm


[root-table]

// build entity bean
output1=${outputDir}${packageDir}server/pm/DM${table}Bean.java
template1=DMObjectBean.java.vm

// build session facade bean
output2=${outputDir}${packageDir}server/${table}Bean.java
template2=ObjectBean.java.vm

// build session facade root mediator
output3=${outputDir}${packageDir}server/${table}MediatorRoot.java
template3=MediatorRoot.java.vm

// build SelectorHelper classes
output4=${outputDir}${packageDir}server/${table}SelectorHelper.java
template4=ObjectSelectorHelper.java.vm
skip-if4=${altOutputDir}${packageDir}server/${table}SelectorHelper.java


[table]

// build mediator base class (generated)
output1=${outputDir}${packageDir}server/${table}MediatorBase.java
template1=MediatorBase.java.vm

// build mediator class (for manual modification)
output2=${outputDir}${packageDir}server/${table}Mediator.java
template2=Mediator.java.vm
skip-if2=${altOutputDir}${packageDir}server/${table}Mediator.java


[multiple-field]

// build entity bean
output1=${outputDir}${packageDir}server/pm/DM${table}_${field}Bean.java
template1=DMFieldBean.java.vm

The "config" section indicates the path which is prepended to each template file. The templates are all retrieved from the classpath, but the prefix allows you to avoid name collisions (like java packages).

All the other sections indicate the possible groupings in the domain model for which files can be generated.
The can contain outputX, templateX and skip-ifX where X is a number from 1 up to the amount needed (needs to be consecutive). In the parameters, you can use variable replacement using the ant/velocity syntax "${var-name}
".

  • output indicates the location where the output file needs to be searched
  • template indicates the template file which needs to be used to produce the output
  • skip-if allows you to skip the template generation if the file with given name already exists.

The sections which can be used (including variables for output names and templates) are

  • global : these templates are invoked once.
  • table : these are generated for each table. "table" is the table name for the filenames, of a Table object for the velocity templates.
  • root-table : these are generated for each roottable. "table" is the (root) table name for the filenames, of a RootTable object for the velocity templates.
  • root-table-expected-amount-small : same as "root-table" but only when the expected amount on the root is "small".
  • root-table-with-inheritance : same as "root" but only when the inheritance tree has more than one table.
  • field : each field, has "root-table" variables and "field" name for filenames or Field instance in the templates.
  • field-with-choices : same as "field" but only for fields with choices.
  • select-not-hidden : all selects which are not hidden, has "root-table" variables and "select" name for filenames or Select instance in the templates.
  • action-not-hidden : all actions which are not hidden, has "root-table" variables and "action" name for filenames or Action instance in the templates.

For variable replacement in the filenames, the following are available in all cases.

  • packageName
  • packageDir
  • outputDir
  • altOutputDir

The following variables are always available in te Velocity templates.

  • engine : a reference to the Generator class.
  • name : "equanda'.
  • dollar : "$".
  • dm, data : the actual domain model, instance of the DomainModel class.
  • package : the package name, as passed in the (template specific) configuration. If not defined there, then the "ejb-package" setting from the "extra" sectio is used.
  • generationdate : string representation of the time when the generation started.
  • keyvalue : the keyvalue pairs which are passed in the (template specific) configuration.
  • dbtype : an instance of the convert class as determined in the "database" section.
  • 1. Template structure