Now we want to generate a Java field for each attribute defined on a Class:

You can see the attributes are linked to their class with the reference attributes. The text template has to iterate on the attributes list and print the corresponding Java field declaration:
[#package tutorial.java]
[#template public JavaSource(class : rhapsody.Class)]
[#file]generated/${class.name}.java[/#file]
public class ${class.name} {
[#-- Attributes declaration --]
[#foreach attr : rhapsody.Attribute in class.attributes]
private ${attr.type.name} ${attr.name};
[/#foreach]
}
[/#template]
The template loops on each attribute and prints the name of its type (dynamic text ${attr.type.name}) followed by its name.
[#-- Attributes declaration --] is a comment. A comment is delimited by [#-- and --] and is not written to the output. Note that due to automatic whitespace stripping, whitespaces and linefeeds on line containing only directives and comments are ignored.
Relaunch the generation and open the file Order.java:
public class Order {
private String date;
}
Next Section: Add a field for relations
Prev Section: Inspect the generated files