1 29 package net.sourceforge.groboutils.mbtf.v1.engine; 30 31 32 import net.sourceforge.groboutils.mbtf.v1.IError; 33 import net.sourceforge.groboutils.mbtf.v1.IErrors; 34 import net.sourceforge.groboutils.mbtf.v1.IPathHistory; 35 import net.sourceforge.groboutils.mbtf.v1.TestHaltRuntimeException; 36 import net.sourceforge.groboutils.mbtf.v1.TestFailRuntimeException; 37 38 import java.util.Vector ; 39 40 41 49 public class ErrorsImpl implements IErrors 50 { 51 private Vector errors = new Vector (); 52 private Vector warnings = new Vector (); 53 private boolean haltTests = false; 54 private boolean haltPath = false; 55 private IPathHistory ph; 56 57 58 69 70 71 public void setCurrentPathHistory( IPathHistory ph ) 72 { 73 this.ph = ph.copy(); 74 } 75 76 77 87 public void halt( String msg ) 88 { 89 addErrorType( msg, null ); 90 this.haltPath = true; 91 this.haltTests = true; 92 93 throw new TestHaltRuntimeException( this, msg ); 94 } 95 96 97 108 public void addFailure( String msg ) 109 { 110 addFailure( msg, null ); 111 } 112 113 114 126 public void addFailure( String msg, Throwable t ) 127 { 128 addErrorType( msg, t ); 129 this.haltPath = true; 130 } 131 132 133 146 public void fail( String msg ) 147 throws TestFailRuntimeException 148 { 149 addFailure( msg ); 150 throw new TestFailRuntimeException( this, msg ); 151 } 152 153 154 168 public void fail( String msg, Throwable t ) 169 throws TestFailRuntimeException 170 { 171 addFailure( msg, t ); 172 throw new TestFailRuntimeException( this, msg ); 173 } 174 175 176 187 public void addError( String msg ) 188 { 189 addError( msg, null ); 190 } 191 192 193 204 public void addError( String msg, Throwable t ) 205 { 206 addErrorType( msg, t ); 207 } 208 209 210 219 public void addWarning( String msg ) 220 { 221 addMessage( this.warnings, msg, null ); 222 } 223 224 225 228 public IError[] getErrors() 229 { 230 IError e[] = new IError[ this.errors.size() ]; 231 this.errors.copyInto( e ); 232 return e; 233 } 234 235 236 237 238 239 241 242 public IError[] getWarnings() 243 { 244 IError e[] = new IError[ this.warnings.size() ]; 245 this.warnings.copyInto( e ); 246 return e; 247 } 248 249 250 public boolean isHaltPath() 251 { 252 return this.haltPath; 253 } 254 255 256 public boolean isHaltTests() 257 { 258 return this.haltTests; 259 } 260 261 262 public String toString() 263 { 264 IError[] e = getErrors(); 265 StringBuffer sb = new StringBuffer ("[ Registered Errors:\n"); 266 for (int i = 0; i < e.length; ++i) 267 { 268 sb.append( e[i] ); 269 } 270 271 sb.append("Registered Warnings:\n"); 272 e = getWarnings(); 273 for (int i = 0; i < e.length; ++i) 274 { 275 sb.append( e[i] ); 276 } 277 278 sb.append( "\n]" ); 279 return sb.toString(); 280 } 281 282 283 285 286 public void addErrors( IErrors e ) 287 { 288 addErrors( e.getErrors() ); 289 if (e instanceof ErrorsImpl) 290 { 291 ErrorsImpl ei = (ErrorsImpl)e; 292 addWarnings( ei.getWarnings() ); 293 if (ei.isHaltPath()) 294 { 295 this.haltPath = true; 296 } 297 if (ei.isHaltTests()) 298 { 299 this.haltTests = true; 300 } 301 } 302 } 303 304 305 public void addErrors( IError[] r ) 306 { 307 if (r != null) 308 { 309 for (int i = 0; i < r.length; ++i) 310 { 311 this.errors.addElement( r[i] ); 312 } 313 } 314 } 315 316 317 public void addWarnings( IError[] r ) 318 { 319 if (r != null) 320 { 321 for (int i = 0; i < r.length; ++i) 322 { 323 this.warnings.addElement( r[i] ); 324 } 325 } 326 } 327 328 329 330 332 333 protected void addErrorType( String msg, Throwable t ) 334 { 335 addMessage( this.errors, msg, t ); 336 } 337 338 339 protected void addMessage( Vector v, String msg, Throwable t ) 340 { 341 IError err = new ErrorImpl( msg, t, this.ph ); 342 v.addElement( err ); 343 } 344 } 345 346 | Popular Tags |