Max a = (Max) helper.getAnnotation(element, Max.class);
MaxFacet facet = new MaxFacet(a.value());
property.addFacet(facet);
}
if (helper.isAnnotationPresent(element, Min.class)) {
Min a = (Min) helper.getAnnotation(element, Min.class);
MinFacet facet = new MinFacet(a.value());
property.addFacet(facet);
}
if (helper.isAnnotationPresent(element, NotNull.class)) {
property.setNotNullAnnotated(true);
}
if (helper.isAnnotationPresent(element, Pattern.class)) {
Pattern a = (Pattern) helper.getAnnotation(element, Pattern.class);
PatternFacet facet = new PatternFacet(a.regexp(), a.flags());
property.addFacet(facet);
}
/* Example:
@Pattern.List({
@Pattern(regexp = "first_expression", message = "first.Pattern.message"),
@Pattern(regexp = "second_expression", message = "second.Pattern.message"),
@Pattern(regexp = "third_expression", message = "third.Pattern.message")
}) */
if (helper.isAnnotationPresent(element, Pattern.List.class)) {
Pattern.List a = (Pattern.List) helper.getAnnotation(element, Pattern.List.class);
PatternListFacet facet = new PatternListFacet(new ArrayList<PatternFacet>());
for (Pattern pat : a.value()) {
PatternFacet pf = new PatternFacet(pat.regexp(), pat.flags());
facet.addPattern(pf);
}
property.addFacet(facet);
}
if (helper.isAnnotationPresent(element, Size.class)) {
Size a = (Size) helper.getAnnotation(element, Size.class);
final int min = a.min();
final int max = a.max();
if (min != 0 || max != Integer.MAX_VALUE) { // Fixes generation of an empty facet.
if ("java.lang.String".equals(property.getType().getName())) { // @Size serves for both length facet and occurs restriction.
SizeFacet facet = new SizeFacet(min, max); // For minLength, maxLength.
property.addFacet(facet);
} else { // For minOccurs, maxOccurs.