Update a model in IBM Rational Rhapsody

In this step, we wil learn how to develop rules to update a Rhapsody model.

A sample can be used as a first step to develop rules to update a Rhapsody model.

Add sample project

  1. Choose menu command File > New > Example...,
  2. Choose item RulesCompose Sample in window New Example and press Next,
  3. Choose item Rhapsody rulesets > Update Rhapsody model in window Import RulesCompose Sample and press Next,
  4. In next window, press Finish.

Analyse this sample project

  1. We need to declare the "rhapsody" typed model argument in the ruleset main entry point as inout to be sure to update model:
  2. 		public ruleset UpdateModel(inout source : rhapsody)
    
  3. In the main method myRule, we need to load the active Project reference to avoid a conflict during the update of the model between the "Rhapsody On-Demand" connector reader and the "Rhapsody Application" connector writer:
  4. 		var application : rhapsody.Application = rhpModel.getInstances("Application").first();
    		var project : rhapsody.Project = application.activeProject;
    
  5. CAUTION : you should never use folowing statement to read current project:
  6. 		var project : rhapsody.Project = rhpModel.getInstances("Project").first();
    
  7. We need to declare a local variable to store the list of new or updated units:
  8. 		var modifiedUnits : java.util.List = [];
    
  9. See in method searchClassesAndRename, each updated units must be add the modifiedUnits list.
  10. 			modifiedUnits.add(rhpClass);
    
  11. If you add a new Package with new nested units, you need just to add this package the modifiedUnits list, the nested elements will be automatically added to the model.
  12. Finally, we notice to the "Rhapsody Application" connector writer which units will be added or updated:
  13. 		context.getWorkbench().getMetamodelManager().getMetamodel("rhapsody")
    					.getModelWriterDescriptor("Rhapsody Application")
    						.setProperty("unitsToReplace", modifiedUnits);
    

Launch sample project process

  1. Choose menu command Run > Run configurations...,
  2. In Run configurations window, select RulesComposer > RhapsodyUpdate launch configuration,
  3. Select Main tab and select line source (in) in Parameters grid,
  4. In Properties window, select connector "Rhapsody On-Demand" and press OK,
  5. Select now line source (out) in Parameters grid,
  6. In Properties window, select connector "Rhapsody Application" and press OK,
  7. In Run configurations window, now press Run and wait completion:
  8. [progress] Done.