Hi,
>> Recently I did some experiments. I can imagine a JAXB 2 plugin which
>> analyzes the schema and generates JSR 303 annotations which describe
>> how the bean must be validated. In this case bean validator may report
>> XML Schema validation errors with locations in the object structure.
>
> In what way would that be better than the XML schema based
> validation?
If you work with objects in first place then information "your object
is missing the required [name]" property" is more valuable than
"required attribute @name is missing in the element foo". It is
important to know "where" an "what" applied to objects, not to XML.
If you're XML centric then emphasis is different, schema-based
validation of XML is more important.
>> However the task is rather difficult.
>>
>
> You are certainly aware that validation goes beyond checks of individual
> properties of (individual) elements.
Of course.
As far as I see there are actually several levels of validation:
* Facets - basically for simple types, this can be done per-property.
* Simple structure validation - simple complexType/sequence/element*
may be expressed as @Required, @MinOccurs, @MaxOccurs.
* Complex structure validation - complex cases with heterogeneous
properties, element references, wildcards and so on. Not sure if it's
possible and it's surely quite complex.
However one thing must clear from the theory point of view. If you can
use an XML Schema in runtime to validate XML then it must also be
possible to express the same constraints on the class level
(validation annotations) to validate object structure corresponding to
that XML. It may be hard but it is possible.
> Recently I investigated the application of rule based programming
> for this task, which is quite satisfying as it permits the definition of
> the validation rules in a way that's akin to domain expert language.
> And there's practically no limit to the complexity of validation rules.
You can always add custom validation annotations, I don't see any
constraints here. JSR 303 is a very sensible thing.
Bye.
/lexi