Friday, January 23, 2009

[Tech] An easy to use XML Serializer

XML processing is an important part in present software systems, especially when communicate with other software components in the IT infrastructure. Pretty often you must provide your object data as XML. The Open Source market provides a wide range of XML tools, above all XML mapping tools, like Castor, JAXB and others. A very intersting and compact tool, existing since 2004 is XStream hosted on Codehaus. XStream is a proved XML serializing library and provides the following key features:
  • Easy to use API (see example)
  • You do not need explicit mapping files, like other serializing tools
  • Good performance
  • Full object graph support
  • You can modify the XML output
Let us consider a simple business object, person, implemented as a POJO (taken from the XStream homepage):

public class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
// ... constructors and methods

public class PhoneNumber {
private int code;
private String number;
// ... constructors and methods
In order to get a XML representation of the Person object we simple use the XStream API. We also set alias names which are used in the output XML.
XStream xstream = new XStream();
xstream.alias("person", Person.class);
xstream.alias("phonenumber", PhoneNumber.class);
String resultXml = xstream.toXml(myPerson)
When creating a new instance of the person object an serialize it via xstream (toXml) we get the following XML result. As we can see our alias names are used.


The example illustrates that the framework is very compact and easy to use. Look at the 2 Minute tutorial on the XStream homepage to get more examples. You can also implement custom converter and transformation strategies to adapt XStream to your requirements.

Have fun with XStream.

Tuesday, January 20, 2009

[Pub] Data transformation in an SOA

I published a german on article on JAXCenter about data transformation in Service Oriented Architecture. When different applications talk to each other, you must find a suitable data format which all applications can interpret. For the most cases XML is the first choice, because there is a wide range of tool support and additional standards, like Schema Editors, XPath and the like.

In this article I give an overview about the Open Source Framework Smooks, which can be used for data transformation in SOAs. Smooks provide some interesting features:

  • Data Transformation (XML, CSV, EDI, Java, JSON,..) and custom transformers
  • Java Binding from any data source (CSV, EDI, XML,..)
  • Huge message processing by providing concepts like split, transform or route message fragments. You can also route fragments to different destinations, like JMS, File or databases
  • Message Enrichment
Above mentioned attributes/features are also ideal candiates where an Enterprise Service Bus can help. Rather existing Open Source ESBs, like Mule or JBoss ESB can profit from a technology like Smooks. In last part of the article I describe the Smooks extension for Mule which provides:
  • Smooks Transformer for Mule. The transformation logik is done in Smooks
  • Smooks Router for Mule. The routing logik can be configured in Smooks

Sunday, January 04, 2009

[Misc] Clean Code Developer

Some days ago the recommended .NET Expert Ralf Westphal (with Stefan Lieser) has published in his blog (which is always worth reading) about a new Software Engineering Website called Clean Code Developer (written in german).

The websites name is a little related to the book clean code from Robert Martin I recently reviewed here.

To me this website is stunning in many ways. It is the approach to bring professional development into the minds of all developers. And so it lists and explains the most important development principles on this webpage. Furthermore all tools are listed that help to achieve the goal of good development.

But the website doesn't stop here: a related forum for "clean code" discussion has been set up and they have introduced grades for every developer. So the principles have been rated and put into six grades that are associated to colors (from red to white). So every developer can learn and practice these grades and the included clean coding principles.

For those who have fun doing this you can buy a colored bangle starting from red and buying the others later for 5 €. The idea is to remind yourself always writing clean code. Whether you like the last idea is up to you. But this website really bridges an educational gap: at the university you normally learn programming and something like design patterns in an advanced software engineering course (beside of tons of UML). You nearly never learn good coding principles although many of us will code in
their later career.

So as my new years recommendation I would be happy if you can check out the website given above and join the idea of a clean code awareness.

Let this be one of our answers to the financial crisis.