Strongly typed thank you!
This weekend I set out for doing a Rational Rose file import plugin for Modlr. I wrote the code that successfully traversed the rather strange file format that they use. Rational Rose is a pre-xml product:
So when I had all that done I thought that it would an easy and quick task to wrap that information into a model designed in eco so that I could populate it with objects from the file. Once that was done I planned to write the code that transformed from that rose model to the eco modellayer model…
But I immediately got super tired when I realized that I had to create some 30-40 classes with a lot of attributes and relations all by hand in order to hold the rational rose data from the file…
It seemed silly that I would need to do stuff by hand at all. After all we are the tool making species! So I started to think that this is a common scenario – I have a description, or data adhering to a description, in one format, and I want to have that as a model so I can code towards it with strongly typed classes ( the older (and wiser?) I get, I get increasingly more allergic to scripting ).
So if this is a common problem that at least I come across from time to time maybe I should solve that first?
I asked myself what format the data I need to handle usually come in : XML.
So to avoid losing focus of my initial problem all together I used my Rational Rose File decoder logic and made it spit out the same information as XML:
The general idea was to write a plugin that given this XML, or a similar XML, or preferably any XML, could derive a model for me, saving me from doing stuff manually.
I know that some of you are thinking “oh boy this guy is writing a plugin in order to write a plugin in order to convert a rose file?”, and yes you are correct. But one plugin will be very generic – taking almost any XML and turning it into a modlr model.
So nothing fancy:
And the magic of the plugin:
The logic to actually create a Class, an Attribute or a Relation looks like this:
I tried the logic on several different xml files that I found in my temp folder and found some special cases. This lead me to the conclusion that I needed at least two different strategies: one where the xml element has a generic name and the real name is given in some attribute. One example of this is the EcoMdl file format:
But the more common scenario is the format where the xml elements have specific names. Like the pad format:
I added a window that pops up when executing the plugin, it lets you pick the xml file, choose strategy, choose target package and GO:
And it gave me this (I dragged them onto the diagram myself)
Puh, now when I have a good starting point for the rational rose object model I can back to my original task… But that will be some other day…
(the plugin is in the demos folder for the next available eco build and it is called PluginXmlToModel)