001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ken.exception; 017 018 import java.util.ArrayList; 019 import java.util.Iterator; 020 import java.util.List; 021 022 /** 023 * This class is a valud added datastructure that is used to house a list of Exceptions and is 024 * recognized as an Exception so that it can be thrown from methods and handled like an Exception. 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 */ 027 public class ErrorList extends Exception { 028 private static final long serialVersionUID = -8045847343472018601L; 029 030 private List errorList; 031 032 /** 033 * Constructs a ErrorList instance. 034 */ 035 public ErrorList() { 036 errorList = new ArrayList(); 037 } 038 039 /** 040 * This method checks to see if the list is empty or not. 041 * @return boolean 042 */ 043 public boolean isEmpty() { 044 return errorList.isEmpty(); 045 } 046 047 /** 048 * This method adds errors to the error list. 049 * @param error 050 */ 051 public void addError(String error) { 052 this.errorList.add(error); 053 } 054 055 /** 056 * This method retreives all of the errors in the list. 057 * @return List 058 */ 059 public List getErrors() { 060 return this.errorList; 061 } 062 063 /** 064 * This method adds a list of errors to the error list. 065 * @param errors 066 */ 067 public void addErrors(ErrorList errors) { 068 this.errorList.addAll(errors.errorList); 069 } 070 071 /** 072 * This method returns a string representation of all of the errors in the error list. 073 * @see java.lang.Throwable#getMessage() 074 */ 075 public String getMessage() { 076 return toString(); 077 } 078 079 /** 080 * This method is responsible for concatenating all of the errors in the error list together. 081 * @see java.lang.Throwable#toString() 082 */ 083 public String toString() { 084 StringBuffer buf = new StringBuffer("errors=("); 085 086 for (Iterator i = errorList.iterator(); i.hasNext();) { 087 buf.append(i.next()); 088 if (i.hasNext()) { 089 buf.append(";"); 090 } 091 } 092 buf.append(")"); 093 094 return buf.toString(); 095 } 096 }