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:
ProxyPreloader.preloadBeingGeneratedElements: it's better to use this method for all code
generation ruleset.ProxyPreloader.preload: it's better to use this method for all other transformation
ruleset.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);
}
}
}
/META-INF/MANIFEST.MF and add a dependency to: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).
Relaunch now the generation and check that generator allows indifferently On-Demand and Application model reader connector.
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:
<RhapsodyInstallDir>\Sodius\RulesComposer\mdw.iniconnectorName=Rhapsody Application
Now, the code generator will always use the Application reader. If you wish to revert this option:
#connectorName=Rhapsody Application
Prev Section: Use filenames associated to objects in
Rhapsody
Next Section: Use Application model writer in Rhapsody Code Generation