Monday, June 26, 2006
Rationale for orienting the API around JAXB.
In Java there are many ways of handling XML: SAX, DOM, StAX, JAXB, etc. This post attempts to outline a rationale for orienting the APIs within TReCX around JAXB in particular.
- standard mature API (due to become "core" in JDK 1.6 "Mustang").
- allows for symmetry i.e. reuse, in the implementation of the publish and store modules. Put another way, the inputs and outputs should be the same, as we're using the same classes on either end!
- allows for separation of XML and persistence layers. This makes unit testing easier.
- the JAXB generated classes form the POJOs that are then enhanced via JPOX to form the persistence-capable classes used in the persistence layer. (At runtime, the classes used by JAXB to perform unmarshalling / marshalling and the ones used by JPOX to handle persistence are one and the same. The persistence-capable nature of the classes is effectively "invisible" to the JAXB runtime).
Put another way, JAXB is more object-oriented and more closely integrated with Java.
Equally, however, it should be noted that if at some point in the future it would make more sense to implement the store module based on something like StAX, for performance or other reasons, then that should be perfectly sensible and possible. It just wouldn't be "symmetrical" with the publish module any more. However, by that stage, the JAXB implementation should have proved it's worth and done it's job!