A couple of years ago, I decided to use JAXB for parsing an XML configuration file. There were a lot of other ways to do it, but I liked the strongly typed object references it gave to my runtime classes. I wasn't concerned about performance, since it was only going to be used onced -- to unmarshall a single configuration file at application startup. I looked at a couple of the implementations of the JAXB spec. Sun's reference implementation was commonly used, but I liked the way that Apache's JaxMe worked better. It had some nice JAXB+ extras I liked as well, even though I didn't plan on using any at first.
Two years later I find myself considering using JAXB once again. My use for JAXB would be a lot different this time around. I thought it was good time re-evaluate some of the JAXB implementations.
JaxMe has not changed much in the two years. In fact, I had upgraded the version of JaxMe that the app I wrote two years was using, so I had already used its latest. It had improved in quality quite a bit, with many "features" (support for advanced XSD constructs) added and bugs fixed.
I took a look at Sun's reference implementation, JAXB-RI. The biggest change with it is that it uses Java 5 Annotations to greatly reduce the amount of code generated from a given schema. This is really nice. Now there's no need to generate a separate SAX handler for every complex type, and of course there's no configuration file mapping complex type -> Java class and complex type -> SAX handler. It also no longer generates separate interface and implementation class for each complex type.
Of course this is exactly why Annotations were introduced, to simplify boiler-plate code. The generated code is simple and clean. It has no dependencies on anythin JAXB-RI specific, just the Annotations that are part of th JAXB spec. It would be asy to take an existing class, add some of these annotations and use JAXB to generate XML.
So kudos to the JAXB-RI team. There are still some areas for improvement, but this is a very nice improvement on a useful technology.
No comments:
Post a Comment