Either use “On-Demand” or “Application” model reader

When we use model reader On-Demand in RulesComposer or if we run a deployed ruleset in IBM Rational Rhapsody, the instruction getInstances("Class") return an empty list.
To avoid this fact, we need to preload the model tree.

To proceed, just change module JavaGeneration.mqr:

package tutorial.java
public ruleset JavaGeneration(in model : rhapsody) { 
     entry rule main() {
             // calls the proxy preloader when the connector 
             // "On-Demand" is invoked.
            
if (com.sodius.mdw.metamodel.rhapsody.proxy.
                    ProxyPreloader.isProxyModel(model)) {
                    var myProxyPreloader : com.sodius.mdw.metamodel.
                            rhapsody.proxy.ProxyPreloader
                    = com.sodius.mdw.metamodel.rhapsody
            
               .proxy.ProxyPreloader
                           
.getNewProxyPreloader(model);
                    myProxyPreloader.preload();
             }
 
             foreach (class : rhapsody.Class in 
                                    model.getInstances(
"Class")) {
                    $JavaSource(class);
             }
     }
}

 

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.

Prev Section: Use filenames associated to objects in Rhapsody
Next Section: Customize filenames associated to Rhapsody objects