1 19 20 package org.netbeans.modules.openide.loaders; 21 22 import java.io.IOException ; 23 import java.io.PrintStream ; 24 import java.io.PrintWriter ; 25 import java.io.StringWriter ; 26 import java.util.ArrayList ; 27 import java.util.Date ; 28 import java.util.List ; 29 import java.util.concurrent.Callable ; 30 import java.util.logging.Level ; 31 import java.util.logging.LogRecord ; 32 import org.openide.util.Exceptions; 33 34 39 public final class UIException { 40 41 42 private UIException() { 43 } 44 45 public static void annotateUser( 46 Throwable t, 47 String msg, 48 String locMsg, 49 Throwable stackTrace, 50 Date date 51 ) { 52 AnnException ex = AnnException.findOrCreate(t, true); 53 LogRecord rec = new LogRecord (OwnLevel.USER, msg); 54 if (stackTrace != null) { 55 rec.setThrown(stackTrace); 56 } 57 ex.addRecord(rec); 58 59 if (locMsg != null) { 60 Exceptions.attachLocalizedMessage(t, locMsg); 61 } 62 } 63 private static final class OwnLevel extends Level { 64 public static final Level USER = new OwnLevel("USER", 1973); 66 private OwnLevel(String s, int i) { 67 super(s, i); 68 } 69 } private static final class AnnException extends Exception implements Callable <LogRecord []> { 71 private List <LogRecord > records; 72 73 static AnnException findOrCreate(Throwable t, boolean create) { 74 if (t instanceof AnnException) { 75 return (AnnException)t; 76 } 77 if (t.getCause() == null) { 78 if (create) { 79 t.initCause(new AnnException()); 80 } 81 return (AnnException)t.getCause(); 82 } 83 return findOrCreate(t.getCause(), create); 84 } 85 86 private AnnException() { 87 } 88 89 public synchronized void addRecord(LogRecord rec) { 90 if (records == null) { 91 records = new ArrayList <LogRecord >(); 92 } 93 records.add(rec); 94 } 95 96 public LogRecord [] call() { 97 List <LogRecord > r = records; 98 LogRecord [] empty = new LogRecord [0]; 99 return r == null ? empty : r.toArray(empty); 100 } 101 } } 103 104 | Popular Tags |