Hi.
>> I have been reading your blog and also looked at the various plugins that
>> had mentioned in your blog.
>>
>> I'm trying to come with a plugin which should add annotations for
>> validation.
I would gladly join this project. I'm also interested in JAXB2 validation.
Actualy the only thing that holds me from switching to JAXB2 completely is the
absence of a library like jaxbvalidation (
https://jaxbvalidation.dev.java.net).
>
> Cool. Would you be interested in hosting this on
> http://jaxb2-commons.dev.java.net/ ?
>
> There has been substantial interest in this. I think other people might
> be interested in contributing to this project.
>
>>
>> For example, lets take the following schema:
>>
>> ...
>> <xs:attribute name="intValue" use="required">
>> <xs:simpleType>
>> <xs:restriction base="xs:int">
>> <xs:minInclusive value="1"/>
>> <xs:maxInclusive value="600"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:attribute>
>>
>> <xs:attribute name="stringValue" use="required">
>> <xs:simpleType name="FamilyId">
>> <xs:restriction base="xs:string">
>> <xs:minLength value="1"/>
>> <xs:maxLength value="100"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:attribute>
>> ...
>>
>> In the code, I like to add the annotation like below:
>>
>> public class MyClass {
>> public int intValue;
>> public String stringValue;
>>
>> @Min(1)
>> @Max(100)
>> public int getIntValue() {
>> return intValue;
>> }
>>
>> @Length(min="1", max="100)
>> public String getStringValue() {
>> return stringValue;
>> }
>> }
>>
>> I'm already using these type annotations in our code but I would like
>> to add
>> these in the JAXB generated code as well, so I can validate the bean
>> using
>> our current annotation based validator.
>>
>> Is there a easy way to do this? Can you please give me small example
>> of how
>> to do this? If that works, I will do the rest.
>
> Sure. The basic idea is to look at CPropertyInfo.getSchemaComponent(),
> and then determine what facets you want to copy over.
>
> Then use methods on JAnnotatable to put annotations into the generated
> code.
What is also important is the structural validation. I.e. if you have a content
model like a+ (b | c) then you should be able to check that getA(), getB() and
getC() of the class instance satisfy this constraint.
Raj, I'm pretty interested in participating - and already have quite an
experience from jaxbvalidation. I would suggest starting a new project and
continue the discussion there.
With all respect to jaxb2-commons, I guess this library deserves a standalone
project.
Bye.
/lexi