Example of generator template

The next templates are used to generate simle Java class with automatic loading from the database.
JavaType.mac
<macro>JavaType<begin>%decode<%1%:string:String:Integer:Int:%1%><endmacro>
JavaDemo.mac
00#include<JavaType.mac>
01<macro>main<begin>
02 <for>c classes<begin>%\%
03 public class %.name% {
04 <for>x attributes<begin>
05  <call>JavaType<,>%.type%<endcall> %.name%;<endfor>
06
07  public %.name%() {
08  }
09
10  public load(java.sql.ResultSet rs) {
11  // not-mapped attributes<for>x attributes<where>-M+P<begin>
12  //%.name% = ?;<endfor>
13
14  // mapped attributes<for>x attributes<where>+MP<begin>
15  %.name% = rs.Get<call>JavaType<,>%.type%<endcall>("%.map%");<endfor>
16  }
17
18  private String getLoadString) {
19    return "select * from %.map% "+
20      "where <for>x attributes<where>+PK<div> and <begin>%.map%=?<endfor>";
21  }
22
23  public load() {
24    java.sql.PreparedStatement stmt = connection.prepareStatement(getLoadString());%\%
25<for>x attributes<where>+PK<div> and <begin>
26    stmt.Set<call>JavaType.mac<,>%.type%<endcall>(%.name%);<endfor>
27    java.sql.ResultSet rs = stmt.executeQuery();
28    load(rs);
29    rs.close();
30  }
31}
32<endfor>
33<endmacro>

Macro JavaType can be changed to simplify it's call -
JavaType1.mac
<macro>JavaType1<begin>%decode<%.type%:string:String:Integer:Int:%.type%><endmacro>
It explicitly uses %.type% value of current element (class attribute)

After that the call procedure has to be modified as follow
<call>JavaType1<endcall>
It is shorter but less obviouse variant. In typicall case it make sence to create your command constructions as short as possible becouse it will simplify the understanding of whole template structure.

Semantically equivalent (normalized) form of JavaType1 macro is
<macro>JavaType1<begin><decode>%.type%<,>string<=>String<,>Integer<=>Int<,>%.type%<enddecode><endmacro>

To compile templates run command
Comp.exe JavaDemo.mac
JavaDemo.gen file will be created.

Now it is time to create class model in UML tool like Rational Rose or Enterprise Architecht  and export UML package to XMI file with name Test1.xml.

Class model

Now run MapTool to map your classes to database tables.
... not documented yet ...

Finally generate your source code
Gen.exe XMI=Test1.xml GEN=JavaDemo.gen REPO=scott/tiger OBJ=\test1\MyClass FILE=MyClass.java