Java News from Saturday, March 22, 2008

Sun has posted the early draft review of JSR-303 Bean Validation.

Validating data is a common task that occurs throughout an application, from the presentation layer to the persistence layer. Often the same validation logic is implemented in each layer, proving time consuming and error-prone. To avoid duplication of these validations in each layer, developers often bundle validation logic directly into the domain model, cluttering domain classes with validation code that is, in fact, metadata about the class itself.

This JSR defines a metadata model and API for JavaBean validation. The default metadata source is annotations, with the ability to override and extend the meta-data through the use of XML validation descriptors.

The validation API developed by this JSR is not intended for use in any one tier or programming model. It is specifically not tied to either the web tier or the persistence tier, and is available for both server-side application programming, as well as rich client Swing application developers. This API is seen as a general extension to the JavaBeans object model, and as such is expected to be used as a core component in other specifications. Ease of use and flexibility are influencing the design of this specification.

I have to read further, but at first glance it seems to be a weak version of Eiffel-like preconditions. I think a system that enforced preconditions and class invariants without regard for Javabeans naming conventions would be a much better idea, and probably simpler all-around to boot.