1 9 package org.jboss.portal.server.output; 10 11 import java.io.PrintWriter ; 12 import java.io.StringWriter ; 13 14 import org.jboss.portal.server.WindowContext; 15 16 22 public class ErrorResult extends Result 23 { 24 25 private final Throwable throwable; 26 27 28 private final String message; 29 30 public ErrorResult(WindowContext producer, String message) 31 { 32 super(producer); 33 if (message == null) 34 { 35 throw new IllegalArgumentException ("There must be a message"); 36 } 37 this.throwable = null; 38 this.message = message; 39 } 40 41 public ErrorResult(WindowContext producer, Throwable throwable) 42 { 43 super(producer); 44 if (throwable == null) 45 { 46 throw new IllegalArgumentException ("There must be a throwable"); 47 } 48 this.throwable = throwable; 49 this.message = throwable.getMessage(); 50 } 51 52 55 public Throwable getThrowable() 56 { 57 return throwable; 58 } 59 60 63 public String getMessage() 64 { 65 return message; 66 } 67 68 public String toString() 69 { 70 if (throwable != null) 71 { 72 StringWriter writer = new StringWriter (); 73 writer.write("Error :\n"); 74 throwable.printStackTrace(new PrintWriter (writer)); 75 return writer.toString(); 76 } 77 else 78 { 79 return "Error"; 80 } 81 } 82 } 83 | Popular Tags |