Sunday, March 1, 2009

Generating Strongly-Typed Properties Classes With openArchitectureWare, Part 2: Model

Previously I demonstrated how to create an Ecore metamodel describing Java .properties files, with the ultimate goal of using openArchitectureWare to build strongly-typed accessor classes for my properties. Before I start writing oAW templates, though, I want to have a sample model that I can work with which is relatively simple but still exercises most of the breadth of my metamodel.

The oAW sample project contains a model already called "Model.xmi". The "xmi" is "XML Metadata Interchange", an OMG specification concerned with interoperable models, and the default format for models in Ecore/EMF. I will delete the existing Model.xmi file and create a new model called "SamplePropertySet.xmi". One way to do this is to open the Properties.ecore metamodel, right-click on the class that I want at the "root" of my model (namely, PropertySet), and select "Create Dynamic Instance". Choosing a location in my workspace, away I go.

The .xmi file can be edited with the "Sample Reflective Ecore Model Editor", which is essentially the same as the tree-node-properties editor I used on the .ecore file, except now the entities that I edit on my model are instances of the classes and attributes defined in my metamodel. In other words, the "root" of my model is a PropertySet, and to that I can add children which are Property instances. When I select one of these and open the Eclipse Properties grid, the properties are the class attributes defined in the metamodel. If you have been following along and are still a little fuzzy on the relationship between metamodel and model, the following illustration might be helpful:

I'm going to test my openArchitectureWare code generation templates with a couple of properties -- one of type "Integer" and another of type "String". My "completed" model looks like this:

There are a number of other things that I could do with EMF at this point, such as generating a Java object model and "starter" Eclipse plugins for working with my models. But I don't need to do any of that for this project: Starting next time, everything going forward will be in the Land of openArchitectureWare.

1 comment:

Unknown said...

Hey Scott--
It's been a long time since we've spoken, or even seen each other. It's funny, just the other day, a friend of mine was telling me about somebody that shares your last name, and it made me think of you. I googled you, and here you are. Anyway, it looks like you and your huge brain ended up doing some very interesting things. I'm really glad to see you are so successful in your field.
I'm living in Santa Monica, CA, and I'm a personal trainer. After retiring from professional bicycle racing in 2005, working in an office just wasn't for me. So now, recess is my job!
My email is if you want to keep in touch.