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.ConstraintViolation;
23  import net.sf.oval.configuration.annotation.Constraint;
24  import net.sf.oval.configuration.annotation.Constraints;
25  
26  /**
27   * Check if not null.
28   * 
29   * @author Sebastian Thomschke
30   */
31  @Documented
32  @Retention(RetentionPolicy.RUNTIME)
33  @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
34  @Constraint(checkWith = NotNullCheck.class)
35  public @interface NotNull
36  {
37  	@Documented
38  	@Retention(RetentionPolicy.RUNTIME)
39  	@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
40  	@Constraints
41  	public @interface List
42  	{
43  		/**
44  		 * The NotNull constraints.
45  		 */
46  		NotNull[] value();
47  
48  		/**
49  		 * Formula returning <code>true</code> if this constraint shall be evaluated and
50  		 * <code>false</code> if it shall be ignored for the current validation.
51  		 * <p>
52  		 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
53  		 * E.g. <code>groovy:_this.amount > 10</code>
54  		 * <p>
55  		 * Available context variables are:<br>
56  		 * <b>_this</b> -&gt; the validated bean<br>
57  		 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
58  		 *    or the validated bean for object level constraints)
59  		 */
60  		String when() default "";
61  	}
62  
63  	/**
64  	 * <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.
65  	 * 
66  	 * <p><b>Default:</b> ConstraintTarget.CONTAINER, ConstraintTarget.VALUES
67  	 * 
68  	 * <p><b>Note:</b> This setting is ignored for object types other than array, map and collection.
69  	 */
70  	ConstraintTarget[] appliesTo() default {ConstraintTarget.CONTAINER, ConstraintTarget.VALUES};
71  
72  	/**
73  	 * error code passed to the ConstraintViolation object
74  	 */
75  	String errorCode() default "net.sf.oval.constraint.NotNull";
76  
77  	/**
78  	 * message to be used for the ContraintsViolatedException
79  	 * 
80  	 * @see ConstraintViolation
81  	 */
82  	String message() default "net.sf.oval.constraint.NotNull.violated";
83  
84  	/**
85  	 * The associated constraint profiles.
86  	 */
87  	String[] profiles() default {};
88  
89  	/**
90  	 * severity passed to the ConstraintViolation object
91  	 */
92  	int severity() default 0;
93  
94  	String target() default "";
95  
96  	/**
97  	 * Formula returning <code>true</code> if this constraint shall be evaluated and
98  	 * <code>false</code> if it shall be ignored for the current validation.
99  	 * <p>
100 	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
101 	 * E.g. <code>groovy:_this.amount > 10</code>
102 	 * <p>
103 	 * Available context variables are:<br>
104 	 * <b>_this</b> -&gt; the validated bean<br>
105 	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
106 	 *    or the validated bean for object level constraints)
107 	 */
108 	String when() default "";
109 }