001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.common.collection; 025 026 import java.util.Collections; 027 import java.util.Iterator; 028 import java.util.List; 029 import org.jboss.dna.common.i18n.I18n; 030 031 /** 032 * A list of problems for some execution context. The problems will be {@link #iterator() returned} in the order in which they 033 * were encountered (although this cannot be guaranteed in contexts involving multiple threads or processes). 034 * 035 * @author Randall Hauch 036 * @author John Verhaeg 037 */ 038 public abstract class AbstractProblems implements Problems { 039 040 protected static final List<Problem> EMPTY_PROBLEMS = Collections.emptyList(); 041 042 public void addError( I18n message, 043 Object... params ) { 044 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, null)); 045 } 046 047 public void addError( Throwable throwable, 048 I18n message, 049 Object... params ) { 050 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, throwable)); 051 } 052 053 public void addError( I18n message, 054 String resource, 055 String location, 056 Object... params ) { 057 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, null)); 058 } 059 060 public void addError( Throwable throwable, 061 I18n message, 062 String resource, 063 String location, 064 Object... params ) { 065 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, throwable)); 066 } 067 068 public void addError( int code, 069 I18n message, 070 Object... params ) { 071 addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, null)); 072 } 073 074 public void addError( Throwable throwable, 075 int code, 076 I18n message, 077 Object... params ) { 078 addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, throwable)); 079 } 080 081 public void addError( int code, 082 I18n message, 083 String resource, 084 String location, 085 Object... params ) { 086 addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, null)); 087 } 088 089 public void addError( Throwable throwable, 090 int code, 091 I18n message, 092 String resource, 093 String location, 094 Object... params ) { 095 addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, throwable)); 096 } 097 098 public void addWarning( I18n message, 099 Object... params ) { 100 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, null)); 101 } 102 103 public void addWarning( Throwable throwable, 104 I18n message, 105 Object... params ) { 106 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, throwable)); 107 } 108 109 public void addWarning( I18n message, 110 String resource, 111 String location, 112 Object... params ) { 113 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, null)); 114 } 115 116 public void addWarning( Throwable throwable, 117 I18n message, 118 String resource, 119 String location, 120 Object... params ) { 121 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, throwable)); 122 } 123 124 public void addWarning( int code, 125 I18n message, 126 Object... params ) { 127 addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, null)); 128 } 129 130 public void addWarning( Throwable throwable, 131 int code, 132 I18n message, 133 Object... params ) { 134 addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, throwable)); 135 } 136 137 public void addWarning( int code, 138 I18n message, 139 String resource, 140 String location, 141 Object... params ) { 142 addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, null)); 143 } 144 145 public void addWarning( Throwable throwable, 146 int code, 147 I18n message, 148 String resource, 149 String location, 150 Object... params ) { 151 addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, throwable)); 152 } 153 154 public void addInfo( I18n message, 155 Object... params ) { 156 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, null)); 157 } 158 159 public void addInfo( Throwable throwable, 160 I18n message, 161 Object... params ) { 162 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, throwable)); 163 } 164 165 public void addInfo( I18n message, 166 String resource, 167 String location, 168 Object... params ) { 169 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, null)); 170 } 171 172 public void addInfo( Throwable throwable, 173 I18n message, 174 String resource, 175 String location, 176 Object... params ) { 177 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, throwable)); 178 } 179 180 public void addInfo( int code, 181 I18n message, 182 Object... params ) { 183 addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, null)); 184 } 185 186 public void addInfo( Throwable throwable, 187 int code, 188 I18n message, 189 Object... params ) { 190 addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, throwable)); 191 } 192 193 public void addInfo( int code, 194 I18n message, 195 String resource, 196 String location, 197 Object... params ) { 198 addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, null)); 199 } 200 201 public void addInfo( Throwable throwable, 202 int code, 203 I18n message, 204 String resource, 205 String location, 206 Object... params ) { 207 addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, throwable)); 208 } 209 210 public boolean hasProblems() { 211 return getProblems().size() > 0; 212 } 213 214 public boolean hasErrors() { 215 for (Problem problem : this.getProblems()) { 216 if (problem.getStatus() == Problem.Status.ERROR) return true; 217 } 218 return false; 219 } 220 221 public boolean hasWarnings() { 222 for (Problem problem : this.getProblems()) { 223 if (problem.getStatus() == Problem.Status.WARNING) return true; 224 } 225 return false; 226 } 227 228 public boolean hasInfo() { 229 for (Problem problem : this.getProblems()) { 230 if (problem.getStatus() == Problem.Status.INFO) return true; 231 } 232 return false; 233 } 234 235 public boolean isEmpty() { 236 return getProblems().isEmpty(); 237 } 238 239 public int size() { 240 return getProblems().size(); 241 } 242 243 /** 244 * {@inheritDoc} 245 * 246 * @see org.jboss.dna.common.collection.Problems#iterator() 247 */ 248 public Iterator<Problem> iterator() { 249 return getProblems().iterator(); 250 } 251 252 protected abstract void addProblem( Problem problem ); 253 254 protected abstract List<Problem> getProblems(); 255 }