001    
002    /*
003     * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.
004     *
005     * $Id: Pattern.java 305 2012-03-07 03:26:12Z archie.cobbs $
006     */
007    
008    package org.dellroad.stuff.validation;
009    
010    import java.lang.annotation.Documented;
011    import java.lang.annotation.ElementType;
012    import java.lang.annotation.Retention;
013    import java.lang.annotation.RetentionPolicy;
014    import java.lang.annotation.Target;
015    
016    import javax.validation.Constraint;
017    import javax.validation.Payload;
018    import javax.validation.ReportAsSingleViolation;
019    
020    /**
021     * Works like the standard {@link javax.validation.constraints.Pattern @Pattern} but applies to any
022     * type of object, converting to {@link String} as necessary via {@link Object#toString}, and recursing
023     * on collection types.
024     */
025    @Documented
026    @Constraint(validatedBy = PatternValidator.class)
027    @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE })
028    @Retention(RetentionPolicy.RUNTIME)
029    @ReportAsSingleViolation
030    public @interface Pattern {
031    
032        String message() default "Does not match the pattern \"{regexp}\"";
033    
034        Class<?>[] groups() default {};
035    
036        Class<? extends Payload>[] payload() default {};
037    
038        /**
039         * Regular expression that must be matched.
040         */
041        String regexp();
042    
043        /**
044         * Regular expression flags.
045         */
046        javax.validation.constraints.Pattern.Flag[] flags() default {};
047    }
048