Subversion Repository Public Repository

litesoft

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
package com.temp.client.foundation.support;

import org.litesoft.core.util.*;

import com.temp.client.foundation.handler.*;
import com.temp.client.foundation.widget.dialog.*;
import com.temp.shared.utils.*;

import java.util.*;

/**
 * A SystemErrorReporter that utilizes an ExceptionDialog.
 * <p/>
 * 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
     * <p/>
     * 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() );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/support/ExceptionDialogBasedSystemErrorReporter.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

724 Diff Diff GeorgeS picture GeorgeS Mon 11 Jun, 2012 00:47:26 +0000
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000