1 19 20 package org.netbeans.modules.exceptions; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.logging.Handler ; 25 import java.util.logging.LogRecord ; 26 import java.util.logging.Level ; 27 import org.openide.windows.WindowManager; 28 29 33 public class ExceptionsHandler extends Handler { 34 private NotifyDialog notifyDialog = null; 36 private LinkedList <LinkedList <LogRecord >> transport = null; 37 private static ExceptionsHandler defaultHandler = new ExceptionsHandler(); 38 39 41 private ExceptionsHandler() { 42 } 43 44 public void publish(final LogRecord rec) { 46 if (rec.getThrown() != null){ 47 ExceptionLogger.logError(rec); 48 } 49 if ((rec.getThrown() != null)&&(rec.getLevel().intValue() >= Level.INFO.intValue())){ 50 LinkedList <LogRecord > recs = new LinkedList <LogRecord >(); 51 for (Iterator <LogRecord > it = Collector.getDefault().getQueue().iterator(); it.hasNext();) { 52 recs.addLast(it.next()); } 54 recs.addFirst(rec); addRecord(recs); 56 WindowManager.getDefault().invokeWhenUIReady(new Runnable (){ 57 public void run(){ 58 if (notifyDialog == null) notifyDialog = new NotifyDialog(); 59 notifyDialog.notify(transport); 60 if (rec.getLevel().intValue() > Level.INFO.intValue()) notifyDialog.setVisible(true); 61 } 62 }); 63 } 64 if ((rec.getThrown()== null)&&(rec.getLevel().intValue() >= Level.WARNING.intValue())) ExceptionLogger.log(rec); 65 } 66 67 public void showNotifyDialog(){ 68 if (notifyDialog == null) notifyDialog = new NotifyDialog(); 69 notifyDialog.setVisible(true); 70 } 71 72 73 public static boolean equalsThrows(Throwable thr1, Throwable thr2){ if ((thr1 == null) && (thr2 == null)) return true; if ((thr1 == null) || (thr2 == null)) return false; int i; 79 StackTraceElement [] recStack = thr1.getStackTrace(); 80 StackTraceElement [] st1 = thr2.getStackTrace(); 81 if (recStack.length == st1.length){ 82 i = 0; 83 while (i < st1.length){ 84 if (st1[i].toString().equals(recStack[i].toString())){ 85 ++i; 86 } else i=st1.length + 10; } 88 if (i==st1.length){ if ((thr1.getCause()!= null)||(thr2.getCause()!= null)){ 90 return equalsThrows(thr1.getCause(), thr2.getCause()); 91 }else return true; 92 } 93 } 94 return false; 95 } 96 97 98 99 public static synchronized ExceptionsHandler getInstance() { 100 return defaultHandler; 101 } 102 103 public void flush() { 104 } 106 107 public void close() throws SecurityException { 108 } 110 111 112 private void addRecord(LinkedList <LogRecord > rec) { 114 if (transport == null) transport = new LinkedList <LinkedList <LogRecord >>(); 115 transport.add(rec); 116 } 117 118 } 119 | Popular Tags |