1
2
3
4
5
6 package gov.nist.secauto.metaschema.core.metapath;
7
8 import edu.umd.cs.findbugs.annotations.Nullable;
9
10
11
12
13
14 public abstract class AbstractCodedMetapathException
15 extends MetapathException {
16
17
18
19
20 private static final long serialVersionUID = 1L;
21
22
23
24
25 private final int code;
26
27
28
29
30
31
32
33
34
35
36 public AbstractCodedMetapathException(int code, String message) {
37 super(message);
38 this.code = code;
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52 public AbstractCodedMetapathException(int code, String message, Throwable cause) {
53 super(message, cause);
54 this.code = code;
55 }
56
57
58
59
60
61
62
63
64
65
66 public AbstractCodedMetapathException(int code, Throwable cause) {
67 super(cause);
68 this.code = code;
69 }
70
71 @Override
72 public String getMessage() {
73 String message = getMessageText();
74 return String.format("%s%s", getCodeAsString(), message == null ? "" : ": " + message);
75 }
76
77
78
79
80
81
82 @Nullable
83 public String getMessageText() {
84 return super.getMessage();
85 }
86
87
88
89
90
91
92 public int getCode() {
93 return code;
94 }
95
96
97
98
99
100
101 public abstract String getCodePrefix();
102
103
104
105
106
107
108 protected String getCodeAsString() {
109 return String.format("%s%04d", getCodePrefix(), getCode());
110 }
111 }