MOXy BeanValidation gives me the ability to add validation to my JAXB classes.
Using MOXy's "Bean Validation Plugin" I can have Bean Validation in generated JAXB classes based on restrictions/facets from a prexisting Schema.
However is there any way of generating a schema with restrictions/facetsbased on Bean Validation annotations from a JAXB annotated java class?
XJC has a handy plugin architecture when doing 'schema first' generating java, but is there any equivalent 'java first' way to enhance the generated XSD with additional restrictions, or even to add XML comments ? Either in MOXy or JAXB-RI?
MOXy is extremely flexible with meet in the middle mappings, can this be used during schema generation?
The jaxb-facets project seems to do what I want but the implementer had to fork an entire new JAXB-RI to get it in and it seems that it won't be adopted any time soon.(See this Java JIRA)
I tried the resolution specified by @m0mus but had to use the 2.7.0-SNAPSHOT versions from the sonatype repository. I still had a couple of problems; 1. I had to annotate the java fields with @XmlElement to get the facets to appear in the xsd. @XmlAttribute, @XmlAccessorType(XmlAccessType.FIELD) made no difference. @Pattern did not work; I had to work around with a single Pattern in Pattern.List;
@XmlElement
@Pattern.List(value = { @Pattern(regexp="[0-9]*") })
public String phoneNumber2;
For more info see the EclipseLink Forum