We now want to create a Relational Table for each UML Class in the input model:

package tutorial.uml2relational;
public ruleset UML2Relational(in source : uml21, out target : relational) {
public rule main() {
// create a Table for each Class
foreach (class : uml21.Class in source.getInstances("Class")) {
@createTable(class, target.create("Table"));
}
}
private rule createTable(class : uml21.Class,
table : relational.Table) {
// set the name
table.name = class.name;
}
}
Here is the behavior of this ruleset:
Class in the source UML model,
using source.getInstances("Class").foreach
and the loop variable class of type UML Class.
Table instance in the target Relational model,
using target.create("Table").createTable using @createTable(...), passing
the class and created Table as arguments.name of the table to the same as class
(a name attribute is defined on both UML and Relational types).Notes:
'@' is the notation used to call a rule.createTable is private and is not visible outside of its ruleset.