Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d2054ad0e1a72585d3ffaa32c6d35e24444b2de0 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.tcf.core;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.tm.tcf.protocol.IErrorReport;

public class ErrorReport extends Exception implements IErrorReport {

    private static final long serialVersionUID = 3687543884858739977L;
    private final Map<String,Object> attrs;

    @SuppressWarnings("unchecked")
    public ErrorReport(String msg, Map<String,Object> attrs) {
        super(msg);
        this.attrs = attrs;
        Object caused_by = attrs.get(IErrorReport.ERROR_CAUSED_BY);
        if (caused_by != null) {
            Map<String,Object> map = (Map<String,Object>)caused_by;
            StringBuffer bf = new StringBuffer();
            bf.append("TCF error report:");
            bf.append('\n');
            Command.appendErrorProps(bf, map);
            initCause(new ErrorReport(bf.toString(), map));
        }
    }

    public ErrorReport(String msg, int code) {
        super(msg);
        attrs = new HashMap<String,Object>();
        attrs.put(ERROR_CODE, code);
        attrs.put(ERROR_TIME, System.currentTimeMillis());
        attrs.put(ERROR_FORMAT, msg);
        attrs.put(ERROR_SEVERITY, SEVERITY_ERROR);
    }

    public int getErrorCode() {
        Number n = (Number)attrs.get(ERROR_CODE);
        if (n == null) return 0;
        return n.intValue();
    }

    public int getAltCode() {
        Number n = (Number)attrs.get(ERROR_ALT_CODE);
        if (n == null) return 0;
        return n.intValue();
    }

    public String getAltOrg() {
        return (String)attrs.get(ERROR_ALT_ORG);
    }

    public Map<String, Object> getAttributes() {
        return attrs;
    }
}

Back to the top