|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.common; |
|
19 |
| |
|
20 |
| import java.io.File; |
|
21 |
| import java.io.IOException; |
|
22 |
| import java.net.URL; |
|
23 |
| |
|
24 |
| import org.qedeq.kernel.utility.IoUtility; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public class SourceFileException extends QedeqException { |
|
34 |
| |
|
35 |
| |
|
36 |
| private static final long serialVersionUID = -4109767904038020052L; |
|
37 |
| |
|
38 |
| |
|
39 |
| private final SourceArea errorArea; |
|
40 |
| |
|
41 |
| |
|
42 |
| private final SourceArea referenceArea; |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
132
| public SourceFileException(final int errorCode, final String errorText,
|
|
54 |
| final Throwable exception, final SourceArea errorArea, final SourceArea referenceArea) { |
|
55 |
132
| super(errorCode, errorText, exception);
|
|
56 |
132
| this.errorArea = errorArea;
|
|
57 |
132
| this.referenceArea = referenceArea;
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
79
| public SourceFileException(final QedeqException exception, final SourceArea errorArea,
|
|
69 |
| final SourceArea referenceArea) { |
|
70 |
79
| this(exception.getErrorCode(), exception.getMessage(), exception, errorArea, referenceArea);
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
0
| public SourceFileException(final URL url, final Exception exception) {
|
|
81 |
0
| super(9997, exception.toString(), exception);
|
|
82 |
0
| errorArea = new SourceArea(url, new SourcePosition(url, 1, 1), null);
|
|
83 |
0
| referenceArea = null;
|
|
84 |
| } |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
0
| public SourceFileException(final File file, final Exception exception) {
|
|
93 |
0
| super(9998, exception.getMessage(), exception);
|
|
94 |
0
| final URL url = IoUtility.toUrl(file);
|
|
95 |
0
| errorArea = new SourceArea(url, new SourcePosition(url, 1, 1), null);
|
|
96 |
0
| referenceArea = null;
|
|
97 |
| } |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
11
| public SourceFileException(final Exception exception) {
|
|
105 |
11
| super(9999, exception.getMessage(), exception);
|
|
106 |
11
| errorArea = null;
|
|
107 |
11
| referenceArea = null;
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
0
| public SourceFileException(final Throwable exception) {
|
|
116 |
0
| super(1000, exception.toString(), exception);
|
|
117 |
0
| errorArea = null;
|
|
118 |
0
| referenceArea = null;
|
|
119 |
| } |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
3
| public SourceFileException(final IOException exception) {
|
|
127 |
3
| super(9997, exception.toString(), exception);
|
|
128 |
3
| errorArea = null;
|
|
129 |
3
| referenceArea = null;
|
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
463
| public SourceArea getSourceArea() {
|
|
138 |
463
| return errorArea;
|
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
0
| public SourceArea getReferenceArea() {
|
|
147 |
0
| return referenceArea;
|
|
148 |
| } |
|
149 |
| |
|
150 |
309
| public String getMessage() {
|
|
151 |
309
| if (getCause() != null) {
|
|
152 |
309
| if (getCause() instanceof IOException) {
|
|
153 |
7
| return getCause().toString();
|
|
154 |
| } |
|
155 |
302
| if (getCause().getCause() != null) {
|
|
156 |
0
| return getCause().getCause().getMessage();
|
|
157 |
| } |
|
158 |
302
| return getCause().getMessage();
|
|
159 |
| } |
|
160 |
0
| return "";
|
|
161 |
| } |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
273
| public String getDescription() {
|
|
171 |
273
| final StringBuffer buffer = new StringBuffer();
|
|
172 |
273
| buffer.append(getErrorCode() + ": " + getMessage());
|
|
173 |
273
| if (errorArea != null && errorArea.getStartPosition() != null) {
|
|
174 |
256
| final SourcePosition start = errorArea.getStartPosition();
|
|
175 |
256
| buffer.append("\n");
|
|
176 |
256
| buffer.append(errorArea.getAddress() + ":" + start.getLine() + ":"
|
|
177 |
| + start.getColumn()); |
|
178 |
| } |
|
179 |
273
| return buffer.toString();
|
|
180 |
| } |
|
181 |
| |
|
182 |
260
| public String toString() {
|
|
183 |
260
| return getDescription();
|
|
184 |
| } |
|
185 |
| } |