summaryrefslogtreecommitdiffstats
path: root/tags/java-stable-20060304/sca/common/src/main/java/org/apache/tuscany/common/TuscanyRuntimeException.java
blob: 922705f7b50e7b1253547e4a07dfe28c1d2f96a8 (plain)
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
package org.apache.tuscany.common;

import java.util.ArrayList;
import java.util.List;

/**
 * The root unchecked exception for the Tuscany runtime
 * 
 * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $
 */

public abstract class TuscanyRuntimeException extends RuntimeException {

    protected List<String> contextStack;

    protected String moduleComponentName;

    protected String componentName;

    public TuscanyRuntimeException() {
        super();
    }

    public TuscanyRuntimeException(String message) {
        super(message);
    }

    public TuscanyRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    public TuscanyRuntimeException(Throwable cause) {
        super(cause);
    }

    /**
     * Returns a collection of names representing the context call stack where the error occured. The top of the stack
     * is the first element in the collection.
     */
    public List<String> returnContextNames(String name) {
        if (contextStack == null) {
            contextStack = new ArrayList();
        }
        return contextStack;
    }

    /**
     * Pushes a context name where an error occured onto the call stack
     */
    public void addContextName(String name) {
        if (contextStack == null) {
            contextStack = new ArrayList();
        }
        contextStack.add(name);
    }

    private String identifier;

    /**
     * Returns a string representing additional error information referred to in the error message
     */
    public String getIdentifier() {
        return identifier;
    }

    /**
     * Sets an additional error information referred to in the error message
     */
    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getMessage() {
        if (identifier == null && contextStack == null) {
            return super.getMessage();
        }
        StringBuffer b = new StringBuffer();
        if (identifier != null) {
            b.append(" [" + identifier + "]");
        }
        if (contextStack != null) {
            b.append("\nContext stack trace: ");
            for (int i = contextStack.size() - 1; i >= 0; i--) {
                b.append("[" + contextStack.get(i) + "]");
            }
        }
        return super.getMessage() + b.toString();

    }

}