Either use "On-Demand" or "Application" model reader in Rhapsody Code Generation

Using "On-Demand" reader in Code Generation

When we use model reader On-Demand in RulesComposer or if we run a deployed ruleset as Code Generator in IBM Rational Rhapsody, the instruction getInstances("Unit", true) return an empty list.

To avoid this fact, we need to preload the model tree. Two methods exist:

To proceed, just change module JavaGeneration.mqr:

package tutorial.java; 

import com.sodius.mdw.metamodel.rhapsody.proxy.ProxyPreloader; 

public ruleset JavaGeneration(in model : rhapsody) {
 
  entry rule main() {
  
    // calls the proxy preloader when the connector              
    // "On-Demand" is invoked.
    if (ProxyPreloader.isProxyModel(model)) {
      var myProxyPreloader : ProxyPreloader = ProxyPreloader.getNewProxyPreloader(model);
      myProxyPreloader.preloadBeingGeneratedElements();             
    }
     
    foreach (unit : rhapsody.Unit in model.getInstances("Unit", true)) {
      $JavaSource(unit);             
    }     
  }
}

If RulesComposer indicates a compilation error for the class ProxyPreloader, please open file /META-INF/MANIFEST.MF and add a dependency to:
com.sodius.mdw.metamodel.rhapsody.proxy

If file /META-INF/MANIFEST.MF is missed, please check if you project is an Eclipse plugin type. You can check it, using right-click on project node, and select command PDE Tools > Convert Projects to Plug-in Projects….

Note: To avoid this problem in the future, we advise you to create a RulesComposer project (See tutorial).

Now, add dependencies to:
com.sodius.mdw.metamodel.rhapsody
com.sodius.mdw.metamodel.rhapsody.proxy
com.sodius.mdw.core

Relaunch now the generation and check that generator allows indifferently On-Demand and Application model reader connector.

Using "Application" reader in Code Generation

The default connector reader used by the RulesPlayer Code Generator is the On-Demand model reader.

To use the Application reader, you should change the default options of the Code Generator:

Now, the code generator will always use the Application reader. If you wish to revert this option:


Notes:
The Application reader is slower and requires to define all Rhapsody properties. However, this reader is mandatory when your ruleset updates the model in Rhapsody.

Prev Section: Use filenames associated to objects in Rhapsody
Next Section: Use Application model writer in Rhapsody Code Generation