Model Driven Architecture presentation
I am working on a presentation on Model Driven Architecture, and I think the best way to explain how it works, and the benefits it brings, would be to start by showing an actual example.
I don’t really want to go through the boring usual examples using Eclipse and Java, even if it is powerful. So I though about using Rails’ amazing scaffolding scripts.
Model Driven Architecture is a set of processes defined by our dear W3C. They show how to go from a diagram to an actual, working, plateform-specific implementation code. That technique is extremely useful for big projects as it saves thousands of lines of code. It provides a working, out-of-the-box skeleton application.
In order to show how great MDA is, I wanted to create some application that takes an UML diagram as an input, and a Rails website as an output.
First, how to feed a UML diagram to a program? That step is pretty easy. XMI, or the XML Metadata Interchange is a format to exchange Metadata, which is what UML diagrams are.
To parse that XMI file, I wanted to try Why’s Hapricot gem since I’ve heard how convinient it was. And indeed it is. The API is really expressive, and parsing the XMI file was nothing more than that:
@doc = Hpricot::XML(File.open(file, 'r'))
classes = Hash[(@doc/'uml:Model'/:packagedElement/:packagedElement).collect \
{|a_class| [a_class.attributes['name'], (a_class/:ownedAttribute).collect { |a| a.attributes['name'] }]}]
Doing this, I had access to all the classes and attributes of my XMI file. I only needed to map them to the rails scaffolding script.
In order to have something visual during the presentation, I used the Shoes GUI kit for ruby. I have nothing against command lines, but Shoes is so easy to use. The total program takes only 34 lines of code, GUI included.

I’ll probably post the slides of the presentation when they’ll be done.
()
