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.guard;
14  
15  import static net.sf.oval.Validator.*;
16  
17  import java.util.List;
18  
19  import net.sf.oval.ConstraintViolation;
20  import net.sf.oval.exception.ConstraintsViolatedException;
21  import net.sf.oval.internal.util.ArrayUtils;
22  
23  /**
24   * @author Sebastian Thomschke
25   */
26  public class ConstraintsViolatedAdapter implements ConstraintsViolatedListener
27  {
28  	private final List<ConstraintsViolatedException> violationExceptions = getCollectionFactory().createList(8);
29  	private final List<ConstraintViolation> violations = getCollectionFactory().createList(8);
30  
31  	public void clear()
32  	{
33  		violationExceptions.clear();
34  		violations.clear();
35  	}
36  
37  	/**
38  	 * @return Returns the constraint violation exceptions.
39  	 */
40  	public List<ConstraintsViolatedException> getConstraintsViolatedExceptions()
41  	{
42  		return violationExceptions;
43  	}
44  
45  	/**
46  	 * @return Returns the constraint violations.
47  	 */
48  	public List<ConstraintViolation> getConstraintViolations()
49  	{
50  		return violations;
51  	}
52  
53  	/**
54  	 * {@inheritDoc}
55  	 */
56  	public void onConstraintsViolatedException(final ConstraintsViolatedException exception)
57  	{
58  		violationExceptions.add(exception);
59  		violations.addAll(ArrayUtils.asList(exception.getConstraintViolations()));
60  	}
61  }