Generating An Allegory Package

Additions/Clarifications are in red and newest in green
In a lecture on MDE, I talked about allegories as a category theory representation of a class diagram.  In this assignment, you will work in pairs to:

STRONG ADVICE

I have implemented this application (recently) in two ways.  Below I give my strongest recommendations -- you are hereby warned of disaster on this assignment if you do not follow these guidelines.
  1. Consider the example in the class lectures -- the one (PDD) about Persons, their children, Departments that they work in, and Divisions that have these Departments.  Here's its Violet depiction. Note that I have made explicit the names of the identifiers in every class.  And yes, the translation of the class diagram to a set of tables is slightly different than the rules I provided you.


  2. Hack -- yes, hack -- a prototype of the PDD allegory program in Java.  You should answer these questions (queries) in your design:
      1. print all persons whose name begins with 'd' or 'p'
      2. print all divisions in which don works
      3. print all persons that work in the same department as priscila
      4. who are the division colleagues of priscila
      5. print the children of employees that work in this company
  3. Literally, make your hacked program work -- have it correctly answer the above queries, and make a regression test of it when you are done.
  4. Beautify your hacked code -- make it look as clean as possible. Make it look as generated as possible (meaning that the amount of information you need to produce exactly your hand-written code is minimized).
  5. Only after you are satisfied with the last step (3), automate the writing of this code given its Violet class diagram specification, which you can use Violett.ClassParser to trans.ate into a vpl database.
Remember the Fundamental rule: you can't automate something that you don't know and understand.

Finally, if you do not have time to write a PDD program yourself, use this program to study -- see why it works using this input.  

Here is a test program that you can use to read the input file and run a set of queries on this input to see that the PDD program I gave you works.

Part 1: Violet Class Diagram Specifications and Conformance

Violet is general enough to be useful in specifying a class diagram that has the needed details for an allegory package.  Here are the conventions that you'll need:

Notation in Class NotesNew NotationEquivalent New notation with Cardinatlities
No cardinalities permitted

On the left, you'll see the notation I used in my lecture notes as drawn by Violet.  The middle column shows the new notation and the right column is the new notation with cardinalities.  But for one exception, here's nothing really "new" about the "new" notation -- it too is standard in UML.  I just use a non-redundant version of UML notations, and both the "old" and "new" are not redundant.  To summarize the changes:
Violet remains unchanged.  It is how we draw diagrams is differnt.
You will need a MDELite Java program,  to validate these class diagrams.  You can use the standard Violet.ClassParser.java file to translate a Violet class diagram file into a vpl database.  There exists an MDELite Violett.ClassConform.java program, but the contraints will need to be changed.  The current Violet.ClassConform throws errors if associations have middle labels.  It also doesn't understand cardinalities, as described above.  So your first taks is to cannibalize Violett.ClassConform and make it enforce the correct model constraints.

What to Submit for Part I

This is going to sound really strange.  But do Part I last.  By the time you finish the next two Parts, you'll know exactly what constraints you will need to check.  Start with "obviously" correct Violet diagrams, and translate them into "obviously'" correct VPL databases and proceed to Part II and III.  It took me about ~2 hours to cannibalize Violett.ClassParser to do what I needed.  It really isn't much; the challenge is figuring out how to express constraints given the MDELite package. Given this oddity, here's what you need to submit for Part I:

Part II: M2T Transformation of a VPL database to an MDELite Database Schema

Next, you need to generate an MDELite database schema from a VPL database.  I did it twice -- first using only RB to print database schema declarations line by line:
dbase(example,[tab1, tab2, ... ]).

table(tab1,[attr1,attr2...]).
...
I then realized that I had spent far too much effort in doing so.  The alternative, which I give another strong recommendation, is to use MDELite to construct a database schema programmatically.  So your code will more likely look like Example 3: Constructing Schemas in the MDELite document M2MPrograms.html.  The last couple of lines in this M2T program will look like:
PrintStream ps = getOut();    // get the RB PrintStream object
dbs.print(ps); // dbs is a DBSchema object which you will create; this line prints it out
// to the RB PrintStream
You're going to need some hints: Please refer to the code listing in the AllegoryDemo.html document to see exactly the code I produced.  

What to Submit for Part II


Part III: M2T Transformation from a VPL database to Java Programs

Read AllegoryDemo.html in the MDELite document directory.  It is a first-approximation for what you are to generate. If you followed my STRONG ADVICE, you will have written something like the Allegory demo -- or frankly something even better. Let X.vpl.pl be a constraint-checked VPL database. You will use RB to write your M2T transformation that does the following:
Should you generate a single class X.java that contains all of the above classes, you're done.  If you generate multiple Java classes, you'll have to put them into a package X, where file X.java (above) will be renamed to database.java.  Here is an outline of how I generated this code:
public class VPLSchema2Java extends RunningBear {

static String q = "\"";
static DBSchema dbs;
static Table dual;
static String appName;

public static void main(String... args) {
// Step 1: standard marquee processing
Marquee2Arguments mark = new Marquee2Arguments(Vpl2Schema.class, ".schema.pl", ".java", args);
String inputFileName = mark.getInputFileName();
String outputFileName = mark.getOutputFileName();
appName = mark.getAppName(mark.getInputFileName());
openOut(outputFileName);
appName = mark.getAppName(mark.getInputFileName());

// Step 2: open tables of database and create empty schema
// and read dual file
dbs = DBSchema.readSchema(inputFileName);
dual = Table.readTable(appName + ".dual.csv");

// Step 3: generate file
header();
mainClass();
common();
classes();
footer();
}
}

Here is a test program that you can use to read the input file and run a set of queries on this input to see that the PDD program I gave you works.
So, download all 3 files above, compile both java files and run Main.java given the input file as a command-line input.  You'll see the output.  Make sure that you produce the same (or isomorphic) output.


What to Submit for Part IIII


What to Submit to Canvas

  1. a single zip file 
  2. the request for Part 1
  3. the request for Part 2
  4. the request for Part 3
  5. remember to put your name and email address at the top of your submitted PDF file.

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.