Creating MDELite Tools using Catalina
Corrections in Green
Find a partner and form a group of two (if you can). As a group you will make one submission. Download a fresh version of MDELite8 (as I had to modify it for this assignment), unzip it and follow the installation instructions. Doing so, you should be able to run Catalina
> java MDL.Catalina
Usage: Boot.MDELite.catalina option args...
all state -> java
validateViolet state -> T/F
validateMeta state -> meta
quick meta -> java
Next, you should read the Catalina manual, which is in the Docs download of MDELite8. There are two different problems in this assignment: you are to complete the construction of 2 MDE tools.
Overview of Part A: the V2YTool
Here is an annotated category diagram for an MDE tool, called Tool.V2YTool, that translates Violet class diagrams into Yuml class diagrams. If you click the diagram, you'll see its violet XML file.
You can't build the Java source of this tool until you have completed Part 1 of this assignment, which is the v2y model-to-model transformation. Ultimately, you will be able to draw a class diagram in Violet (like the on in the left diagram below) and produce the gorgeous Yuml diagram on the right.
violet class diagram
| yuml class diagram
|
|
|
Part A.1
The category diagram of Tool.V2YTool has 5 arrows and two database domains whose schemas are in MDELite (libpl/vpl.schema.pl and libpl/ypl.schema.pl).
Four of these arrows are already written, as they are part of MDELite:
arrow name
| Java Executable
|
parse
| Violett.KlassParser |
VPL conform | Violett.ClassConform |
YPL conform | Yuml.ClassConform |
unparser | Yuml.ClassUnParser |
What is missing is the M2M translation of a Violet database that encodes a class diagram to a Yuml database that encodes that diagram. You are to write this tool. I have created a NetBeans project shell to get you started. Here is the shell. You complete the M2M.v2y program contained within it. Add your own test programs.
- Note: there are other directories in this shell, like toDP and toNS. Ignore them. Just focus on the M2M.v2y program.
Once you get this program working, place it and MDELite on your classpath for Part 2.
Part A.2
Complete the Tool.V2TTool tool. Here is the Violet state diagram that specifies the above V2YTool category. You can now build the source of the tool by:
> java MDL.Catalina all V2YTool.state.violet
Where file V2YTool.state.violet is in the directory in which you invoke MDL.Catalina. The source V2TTool.java is produced by the above call. You can't quite compile this file as is. Follow these steps:
- Create a directory called Tool, and drag V2TTool.java into it. As long as MDELite and M2M.v2y programs are on your classpath, you can compile V2TTool.java.
- Once you're satisfied that this has been accomplished and that you can invoke your tool, move up one directory (so that Tool/ is in your current directory).
- Get example.klass.violet file, and run:
> java Tool.V2YTool all example.klass.violet
to produce file example.yuml.yuml, whose contents you can copy into the yuml.me class diagram window to produce the yuml diagram above. example.yuml.yuml might look like:
[Class|name|]
[AssociationEnd|roleName;visibility;cardinality|]
[Attribute|name;visibility|]
[Class]++-[Attribute]
[Association]++-[AssociationEnd]
[Class]++-[AssociationEnd]
- Note 1: I have partially written the M2M.v2y program. You have to do the rest.
- Note 2: Violet produces class diagram files whose name is X.class.violet. Because of the naming convensions that MDELite uses, there is a conflict. So to get around this conflict, whenever you create a file X.class.violet using violet, rename the class to be X.klass.violet. You can then submit it to the V2YTool above for translation.
Overview of Part B: Completing the FSMTool
There are many ways (read: infinite) in which FSMs can be encoded in Java. The most common are:
- encode graphs as matrices
encode graphs as nested switch statements; the below is typical:
switch(current_state) {
state one: switch (target_state) {
case one: illegal(one, target_state); return;
case two: got(target_state); return;
...
}
public void goto(State next) {
current_state = next;
}
public void illegal(State here, State there) {
System.err.format("cannot transition from %s to %s\n", here, there);
}
Use design patterns to encode FSM
Here is the Catalina spec of a tool that allows its users to translate FSMs to "nested state machines" or "State design pattern". Click the figure below to see the Violet FSM spec for Catalina:
CORRECTION: SEE ABOVE FIX IN BLACK
In the Netbeans shell that I gave you earlier, I created two src directories: src/toDP and src/toNS. Look at the code in src/toDP/Main.java. It sketches a RB program that you should elaborate to produce a design pattern encoding of a FSM. Copy this shell of a program to src/toNS, and write an RB program that translates to a nested state machine. OR a matrix-driven program. (If you do all 3, you get extra credit). You may need to rename the RB programs (and maybe add one more arrow) to the above spec.
Now, the constraint that ties all of these implementations together is a program (which you can change below). it should work no matter which implementation has been generated:
enum states { start, Ready, Drink, Eat, Yell, stop }
public static void main(String... args) {
DEH fsm = new DEH(); // fsm is in start state
fsm.goto(Ready);
fsm.goto(Yell); // transition ignored, stays in Ready state
fsm.goto(Eat); // chow time
fsm.goto(Drink);
fsm.goto(Eat);
fsm.goto(Drink);
fsm.goto(Eat); // chow time
fsm.goto(Drink);
fsm.goto(Ready); // transition ignored, stays in Drink state
fsm.goto(Yell);
fsm.goto(stop);
fsm.goto(start); // transition ignored, stays in stop state
}
DEH is a java class that you will generate for the following FSM of my eating habits. Click the image to retrieve the state.violet XML file:
Your task is to:
- write two different RB Model-to-Text scripts to produce two (or maybe 3) java programs that implement FSMs. Doing so will complete the FSMTool.
- The constraint on these programs is that they are largely interchangeable -- they offer the same programming interface to create a FSM and trigger advances instate.
- You'll produce these two programs and use Catalina to build your FSM tool; ideally build a couple more FSMs.
What to Submit
- a single zip file that unzips into <yourName>/<yourFilesAndDirectories> (I will return submissions that do not satisfy this constraint)
- a PDF file that convinces the TA that your program works, works on violet class diagrams that you yourself have created.
- Explanation how to run your tool.
- A bash-script called run.script that will run your examples (so that it is easy for me to see what you have done).
- Repeat 3-5 for part B.
A critical part of any design is clarity and understandability. Hence, you will be graded on the clarity of your project and its ability to work correctly. Sloppy code, documentation, or anything that makes grading or understanding your program difficult will cost you points. Beware, some of these "beauty" points are subjective.
Remember: No late assignments/submissions will be accepted.