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;
14  
15  import java.io.Serializable;
16  
17  import net.sf.oval.context.OValContext;
18  import net.sf.oval.exception.OValException;
19  
20  /**
21   * interface for classes that can exclude the checking of constraints
22   * 
23   * @author Sebastian Thomschke
24   */
25  public interface CheckExclusion extends Serializable
26  {
27  	/**
28  	 * @return the profiles, may return null
29  	 */
30  	String[] getProfiles();
31  
32  	/**
33  	 * Formula returning <code>true</code> if this constraint shall be evaluated and
34  	 * <code>false</code> if it shall be ignored for the current validation.
35  	 * <p>
36  	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
37  	 * E.g. <code>groovy:_this.amount > 10</code>
38  	 * <p>
39  	 * Available context variables are:<br>
40  	 * <b>_this</b> -&gt; the validated bean<br>
41  	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
42  	 *    or the validated bean for object level constraints)
43  	 *    
44  	 * @return the formula
45  	 */
46  	String getWhen();
47  
48  	/**
49  	 * @param validatedObject the object/bean to validate the value against, for static fields or methods this is the class
50  	 * @param valueToValidate the value to validate, may be null when validating pre conditions for static methods
51  	 * @param validator the calling validator
52  	 * @return <code>true</code> if this check exclusion is active and must be satisfied
53  	 */
54  	boolean isActive(final Object validatedObject, final Object valueToValidate, final Validator validator);
55  
56  	/**
57  	 * This method implements the validation logic
58  	 * 
59  	 * @param check a check that OVal is about to validate
60  	 * @param validatedObject the object/bean to validate the value against, for static fields or methods this is 
61  	 * the class
62  	 * @param valueToValidate the value to validate, may be null when validating pre conditions for static methods
63  	 * @param context the validation context (e.g. a field, a constructor parameter or a method parameter)
64  	 * @param validator the calling validator
65  	 * @return true if the value satisfies the checked constraint
66  	 */
67  	boolean isCheckExcluded(Check check, Object validatedObject, Object valueToValidate, OValContext context,
68  			Validator validator) throws OValException;
69  
70  	/**
71  	 * @param profiles the profiles to set
72  	 */
73  	void setProfiles(String... profiles);
74  
75  	/**
76  	 * Sets the formula returning <code>true</code> if this constraint shall be evaluated and
77  	 * <code>false</code> if it shall be ignored for the current validation.
78  	 * <p>
79  	 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
80  	 * E.g. <code>groovy:_this.amount > 10</code>
81  	 * <p>
82  	 * Available context variables are:<br>
83  	 * <b>_this</b> -&gt; the validated bean<br>
84  	 * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
85  	 *    or the validated bean for object level constraints)
86  	 *  
87  	 * @param when formula calculating if this check is active
88  	 */
89  	void setWhen(final String when);
90  }