01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.exception;
13:
14: import java.util.List;
15:
16: import net.sf.oval.ConstraintViolation;
17:
18: /**
19: * This exception is thrown if one or more constraints are not satisfied during validation.
20: *
21: * @author Sebastian Thomschke
22: */
23: public class ConstraintsViolatedException extends OValException {
24: private static final long serialVersionUID = 1L;
25:
26: private final long causingThreadId = Thread.currentThread().getId();
27:
28: private final ConstraintViolation[] constraintViolations;
29:
30: public ConstraintsViolatedException(
31: final ConstraintViolation... constraintViolations) {
32: // the message of the first occuring constraint violation will be used
33: super (constraintViolations[0].getMessage());
34:
35: this .constraintViolations = constraintViolations;
36: }
37:
38: public ConstraintsViolatedException(
39: final List<ConstraintViolation> constraintViolations) {
40: // the message of the first occuring constraint violation will be used
41: super (constraintViolations.get(0).getMessage());
42:
43: this .constraintViolations = constraintViolations
44: .toArray(new ConstraintViolation[constraintViolations
45: .size()]);
46: }
47:
48: /**
49: * @return the id of the thread in which the violations occured
50: */
51: public long getCausingThreadId() {
52: return causingThreadId;
53: }
54:
55: /**
56: * @return the constraintViolations
57: */
58: public ConstraintViolation[] getConstraintViolations() {
59: return constraintViolations.clone();
60: }
61: }
|