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:
    public ruleset UpdateModel(inout source : rhapsody)
    
  2. 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:
    var application : rhapsody.Application = rhpModel.getInstances("Application").first();
    var project : rhapsody.Project = application.activeProject;
    
  3. CAUTION : you should never use folowing statement to read current project:
    var project : rhapsody.Project = rhpModel.getInstances("Project").first();
    
  4. We need to declare a local variable to store the list of new or updated units:
    var modifiedUnits : java.util.List = java.util.ArrayList.new();
    
  5. See in method searchClassesAndRename, each updated units must be add the modifiedUnits list.
    modifiedUnits.add(rhpClass);
    
  6. 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.
  7. Finally, we notice to the "Rhapsody Application" connector writer which units will be added or updated:
    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:
    [progress] Evaluation of RhapsodyUpdate
    [progress] Reading Rhapsody On-Demand
    [progress] Writing Rhapsody Application
    [progress] Building : Project
    [progress] Building Package : RHP1754740916436624630 / Default
    [progress] Building Package : RHP1754740916436624630 / package2
    [progress] Building Class : RHP1754740916436624630 /  / ClassOfpackage2
    [progress] Creating generalizations
    [progress] Creating template instanciations
    [progress] Setting port contracts
    [progress] Creating relations
    [progress] Creating AssociationClasses
    [progress] Drawing Sequence Diagrams
    [progress] Creating flowlinks
    [progress] Creating unit links
    [progress] Creating instance slots
    [progress] Setting Links connections
    [progress] Creating Tags
    [progress] Creating dependencies
    [progress] Setting SendActions
    [progress] Creating referenced SequenceDiagrams
    [progress] Setting InteractionOccurences
    [progress] Drawing diagrams
    [progress] Done.
    

Deploy and launch this ruleset with Rhapsody Code Generator

This sample needs some adaptation if you want to deploy this ruleset in Rhapsody and invoke it with Code Generator.

A tutorial will explain this procedure in details.


Prev Section: Create your own ruleset player and Rhapsody plugin