01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.constraint;
13:
14: import java.lang.annotation.Documented;
15: import java.lang.annotation.ElementType;
16: import java.lang.annotation.Retention;
17: import java.lang.annotation.RetentionPolicy;
18: import java.lang.annotation.Target;
19:
20: import net.sf.oval.ConstraintViolation;
21: import net.sf.oval.configuration.annotation.Constraint;
22:
23: /**
24: * Check if the specified regular expression pattern is matched.
25: *
26: * <br><br>
27: * <b>Note:</b> This constraint is also satisified when the value to validate is null, therefore you might also need to specified @NotNull
28: *
29: * @author Sebastian Thomschke
30: */
31: @Documented
32: @Retention(RetentionPolicy.RUNTIME)
33: @Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.METHOD})
34: @Constraint(checkWith=MatchPatternCheck.class)
35: public @interface MatchPattern {
36: /**
37: * errpr code passed to the ConstraintViolation object
38: */
39: String errorCode() default "net.sf.oval.constraints.MatchPattern";
40:
41: /**
42: * Match flags, a bit mask that may include
43: * Pattern.CASE_INSENSITIVE, Pattern.MULTILINE, Pattern.DOTALL,
44: * Pattern.UNICODE_CASE, Pattern.CANON_EQ
45: *
46: * @see java.util.regex.Pattern
47: */
48: int flags() default 0;
49:
50: /**
51: * message to be used for the ContraintsViolatedException
52: *
53: * @see ConstraintViolation
54: */
55: String message() default "net.sf.oval.constraints.MatchPattern.violated";
56:
57: /**
58: * The regular expression to match against
59: * <br><br>
60: * Examples:<br>
61: * decimal number: "^-{0,1}(\\d*|(\\d{1,3}([,]\\d{3})*))[.]?\\d*$"<br>
62: * numbers only: "^\\d*$"<br>
63: * e-mail address: "^([a-z0-9]{1,}[\\.\\_\\-]?[a-z0-9]{1,})\\@([a-z0-9]{2,}\\.)([a-z]{2,2}|org|net|com|gov|edu|int|info|biz|museum)$"<br>
64: *
65: * @see java.util.regex.Pattern
66: */
67: String pattern();
68:
69: /**
70: * severity passed to the ConstraintViolation object
71: */
72: int severity() default 0;
73:
74: /**
75: * The associated validation profiles.
76: */
77: String[] profiles() default {};
78: }
|