Although we see many advantages in using (free) open source tools or frameworks we keep our eyes open to check whether the chosen open source solution is best for our customer.
We recently had a situation where we preferred a commercial solution over an open source one.
For a specific interface, we had to map a CSV file to an XML file and this transformation should be processed by the Mule ESB. At first we looked at Smooks to tackle this issue, as I described here. It resulted in a workable solution, but as you can read in post, the transformation had to take place in two steps: first from CSV to simple XML format and secondly, a transformation from the simple XML to a more advanced XML schema. For this second transformation we made use of an XSL stylesheet. We created the XSL file used for the transformation by making use of Altova MapForce.
However, MapForce can do a lot more then this simple XML to XML mapping. One of the things it can do is map CSV directly to (advanced) XML. This can’t be done with just a XSL translation anymore, but MapForce can generate Java code to perform the transformation at runtime. In this post I will show how you can use MapForce to generate the code. In a next post I will show you how to combine this generated code with the Mule ESB as a transformer.
The CSV file for this example looks like:
The ‘com.altova’ package contains ‘generic’ code that is necessary for each MapForce mapping in Java. It contains global types, functions and so on.
The ‘nl.redstream’ package is the package name we configured. This one contains the code that is specific for our mapping.
To run the code after you build it you can use the following command:
Unfortunately by using the generated Main classes, the transformation can only be done on the files that where used as input for the mapping in this code. In the next post I will show how to use this generated code and use it as a Transformer in our Mule application.
For a lot more info about the Java generation possiblities of MapForce look here.