Validating Objects Through Metadata
Subject:   Sounds nice, but...
Date:   2005-01-20 07:51:23
From:   hookomjj
Response to: Sounds nice, but...

In general, with the simplicity of baking your configuration data into the Java source file, you lose the flexibility to make changes to the configuration data without recompilation.

Ant deploy scripts and team production cycles, make modifying of configuration files vs. java files with recompilation a moot point in my experience.

How slow is the reflection involved in the public static void validate() method?

Since we are dealing with compiled annotations, just like caching reflected properties of beans (quite common), I could also see caching of validation data on a per type basis. The reflection only occurs once then, caching both the annotation state and the ValidateHandler. If you look at how much reflection already exists within frameworks, reflection for annotations (once) really isn't that big of a deal. I left it out of the sample code as to not confuse the meat of this implementation.

Is the complexity worth it?

As stated in goal of this example framework, the end result is extremely easy for developers to grasp (just drop a @ValidateRequired). Developing new JSF validators w/ tag support is just as complex as adding a new annotation (not that either is overly difficult IMHO).

Along the lines of coupling framework behavior such as validation to beans-- based on the fact that annotations are "read" from objects, not "written", the coupling framework metadata won't affect the generic goals of your business objects.