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.guard; 014 015 import static net.sf.oval.Validator.*; 016 017 import java.util.List; 018 019 import net.sf.oval.ConstraintViolation; 020 import net.sf.oval.exception.ConstraintsViolatedException; 021 import net.sf.oval.internal.util.ArrayUtils; 022 023 /** 024 * @author Sebastian Thomschke 025 */ 026 public class ConstraintsViolatedAdapter implements ConstraintsViolatedListener 027 { 028 private final List<ConstraintsViolatedException> violationExceptions = getCollectionFactory().createList(8); 029 private final List<ConstraintViolation> violations = getCollectionFactory().createList(8); 030 031 public void clear() 032 { 033 violationExceptions.clear(); 034 violations.clear(); 035 } 036 037 /** 038 * @return Returns the constraint violation exceptions. 039 */ 040 public List<ConstraintsViolatedException> getConstraintsViolatedExceptions() 041 { 042 return violationExceptions; 043 } 044 045 /** 046 * @return Returns the constraint violations. 047 */ 048 public List<ConstraintViolation> getConstraintViolations() 049 { 050 return violations; 051 } 052 053 /** 054 * {@inheritDoc} 055 */ 056 public void onConstraintsViolatedException(final ConstraintsViolatedException exception) 057 { 058 violationExceptions.add(exception); 059 violations.addAll(ArrayUtils.asList(exception.getConstraintViolations())); 060 } 061 }