Every WEF developer eventually faces a situation when the data connected to the service provider doesn't quite match the user interface. There are
several transform builders that can be used, but sometimes the task of doing the transform can be offloaded to a java developer if the data
can be converted to java beans. There is additional builder support for converting from java beans to IXml, but none for IXml to java. In this
article I will be sharing an eclipse plugin I created to easily unmarshal IXml to java.
Extracting the Schema from a Model
Creating JAXB classes that will enable us to marshal/unmarshal is easy enough using the xjc utility if we have a schema, but in WEF the schema
are stored in the model. We can use the plugin to extract these schema and then run a script to generate, compile, jar and copy the results to the
project's WEB-INF/work/lib directory.
The plugin produces two output files in the console:
The jar files are copied to the project and will get picked up in the designer classpath. The project may have to be refreshed with the file system (press F5).
Using the JAXB Code
If we have contacts xml that looks like this:
that needs to be converted to items xml that looks like this:
we can use the following code:
Since we are simply manipulating java beans and not XML, it is very easy to add business logic to the code. We can also make use of
open source bean libraries such as apache commons beanutils (http://commons.apache.org/proper/commons-beanutils/).
Installing the Plugin
I usually like to use an automated install for my plugins, but I don't have the time right now. Instead just unzip into the eclipse/plugins
directory and restart eclipse with -clean flag. Looks like I can't upload a zip to this wiki so I'm putting the file on my website instead.
Re: Transform IXml with JAXB
I have used this plugin to merge two different IXml objects and it saved time and made the task of merging and enriching the data straight-forward.