views:

188

answers:

1

Let's say I have an annotation JSR 303 class like this:

class A {
    @NotNull
    private String b;

    @Min(5)
    @Max(10)
    private int num = 3;

    @Pattern(regexp="[0-9]*")
    private String foo = "12345aa";
}

How can I take that class and generate a validation.xml which contains the same constraints as those that are specified by the annotations?

A: 

The idea would be to write your own annotation processor. The hard work is to map the annotation to the xml equivalent. There are some examples you could look at on how to write an annotation processor. For example Hibernate Validator uses annotation processing to give developers the ability to verify their constraint placement during development (see ConstraintValidationProcessor). Or have a look at Hibernate's JPA2 Metamodel Generator. AFAIK there is no tool out there yet which does what you want. Btw, why do you want the xml?

Hardy