Metadata-Based Validation

This Artima article links to an IBM developer works article which details how validation in
one place in an application can extend throughout different parts of the
application.  I’ve wanted something like this ever since I played with
Modula-3 in college.  Modula-3 made it so easy to create new constrained
types that I finally saw the power of such constraints.

My dream of a system would work something like this:

1.  Define your data objects and include something which contrains this
data.  In Java this could be annotations.  In .NET this could be
attributes.  In other languages, or pre-annotations Java, it could be
something else, it doesn’t matter, but annotations/attributes definitely make
things easier and nicer.

2.  If I am mapping to a database, the ORM should read these attributes
and contrain the data at the database level.

3.  If I create a UI (web, console, windows, gnome, applet, it should
not matter) certain control types should be infered and other control types
should be validated.  For example, if I have a data member which is an
enum of three values, a textbox is probably not the best input control.  A
drop down with three values, or three option boxes may be better.

4.  If I create a non-U-I (a non-user Interface) (web service?) the
contraints should be enforced, preferably at the service layer.

I would really love this.  Scaffolding would be far more useful with
this type of Metadata in my objects.  People directly accessing underlying
databases have less chance of inserting or modifying data to “garbage”. 
Contraints were pushed down to the database level.  Of course, ideally no
one would connect to the database directly, but the real world is not ideal.

http://www.artima.com/forums/flat.jsp?forum=276&thread=175992&start=0&msRange=15

http://www-128.ibm.com/developerworks/java/library/j-hibval.html