litesoft
@ 724
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / support / ExceptionDialogBasedSystemErrorReporter.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
package com.temp.client.foundation.support; import java.util.LinkedHashMap; import java.util.Map; import com.temp.client.foundation.handler.DialogClose; import com.temp.client.foundation.widget.dialog.ExceptionDialog; import com.temp.shared.utils.Assert; import com.temp.shared.utils.ContextThrowables; import com.temp.shared.utils.SourceIssues; import com.temp.shared.utils.StringUtils; import com.temp.shared.utils.SystemErrorReporter; import org.litesoft.core.util.TemplateSource; /** * A SystemErrorReporter that utilizes an ExceptionDialog. * * This class is specifically designed to group multiple exceptions from the * same "source" into a single dialog. This means that if there is an * expectation that multiple exceptions are possible/likely, then the templates * for that source should explicitly indicate that the Exception message NOT be * shown! * * @author georgs */ public class ExceptionDialogBasedSystemErrorReporter implements SystemErrorReporter, DialogClose { public static final String ERROR_PERSISTS_CONTACT_TEXT = "If the error persists, please open a Contact Us."; private final TemplateSource ts; private String currentDialogSource; private ExceptionDialog currentDialog; private Map<String, SourceIssues> pendingIssues = new LinkedHashMap<String, SourceIssues>(); public ExceptionDialogBasedSystemErrorReporter(TemplateSource ts) { this.ts = ts; } @Override public void reportSystemError(String source, String context, Throwable throwable) { source = Assert.noEmpty("source", source); context = StringUtils.noEmpty(context); Assert.notNull("throwable", throwable); if (currentDialog != null) { if (source.equals(currentDialogSource)) { currentDialog.add(context, throwable); } else { SourceIssues issues = pendingIssues.get(source); if (issues == null) { pendingIssues.put(source, new SourceIssues(source, context, throwable)); } else { issues.add(context, throwable); } } return; } currentDialog = createDialog(currentDialogSource = source, context, throwable); currentDialog.show(this); } /** * Dialog Close Callback * * If there are any pending issues (SourceIssues) then display the next one. */ @Override public void closed() { if (pendingIssues.isEmpty()) { currentDialogSource = null; currentDialog = null; } else { SourceIssues issues = pendingIssues.values().iterator().next(); String source = issues.getSource(); pendingIssues.remove(source); ContextThrowables[] contextThrowables = issues.getContextThrowables(); ContextThrowables ct = contextThrowables[0]; // this class, SourceIssues, & ContextThrowables all assure that there is at least one Throwable! String context = ct.getContext(); Throwable[] throwables = ct.getThrowables(); currentDialog = createDialog(currentDialogSource = source, context, throwables[0]); for (int i = 1; i < throwables.length; i++) { currentDialog.add(context, throwables[i]); } for (int i = 1; i < contextThrowables.length; i++) { ct = contextThrowables[i]; currentDialog.add(ct.getContext(), ct.getThrowables()); } currentDialog.show(this); } } protected ExceptionDialog createDialog(String source, String context, Throwable throwable) { ExceptionDisplayHelper helper = new ExceptionDisplayHelper(ts, source, context, throwable, // "", // ERROR_PERSISTS_CONTACT_TEXT); return new ExceptionDialog(helper.noDetails(), helper.getTitle(), source, context, throwable, helper.getTextBlocks()); } } |