View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.constraint;
14  
15  import java.lang.annotation.Documented;
16  import java.lang.annotation.ElementType;
17  import java.lang.annotation.Retention;
18  import java.lang.annotation.RetentionPolicy;
19  import java.lang.annotation.Target;
20  
21  import net.sf.oval.configuration.annotation.Constraint;
22  import net.sf.oval.configuration.annotation.Constraints;
23  
24  /**
25   * Check if the value satisfies the constraints defined for the specified field.
26   * 
27   * @author Sebastian Thomschke
28   */
29  @Documented
30  @Retention(RetentionPolicy.RUNTIME)
31  @Target({ElementType.PARAMETER, ElementType.METHOD})
32  @Constraint(checkWith = AssertFieldConstraintsCheck.class)
33  public @interface AssertFieldConstraints
34  {
35  	@Documented
36  	@Retention(RetentionPolicy.RUNTIME)
37  	@Target({ElementType.PARAMETER, ElementType.METHOD})
38  	@Constraints
39  	public @interface List
40  	{
41  		/**
42  		 * The AssertFieldConstraints constraints.
43  		 */
44  		AssertFieldConstraints[] value();
45  
46  		/**
47  		 * Formula returning <code>true</code> if this constraint shall be evaluated and
48  		 * <code>false</code> if it shall be ignored for the current validation.
49  		 * <p>
50  		 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
51  		 * E.g. <code>groovy:_this.amount > 10</code>
52  		 * <p>
53  		 * Available context variables are:<br>
54  		 * <b>_this</b> -&gt; the validated bean<br>
55  		 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
56  		 *    or the validated bean for object level constraints)
57  		 */
58  		String when() default "";
59  	}
60  
61  	/**
62  	 * The class in which the field is declared. If omitted the current class and it's super 
63  	 * classes are searched for a field with the given name.
64  	 * The default value Void.class means the current class.
65  	 */
66  	Class< ? > declaringClass() default Void.class;
67  
68  	/**
69  	 * The associated constraint profiles.
70  	 */
71  	String[] profiles() default {};
72  
73  	/**
74  	 * Name of the field. If not specified, the constraints of the field with the same name as
75  	 * the annotated constructor/method parameter are applied.
76  	 */
77  	String value() default "";
78  
79  	/**
80  	 * Formula returning <code>true</code> if this constraint shall be evaluated and
81  	 * <code>false</code> if it shall be ignored for the current validation.
82  	 * <p>
83  	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
84  	 * E.g. <code>groovy:_this.amount > 10</code>
85  	 * <p>
86  	 * Available context variables are:<br>
87  	 * <b>_this</b> -&gt; the validated bean<br>
88  	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
89  	 *    or the validated bean for object level constraints)
90  	 */
91  	String when() default "";
92  }