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.exception;
14  
15  import java.util.List;
16  
17  import net.sf.oval.ConstraintViolation;
18  
19  /**
20   * This exception is thrown if one or more constraints are not satisfied during validation.
21   * 
22   * @author Sebastian Thomschke
23   */
24  public class ConstraintsViolatedException extends OValException
25  {
26  	private static final long serialVersionUID = 1L;
27  
28  	private final long causingThreadId = Thread.currentThread().getId();
29  
30  	private final ConstraintViolation[] constraintViolations;
31  
32  	/**
33  	 * @param constraintViolations must not be null
34  	 */
35  	public ConstraintsViolatedException(final ConstraintViolation... constraintViolations)
36  	{
37  		// the message of the first occurring constraint violation will be used
38  		super(constraintViolations[0].getMessage());
39  
40  		this.constraintViolations = constraintViolations;
41  	}
42  
43  	/**
44  	 * @param constraintViolations must not be null
45  	 */
46  	public ConstraintsViolatedException(final List<ConstraintViolation> constraintViolations)
47  	{
48  		// the message of the first occurring constraint violation will be used
49  		super(constraintViolations.get(0).getMessage());
50  
51  		this.constraintViolations = constraintViolations.toArray(new ConstraintViolation[constraintViolations.size()]);
52  	}
53  
54  	/**
55  	 * @return the id of the thread in which the violations occurred
56  	 */
57  	public long getCausingThreadId()
58  	{
59  		return causingThreadId;
60  	}
61  
62  	/**
63  	 * @return the constraintViolations
64  	 */
65  	public ConstraintViolation[] getConstraintViolations()
66  	{
67  		return constraintViolations.clone();
68  	}
69  }