DELL
2024-02-21 4982b9614516dde101c3e44c60a612b3bfd8d6fe
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright 2011-17 Fraunhofer ISE, energy & meteo Systems GmbH and other contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.openmuc.openiec61850;
 
public final class ServiceError extends Exception {
 
    public static final int NO_ERROR = 0;
    public static final int INSTANCE_NOT_AVAILABLE = 1;
    public static final int INSTANCE_IN_USE = 2;
    public static final int ACCESS_VIOLATION = 3;
    public static final int ACCESS_NOT_ALLOWED_IN_CURRENT_STATE = 4;
    public static final int PARAMETER_VALUE_INAPPROPRIATE = 5;
    public static final int PARAMETER_VALUE_INCONSISTENT = 6;
    public static final int CLASS_NOT_SUPPORTED = 7;
    public static final int INSTANCE_LOCKED_BY_OTHER_CLIENT = 8;
    public static final int CONTROL_MUST_BE_SELECTED = 9;
    public static final int TYPE_CONFLICT = 10;
    public static final int FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT = 11;
    public static final int FAILED_DUE_TO_SERVER_CONSTRAINT = 12;
    public static final int APPLICATION_UNREACHABLE = 13;
    public static final int CONNECTION_LOST = 14;
    public static final int MEMORY_UNAVAILABLE = 15;
    public static final int PROCESSOR_RESOURCE_UNAVAILABLE = 16;
    public static final int FATAL = 20;
    // added to handle data access errors mentioned in iec61850-8-1
    // public static final int DATA_ACCESS_ERROR = 21;
    // added to report timeouts
    public static final int TIMEOUT = 22;
    public static final int UNKNOWN = 23;
 
    private static final long serialVersionUID = 4290107163231828564L;
 
    private static String getErrorName(int code) {
        switch (code) {
        case NO_ERROR:
            return "NO_ERROR";
        case INSTANCE_NOT_AVAILABLE:
            return "INSTANCE_NOT_AVAILABLE";
        case INSTANCE_IN_USE:
            return "INSTANCE_IN_USE";
        case ACCESS_VIOLATION:
            return "ACCESS_VIOLATION";
        case ACCESS_NOT_ALLOWED_IN_CURRENT_STATE:
            return "ACCESS_NOT_ALLOWED_IN_CURRENT_STATE";
        case PARAMETER_VALUE_INAPPROPRIATE:
            return "PARAMETER_VALUE_INAPPROPRIATE";
        case PARAMETER_VALUE_INCONSISTENT:
            return "PARAMETER_VALUE_INCONSISTENT";
        case CLASS_NOT_SUPPORTED:
            return "CLASS_NOT_SUPPORTED";
        case INSTANCE_LOCKED_BY_OTHER_CLIENT:
            return "INSTANCE_LOCKED_BY_OTHER_CLIENT";
        case CONTROL_MUST_BE_SELECTED:
            return "CONTROL_MUST_BE_SELECTED";
        case TYPE_CONFLICT:
            return "TYPE_CONFLICT";
        case FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT:
            return "FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT";
        case FAILED_DUE_TO_SERVER_CONSTRAINT:
            return "FAILED_DUE_TO_SERVER_CONSTRAINT";
        case APPLICATION_UNREACHABLE:
            return "APPLICATION_UNREACHABLE";
        case CONNECTION_LOST:
            return "CONNECTION_LOST";
        case MEMORY_UNAVAILABLE:
            return "MEMORY_UNAVAILABLE";
        case PROCESSOR_RESOURCE_UNAVAILABLE:
            return "PROCESSOR_RESOURCE_UNAVAILABLE";
        case FATAL:
            return "FATAL";
        case TIMEOUT:
            return "TIMEOUT_ERROR";
        case UNKNOWN:
            return "UNKNOWN";
        default:
            return "Unknown ServiceError code";
        }
    }
 
    private final int errorCode;
 
    public ServiceError(int errorCode) {
        super("Error code=" + errorCode);
        this.errorCode = errorCode;
    }
 
    public ServiceError(int errorCode, String s) {
        super(s);
        this.errorCode = errorCode;
    }
 
    public ServiceError(int errorCode, Throwable cause) {
        super(cause);
        this.errorCode = errorCode;
    }
 
    public ServiceError(int errorCode, String s, Throwable cause) {
        super(s, cause);
        this.errorCode = errorCode;
    }
 
    public int getErrorCode() {
        return errorCode;
    }
 
    @Override
    public String toString() {
        String message = getLocalizedMessage();
        String result = getClass().getName() + ": " + getErrorName(errorCode) + "(" + errorCode + ")";
        if (message != null) {
            result += ": " + message;
        }
        return result;
    }
}