Recently I ran into a problem that seemed perfect for EMF to solve. Typically, I’m not a model driven development person, but I need a model for an XPath expression after it is parsed. Various information needs to be tracked, and the annoyances with Xalan and JAXP finally drove me to go the custom route. It’s amazing how difficult it actually is to find an XPath 1.0 tokenizer that actually exposes the API for walking through the tokens of an XPath expression. I looked at a wide variety of grammars, and finally found a nice EPL compatible parser from the JXPath Apache Commons project. Xalan hid most of it’s goodies under protected or package level methods only. Making it utterly useless for using outside of Xalan for any other purpose than Xalan.
So, with JXPath as the tokenizer, this opened the door for finally getting to the pieces necessary to populate a model. The model is necessary to help provide some advance functionality for Content Assistance for the XSL Tooling project. In particular Hover Help, recognizing the return DataTypes, the allowable data types for a function’s arguments, how many arguments may it have, etc. However, I didn’t want to write all the necessary modeling code myself. It’s do able, but just not something I wanted to do.
So, with Ed Merks channeling Locutus of Borg, “Resistance is futile…”, I started drinking the EMF Kool-Aid.
I managed to get a fairly simple model working to hold the key pieces that I needed. A few stumbling blocks have occurred, mainly due to my own learning curve with EMF, but so far so good. The one thing I did find odd, is the ability to generate the Tests for the model. While this does provide a suite of tests to test the model, it doesn’t necessarily give you a good test suite.
Let me clarify this last statement. The assumption is that you modeled it correctly. However, if you forgot something in your model like a required field, or you have the name of the field wrong in the model, the test suite will be wrong as well.
Instead of opting for the test suite to be generated, I just generated the model code, and have been writing some basic tests myself to test the functionality and design. Using this method, I’ve been able to actual uncover several test failures because I had the model wrong. So far I have written no code in any of the core XSL plugins to use this model. Hopefully, taking this approach will save me from having to do any major rework due to having a to rework the model in the future because I forgot some functionality.