In this step, we will change the Java template to generate Java files according to folders and filenames chosen by Rational Rhapsody.
For each object, Rational Rhapsody proposes two files: one for the specifications and a second for the body. Typically files with extension ADS and ADB in Ada, H and CPP in C++ and only JAVA in Java language.
To add a script:
A file rhapsody_Class.mqs is created: it allows us to define MQL scripts on the metatype Class. Change its contents to:
package tutorial.java;
metatype rhapsody.Class;
public script qualifiedPath() : String {
return self.getProperty("RHP.SpecificationFilename");
}
Method qualifiedPath is able to retrieve specification name provided by Rational Rhapsody.
The self variable is available in the script contents. This variable is the instance the script is evaluated
on (instance of the script's metatype).
The getProperty method is available for all connectors and for all metatype inherited from ModelElement. This may return null if property is undefined or if property name is not added into file "Properties.ini" while using connector "Rational Rhapsody Application".
Moreover, the method getMakefileName is available on metatype Configuration to get the full path of the makefile, and method getMainName, the root name (without extension) of the main source file.
Use property RHP.ImplementationFilename to get body name (for C++ or Ada).
Now we can update template JavaSource.tgt:
[#package tutorial.java]
[#template public JavaSource(class : rhapsody.Class)]
[#file]${class.qualifiedPath}[/#file]
[#include JavaDoc()]
public class ${class.name} {
...
Relaunch now the generation and check that Java files are generated in current configuration folder:
<ProjectDir>/<ComponentDir>/<ConfigurationDir>
Note: please find a full example implementing this solution in RulesComposer samples:To add it to your workspace, please: