XSnapshot

The goal of XSnapshot is to provide a complete, easy-to-use but powerful framework for working with the data transfer object pattern in Java, primarily for web applications/web services. The data transfer object pattern itself is a generalization of the value object pattern described in most basic J2EE/EJB books. As it turns out, the latter pattern is applicable to more than just sending/receiving data from entity EJB's; some other examples where it's useful include SOAP services, working with O/R frameworks, and working with presentation layers such as Struts. Some of these use cases have previously been addressed by tools such as the Value Objects module of XDoclet and BeanUtils, but these are quite limited in their functionality. XSnapshot aims to provide a complete solution to defining and working with data transfer classes.

At this stage, XSnapshot is primarily an XDoclet module. It provides a set of XDoclet tags that allow you to define a data transfer class (which we call a snapshot) based on a domain model class (which might for example be a Hibernate-persisted class). Based on the XDoclet markup, XSnapshot will then generate the snapshot class and a helper class that converts between the model class and the snapshot class. XSnapshot also includes a set of classes to help in configuring it at runtime and performing the conversions.

XSnapshot has a number of advanced features not found to our knowledge in any similar framework:

  • class hierarchy support. XSnapshot allows you to create hierarchies of snapshot classes that parallel the model class hierarchies.
  • collection/array/map support. XSnapshot has a powerful syntax for performing conversions on individual keys/values/elements of map/collection-valued properties when converting between snapshots and models.
  • type conversion. This is similar to the BeanUtils type conversion, but more powerful.
  • beanutils-style property references. This is a simplified method for defining transformations that allows you to flatten object graphs, for example converting a reference to an entity object to the id of that object.
  • equals/hashCode/toString/compareTo generation. XSnapshot makes it easy to create snapshot classes that obey the Object contract by generating the supporting methods based on simple markup.
  • spring integration. XSnapshot includes a Spring Factory bean that makes it easy to integrate when running the Spring container.

While currently XSnapshot works only as an XDoclet module, we intend to in the next release define an xml descriptor format similar to that of Hibernate to provide an alternative means for defining snapshot classes (and the only one that can work when the original java sources are not available). The XDoclet module will then be refactored to generate the xml descriptors rather than directly generating the snapshot and helper classes.