We want to execute an FSM model. To do that we must call the "run" operation of the "FSM" class. We are going to do that thanks to a KerMeta script. This script will : load an instance of the FSM meta model stored in a file call the run operation of these instance. To launch a script, the interpreter must know the entry point of the program. That is the roles of these two statements :
@mainClass which stands for the main class,
@mainOperation which stands for the main operation of the main class.
In the FSM example, those scripts are in the "launcher" directory. Look at "minimization.kmt" script. Here the interpreter knows that entry point of the program is the operation "main" in the "Minimization" class.
Using KerMeta allows you to choose between two types of executions : one with constraints checking and one without. A constraints checking execution checks every pre/post condition statements of your KerMeta program. If one of this pre/post conditions are violated, an exception is raised and the program is aborted. A none constraints checking execution does not check the pre/post condition statements of your KerMeta program. For more details, go to section 4. One constraints checking execution sample is explained.
Let's have a look at the file named "minimization.kmt". Open it. Look at the code of the main operation. There is no parameter. To run this script with constraint checking, right click on "minimization.kmt" and select "Run As" and "Kermete App with constraints". To run this script without constraint checking, right click on "minimization.kmt" and select "Run As" and "Kermeta App".
The program asks you for a filename. Put in "../models/sample1.fsm" for example. You are lastly asked for a filename which will correspond to the file generated by the program. Put in "../generated.fsm" and see the execution.
Now if you have a look at the three others scripts (checkInvariants, determinization and fsmLauncher) you will notice that the main operation of the main class takes one argument. Let's focus on "fsmLauncher.kmt" launcher. The main operation takes one parameter which is the name of the file containing the FSM model. It loads the model, prints it and runs it. If you try the running method above, an exception is raised because the parameterized file does not exist. Indeed we did not specify any filename to the program. So, you cannot use the method above to run those kind of script. That is the reason why we are going to use run configurations. Then right click on "fsmLauncher.kmt" file and select "Run As" and "Run...". A window appears like the one below. Select the run configuration named "loaderFSM" and look at the different options. Have a special look at the file parameters :
"Location of your program file", here this is "fsmLauncher.kmt" filename relative to the project's root directory.
"Class qualified name", that is to say the main class of the program.
"Operation name", that is to say the main operation of the main class.
"Operation arguments", the parameters you want to send to the main operation.
Here, we give the string "../models/sample1.fsm" as a parameter to mainLoadFSM operation to "fsm::Main" class. By clicking on "Run" button, it will start the execution. You can create yourself some new run configurations. Just by left clicking on "Kermeta Application " or "Kermeta Constraint Application" (depending on the constraint checking you want) and select "New" and fill in the required fields.
Caution | |
---|---|
Eclipse is slash sensible. It only accepts front slash and no backslash. Then /fr.irisa.triskell.kermeta.samples.fsm.demo/launcher/fsmLauncher.kmt is a valid filename whereas \fr.irisa.triskell.kermeta.samples.fsm.demo\launcher\fsmLauncher.kmt is not. |