Now we want to generate a Java field for each relation defined on a Class like we did for attributes.
You can see the relations are linked to their class with the reference relations. The text template has to iterate on the relations 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]
[#-- Relations declaration --]
[#foreach rel : rhapsody.Relation in class.relations]
private ${rel.otherClass.name} ${rel.name};
[/#foreach]
}
[/#template]
Relaunch the generation and open the file Order.java:
public class Order {
private RhpString date;
private Customer customer;
private LineItem items;
}
Next Section: Add a script to handle the multiplicity
Prev Section: Add fields declaration