dwaite wrote:
The metadata to constraint is analogous to marking an interface with the implementing class for the system. It certainly makes a user implementing a new constraint easier, but makes 'standard' annotations need to have either standardized implementations or per-vendor implementation packages.
To put another way, it could also be considered analogous to dropping the ConstraintValidator classname completely and requiring the annotations to instead have an inner class called ConstraintImpl that implements them.
Actually this is not entirely true. Becasue @constraintValidator is an interface, it will not result in a CNFE at runtime (you still need the class at compile time though).
WRT the standard annotations, you are correct and we are talking about introducing some XML mechanism to softly link an annotation to a constraint implementation. The primary goal is to allow the spec to declare built-in annoations but let the different providers to bring their own implementation (less bug in the spec :) ).
Quote:
dhanji wrote:
In any event, you can use xml instead of annotations to bind the validator if this is uncomfortable to you.
Also, there is a constraint factory for integration with third-party dependency injection libraries like Guice, and others, which uses the class as a key to retrieve the instance. Depending on the factory implementation the constraint could refer to an abstract class or interface (with no impl details).
(Since ConstraintFactory today has no tie into validator or any other part of the system, I'll assume that will be possible later)
Yes, there are ways around this, but they are very gross. I would have to have a constraint factory that knows the per-vendor implementation details to know which class type to return a different implementation for. This is why I suggested having the factory instead take the annotation itself.
For standardized constraints, I would expect an implementation to know its implementation of the constraint validators anyway. Perhaps making the ConstraintValidator class parameter optional, so it could be omitted for standards-defined constraints?
See my comment above. Note that providing the annotation to the constraint factory is not a good approach as it would externalize the discovery mechanism: this mechanism should be well defined and standardized which mean handled by the bean validation provider.
Let's dream a bit.
In a perfect world, I would like the @ConstraintValidator annotation to be reversed and placed on the implementation rather than the annotation constraint. But it requires to either:
- list all the constraint implementations in an XML file
- do some kind of scanning
The scanning does not work for this spec as there is not well defined scope to look at.