1 /** 2 * Copyright 2005-2011 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.kcb.exception; 17 18 import java.util.ArrayList; 19 import java.util.Iterator; 20 import java.util.List; 21 22 /** 23 * This class is a value added datastructure that is used to house a list of Exceptions and is 24 * recognized as an Exception so that it can be thrown from methods and handled like an Exception. 25 * @author Kuali Rice Team (rice.collab@kuali.org) 26 */ 27 public class ErrorList extends Exception { 28 private static final long serialVersionUID = -8045847343472018601L; 29 30 private List<String> errorList; 31 32 /** 33 * Constructs a ErrorList instance. 34 */ 35 public ErrorList() { 36 errorList = new ArrayList<String>(); 37 } 38 39 /** 40 * This method checks to see if the list is empty or not. 41 * @return boolean 42 */ 43 public boolean isEmpty() { 44 return errorList.isEmpty(); 45 } 46 47 /** 48 * This method adds errors to the error list. 49 * @param error 50 */ 51 public void addError(String error) { 52 this.errorList.add(error); 53 } 54 55 /** 56 * This method retreives all of the errors in the list. 57 * @return List 58 */ 59 public List<String> getErrors() { 60 return this.errorList; 61 } 62 63 /** 64 * This method adds a list of errors to the error list. 65 * @param errors 66 */ 67 public void addErrors(ErrorList errors) { 68 this.errorList.addAll(errors.errorList); 69 } 70 71 /** 72 * This method returns a string representation of all of the errors in the error list. 73 * @see java.lang.Throwable#getMessage() 74 */ 75 public String getMessage() { 76 return toString(); 77 } 78 79 /** 80 * This method is responsible for concatenating all of the errors in the error list together. 81 * @see java.lang.Throwable#toString() 82 */ 83 public String toString() { 84 StringBuffer buf = new StringBuffer("errors=("); 85 86 for (Iterator<String> i = errorList.iterator(); i.hasNext();) { 87 buf.append(i.next()); 88 if (i.hasNext()) { 89 buf.append(";"); 90 } 91 } 92 buf.append(")"); 93 94 return buf.toString(); 95 } 96 }