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 that the value is not a reference to the validated object itself.<br>
28   * This is e.g. useful to avoid circular references.<br>
29   * 
30   * @author Sebastian Thomschke
31   */
32  @Documented
33  @Retention(RetentionPolicy.RUNTIME)
34  @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
35  @Constraint(checkWith = NoSelfReferenceCheck.class)
36  public @interface NoSelfReference
37  {
38  	@Documented
39  	@Retention(RetentionPolicy.RUNTIME)
40  	@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
41  	@Constraints
42  	public @interface List
43  	{
44  		/**
45  		 * The NoSelfReference constraints.
46  		 */
47  		NoSelfReference[] value();
48  
49  		/**
50  		 * Formula returning <code>true</code> if this constraint shall be evaluated and
51  		 * <code>false</code> if it shall be ignored for the current validation.
52  		 * <p>
53  		 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
54  		 * E.g. <code>groovy:_this.amount > 10</code>
55  		 * <p>
56  		 * Available context variables are:<br>
57  		 * <b>_this</b> -&gt; the validated bean<br>
58  		 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
59  		 *    or the validated bean for object level constraints)
60  		 */
61  		String when() default "";
62  	}
63  
64  	/**
65  	 * <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.
66  	 * 
67  	 * <p><b>Default:</b> ConstraintTarget.VALUES
68  	 * 
69  	 * <p><b>Note:</b> This setting is ignored for object types other than array, map and collection.
70  	 */
71  	ConstraintTarget[] appliesTo() default ConstraintTarget.VALUES;
72  
73  	/**
74  	 * error code passed to the ConstraintViolation object
75  	 */
76  	String errorCode() default "net.sf.oval.constraint.NoSelfReference";
77  
78  	/**
79  	 * message to be used for the ContraintsViolatedException
80  	 * 
81  	 * @see ConstraintViolation
82  	 */
83  	String message() default "net.sf.oval.constraint.NoSelfReference.violated";
84  
85  	/**
86  	 * The associated constraint profiles.
87  	 */
88  	String[] profiles() default {};
89  
90  	/**
91  	 * severity passed to the ConstraintViolation object
92  	 */
93  	int severity() default 0;
94  
95  	/**
96  	 * An expression to specify where in the object graph relative from this object the expression
97  	 * should be applied.
98  	 * <p>
99  	 * Examples:
100 	 * <li>"owner" would apply this constraint to the current object's property <code>owner</code>
101 	 * <li>"owner.id" would apply this constraint to the current object's <code>owner</code>'s property <code>id</code>
102 	 * <li>"jxpath:owner/id" would use the JXPath implementation to traverse the object graph to locate the object where this constraint should be applied.
103 	 */
104 	String target() default "";
105 
106 	/**
107 	 * Formula returning <code>true</code> if this constraint shall be evaluated and
108 	 * <code>false</code> if it shall be ignored for the current validation.
109 	 * <p>
110 	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
111 	 * E.g. <code>groovy:_this.amount > 10</code>
112 	 * <p>
113 	 * Available context variables are:<br>
114 	 * <b>_this</b> -&gt; the validated bean<br>
115 	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
116 	 *    or the validated bean for object level constraints)
117 	 */
118 	String when() default "";
119 }