| 1 4 package com.nightlabs.rcp.exceptionhandler.wizard; 5 6 import java.io.InputStream ; 7 import java.io.InputStreamReader ; 8 import java.io.OutputStream ; 9 import java.io.PrintWriter ; 10 import java.io.Serializable ; 11 import java.io.StringWriter ; 12 import java.text.SimpleDateFormat ; 13 import java.util.Date ; 14 import java.util.Properties ; 15 16 import com.nightlabs.io.DataBuffer; 17 18 21 public class ErrorReport 22 implements Serializable  23 { 24 private Throwable thrownException; 25 private Throwable triggerException; 26 private String userComment; 27 private Properties systemProperties; 28 30 protected ErrorReport() 31 { 32 } 33 34 public ErrorReport(Throwable thrownException, Throwable triggerException) 35 { 36 setThrownException(thrownException); 37 setTriggerException(triggerException); 38 this.systemProperties = System.getProperties(); 40 41 } 42 43 46 public Throwable getThrownException() 47 { 48 return thrownException; 49 } 50 53 public void setThrownException(Throwable error) 54 { 55 if (error == null) 56 throw new NullPointerException ("Parameter thrownException must not be null!"); 57 this.thrownException = error; 58 } 59 62 public String getUserComment() 63 { 64 return userComment; 65 } 66 69 public void setUserComment(String userComment) 70 { 71 this.userComment = userComment; 72 } 73 public Properties getSystemProperties() 74 { 75 return systemProperties; 76 } 77 public void setSystemProperties(Properties systemProperties) 78 { 79 this.systemProperties = systemProperties; 80 } 81 95 public String toString() 96 { 97 StringBuffer props = new StringBuffer (); 98 try { 99 DataBuffer db = new DataBuffer(1024); 100 OutputStream out = db.createOutputStream(); 101 systemProperties.storeToXML(out, ""); 102 out.close(); 103 104 InputStream in = db.createInputStream(); 105 InputStreamReader reader = new InputStreamReader (in, "UTF-8"); 106 while (reader.ready()) { 107 props.append((char)reader.read()); 108 } 109 } catch (Exception x) { 110 props.append("Fuck, dumping the properties failed: " + x.getMessage()); 111 } 112 113 122 return 123 "Time:\n"+ getCurrentTimeAsString() +"\n\nUser Comment:\n" + userComment + 124 "\n\nError:\n" + getErrorStackTraceAsString() + 125 "\nSystem Properties:\n" + props.toString(); 126 } 127 128 public String getErrorStackTraceAsString() 129 { 130 StringWriter sw = new StringWriter (); 131 PrintWriter pw = new PrintWriter (sw); 132 thrownException.printStackTrace(pw); 133 pw.close(); 134 return sw.getBuffer().toString(); 135 } 136 137 138 public String getCurrentTimeAsString() 139 { 140 SimpleDateFormat bartDateFormat = 141 new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 142 String timestring = new String (); 143 Date date = new Date (); 144 timestring =bartDateFormat.format(date); 145 return timestring; 146 147 } 148 149 150 151 152 153 154 public Throwable getTriggerException() 180 { 181 return triggerException; 182 } 183 public void setTriggerException(Throwable triggerException) 184 { 185 if (triggerException == null) 186 throw new NullPointerException ("Parameter triggerException must not be null!"); 187 this.triggerException = triggerException; 188 } 189 } 190 | Popular Tags |