001    /*******************************************************************************
002     * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
003     * Thomschke.
004     * 
005     * All Rights Reserved. This program and the accompanying materials
006     * are made available under the terms of the Eclipse Public License v1.0
007     * which accompanies this distribution, and is available at
008     * http://www.eclipse.org/legal/epl-v10.html
009     * 
010     * Contributors:
011     *     Sebastian Thomschke - initial implementation.
012     *******************************************************************************/
013    package net.sf.oval.exception;
014    
015    import java.util.List;
016    
017    import net.sf.oval.ConstraintViolation;
018    
019    /**
020     * This exception is thrown if one or more constraints are not satisfied during validation.
021     * 
022     * @author Sebastian Thomschke
023     */
024    public class ConstraintsViolatedException extends OValException
025    {
026            private static final long serialVersionUID = 1L;
027    
028            private final long causingThreadId = Thread.currentThread().getId();
029    
030            private final ConstraintViolation[] constraintViolations;
031    
032            /**
033             * @param constraintViolations must not be null
034             */
035            public ConstraintsViolatedException(final ConstraintViolation... constraintViolations)
036            {
037                    // the message of the first occurring constraint violation will be used
038                    super(constraintViolations[0].getMessage());
039    
040                    this.constraintViolations = constraintViolations;
041            }
042    
043            /**
044             * @param constraintViolations must not be null
045             */
046            public ConstraintsViolatedException(final List<ConstraintViolation> constraintViolations)
047            {
048                    // the message of the first occurring constraint violation will be used
049                    super(constraintViolations.get(0).getMessage());
050    
051                    this.constraintViolations = constraintViolations.toArray(new ConstraintViolation[constraintViolations.size()]);
052            }
053    
054            /**
055             * @return the id of the thread in which the violations occurred
056             */
057            public long getCausingThreadId()
058            {
059                    return causingThreadId;
060            }
061    
062            /**
063             * @return the constraintViolations
064             */
065            public ConstraintViolation[] getConstraintViolations()
066            {
067                    return constraintViolations.clone();
068            }
069    }