When you deploy a transformation ruleset (as below) and run it with the Code Generator (menu command: Code > Re generate), you have probably noticed that the model was not updated.
public ruleset UpdateModel(inout source : rhapsody) {
public rule myRule() {
var app : rhapsody.Application = source.getInstances("Application").first();
// Always get active project only !
var proj : rhapsody.Project = app.activeProject;
var newPkg : rhapsody.Package = source.create("Package");
newPkg.name = "Hello";
proj.packages.add(newPkg);
}
In fact, the Code Generator has been designed to use a On-Demand reader as input argument and nothing as output, since code source modules are generated.
Two possible solutions are exposed here:
public ruleset UpdateModel(in source : rhapsody) {
public rule myRule() {
var app : rhapsody.Application = source.getInstances("Application").first();
// Always get active project only !
var proj : rhapsody.Project = app.activeProject;
var newPkg : rhapsody.Package = source.create("Package");
newPkg.name = "Hello";
proj.packages.add(newPkg);
// Update model in Rhapsody
model.write("Rhapsody Application", null);
}
public ruleset UpdateModel(in source : rhapsody) {
public rule myRule() {
var app : rhapsody.Application = source.getInstances("Application").first();
// Always get active project only !
var proj : rhapsody.Project = app.activeProject;
var newPkg : rhapsody.Package = source.create("Package");
newPkg.name = "Hello";
proj.packages.add(newPkg);
//Setuping the update writer
var modifiedUnits : java.util.List = java.util.ArrayList.new();
modifiedUnits.add(newPkg);
context.getWorkbench().getMetamodelManager()
.getMetamodel("rhapsody").getModelWriterDescriptor("Rhapsody Application")
.setProperty("unitsToReplace", modifiedUnits);
// Update model in Rhapsody
model.write("Rhapsody Application", null);
}
Prev Section: Either use On-Demand or Application model reader in Rhapsody Code Generation
Next Section: Customize filenames associated to Rhapsody
objects