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.lang.reflect.Field;
16  import java.util.List;
17  
18  import net.sf.oval.exception.ConstraintsViolatedException;
19  import net.sf.oval.exception.ValidationFailedException;
20  
21  /**
22   * An interface implemented by Validator for easier mocking.
23   * 
24   * @author Sebastian Thomschke
25   */
26  public interface IValidator
27  {
28  
29  	/**
30  	 * validates the field and getter constrains of the given object
31  	 * and throws an ConstraintsViolatedException if any constraint
32  	 * violations are detected
33  	 * 
34  	 * @param validatedObject the object to validate, cannot be null
35  	 * @throws ConstraintsViolatedException
36  	 * @throws ValidationFailedException
37  	 * @throws IllegalArgumentException if <code>validatedObject == null</code>
38  	 */
39  	void assertValid(final Object validatedObject) throws IllegalArgumentException, ValidationFailedException,
40  			ConstraintsViolatedException;
41  
42  	/**
43  	 * Validates the give value against the defined field constraints and throws 
44  	 * an ConstraintsViolatedException if any constraint violations are detected.<br>
45  	 * 
46  	 * @param validatedObject the object to validate, cannot be null
47  	 * @param validatedField the field to validate, cannot be null
48  	 * @throws IllegalArgumentException if <code>validatedObject == null</code> or <code>field == null</code>
49  	 * @throws ConstraintsViolatedException
50  	 * @throws ValidationFailedException 
51  	 */
52  	void assertValidFieldValue(final Object validatedObject, final Field validatedField,
53  			final Object fieldValueToValidate) throws IllegalArgumentException, ValidationFailedException,
54  			ConstraintsViolatedException;
55  
56  	/**
57  	 * validates the field and getter constrains of the given object
58  	 *
59  	 * @param validatedObject the object to validate, cannot be null
60  	 * @return a list with the detected constraint violations. if no violations are detected an empty list is returned
61  	 * @throws ValidationFailedException
62  	 * @throws IllegalArgumentException if <code>validatedObject == null</code>
63  	 */
64  	List<ConstraintViolation> validate(final Object validatedObject) throws IllegalArgumentException,
65  			ValidationFailedException;
66  
67  	/**
68  	 * validates the field and getter constrains of the given object
69  	 *
70  	 * @param validatedObject the object to validate, cannot be null
71  	 * @param profiles constraint profiles to validate against, by default the globally enabled profiles are used that.
72  	 * @return a list with the detected constraint violations. if no violations are detected an empty list is returned
73  	 * @throws ValidationFailedException
74  	 * @throws IllegalArgumentException if <code>validatedObject == null</code>
75  	 */
76  	List<ConstraintViolation> validate(final Object validatedObject, String... profiles)
77  			throws IllegalArgumentException, ValidationFailedException;
78  
79  	/**
80  	 * Validates the give value against the defined field constraints.<br>
81  	 * 
82  	 * @return a list with the detected constraint violations. if no violations are detected an empty list is returned
83  	 * @throws IllegalArgumentException if <code>validatedObject == null</code> or <code>validatedField == null</code>
84  	 * @throws ValidationFailedException 
85  	 */
86  	List<ConstraintViolation> validateFieldValue(final Object validatedObject, final Field validatedField,
87  			final Object fieldValueToValidate) throws IllegalArgumentException, ValidationFailedException;
88  
89  }