1 package ejava.jpa.example.validation;
2
3 import java.lang.annotation.Documented;
4 import java.lang.annotation.Retention;
5
6 import java.lang.annotation.Target;
7 import static java.lang.annotation.ElementType.*;
8 import static java.lang.annotation.RetentionPolicy.*;
9 import javax.validation.Constraint;
10 import javax.validation.OverridesAttribute;
11 import javax.validation.Payload;
12 import javax.validation.ReportAsSingleViolation;
13 import javax.validation.constraints.NotNull;
14 import javax.validation.constraints.Pattern;
15 import javax.validation.constraints.Size;
16
17
18
19
20 @NotNull
21 @Size
22 @Pattern(regexp="")
23 @ReportAsSingleViolation
24
25 @Documented
26 @Constraint(validatedBy={})
27 @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
28 @Retention(RUNTIME)
29 public @interface ValidName {
30 String message() default "invalid name";
31 Class<?>[] groups() default {};
32 Class<? extends Payload>[] payload() default{};
33 @OverridesAttribute(constraint=Size.class, name="min") int min() default 0;
34 @OverridesAttribute(constraint=Size.class, name="max") int max() default Integer.MAX_VALUE;
35 @OverridesAttribute(constraint=Pattern.class, name="regexp") String regexp() default ".*";
36
37
38
39
40 @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
41 @Retention(RUNTIME)
42 @Documented
43 public @interface List {
44 ValidName[] value();
45 }
46 }