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.ConstraintTarget;
22  import net.sf.oval.configuration.annotation.Constraint;
23  import net.sf.oval.configuration.annotation.Constraints;
24  
25  /**
26   * Check if the value satisfies the all constraints of specified constraint set.
27   * 
28   * @author Sebastian Thomschke
29   */
30  @Documented
31  @Retention(RetentionPolicy.RUNTIME)
32  @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
33  @Constraint(checkWith = AssertConstraintSetCheck.class)
34  public @interface AssertConstraintSet
35  {
36  	@Documented
37  	@Retention(RetentionPolicy.RUNTIME)
38  	@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
39  	@Constraints
40  	public @interface List
41  	{
42  		/**
43  		 * The AssertConstraintSet constraints.
44  		 */
45  		AssertConstraintSet[] value();
46  
47  		/**
48  		 * Formula returning <code>true</code> if this constraint shall be evaluated and
49  		 * <code>false</code> if it shall be ignored for the current validation.
50  		 * <p>
51  		 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
52  		 * E.g. <code>groovy:_this.amount > 10</code>
53  		 * <p>
54  		 * Available context variables are:<br>
55  		 * <b>_this</b> -&gt; the validated bean<br>
56  		 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
57  		 *    or the validated bean for object level constraints)
58  		 */
59  		String when() default "";
60  	}
61  
62  	/**
63  	 * <p>In case the constraint is declared for an array, collection or map this controls how the constraint is applied to it and it's child objects.
64  	 * 
65  	 * <p><b>Default:</b> ConstraintTarget.CONTAINER
66  	 * 
67  	 * <p><b>Note:</b> This setting is ignored for object types other than array, map and collection.
68  	 */
69  	ConstraintTarget[] appliesTo() default ConstraintTarget.CONTAINER;
70  
71  	/**
72  	 * The id of the constraint set to apply here<br>
73  	 */
74  	String id();
75  
76  	/**
77  	 * The associated constraint profiles.
78  	 */
79  	String[] profiles() default {};
80  
81  	/**
82  	 * Formula returning <code>true</code> if this constraint shall be evaluated and
83  	 * <code>false</code> if it shall be ignored for the current validation.
84  	 * <p>
85  	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
86  	 * E.g. <code>groovy:_this.amount > 10</code>
87  	 * <p>
88  	 * Available context variables are:<br>
89  	 * <b>_this</b> -&gt; the validated bean<br>
90  	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
91  	 *    or the validated bean for object level constraints)
92  	 */
93  	String when() default "";
94  }