|
@@ -1,16 +1,16 @@
|
1
|
1
|
/*
|
2
|
2
|
* Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
3
|
|
- *
|
|
3
|
+ *
|
4
|
4
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
5
|
* of this software and associated documentation files (the "Software"), to deal
|
6
|
6
|
* in the Software without restriction, including without limitation the rights
|
7
|
7
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
8
|
* copies of the Software, and to permit persons to whom the Software is
|
9
|
9
|
* furnished to do so, subject to the following conditions:
|
10
|
|
- *
|
|
10
|
+ *
|
11
|
11
|
* The above copyright notice and this permission notice shall be included in
|
12
|
12
|
* all copies or substantial portions of the Software.
|
13
|
|
- *
|
|
13
|
+ *
|
14
|
14
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
15
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
16
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -24,154 +24,165 @@ package com.dmdirc.parser.common;
|
24
|
24
|
|
25
|
25
|
/**
|
26
|
26
|
* IRC Parser Error.
|
27
|
|
- *
|
|
27
|
+ *
|
28
|
28
|
* @author Shane Mc Cormack
|
29
|
29
|
*/
|
30
|
30
|
public final class ParserError {
|
31
|
|
- /** Error is potentially Fatal, Desync 99% Guaranteed! */
|
32
|
|
- public static final int ERROR_FATAL = 1;
|
33
|
|
- /** Error is not fatal, but is more severe than a warning. */
|
34
|
|
- public static final int ERROR_ERROR = 2;
|
35
|
|
- /** Error was an unexpected occurance, but shouldn't be anything to worry about. */
|
36
|
|
- public static final int ERROR_WARNING = 4;
|
37
|
|
- /** Error is a user-error rather than a server error. */
|
38
|
|
- public static final int ERROR_USER = 8;
|
39
|
|
- /** Error was an exception from elsewhere. */
|
40
|
|
- public static final int ERROR_EXCEPTION = 16;
|
41
|
|
-
|
42
|
|
- /** Store the Error level. */
|
43
|
|
- private int errorLevel;
|
44
|
|
- /** Store the Error Information. */
|
45
|
|
- private String errorData;
|
46
|
|
- /** Store the Exception object. */
|
47
|
|
- private Exception exceptionInfo;
|
48
|
|
-
|
49
|
|
- /** Last line of server input before this exception was triggered. */
|
50
|
|
- private String lastLine = "";
|
51
|
|
-
|
52
|
|
- /**
|
53
|
|
- * Create a new Error.
|
54
|
|
- *
|
55
|
|
- * @param level Set the error level.
|
56
|
|
- * @param data String containing information about the error.
|
57
|
|
- * @param line The last line of data recieved from the server before this exception.
|
58
|
|
- */
|
59
|
|
- public ParserError(final int level, final String data, final String line) {
|
60
|
|
- errorData = data;
|
61
|
|
- errorLevel = level;
|
62
|
|
- lastLine = line;
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- /**
|
66
|
|
- * Check if this error is considered Fatal.
|
67
|
|
- *
|
68
|
|
- * @return Returns true for a fatal error, false for a non-fatal error
|
69
|
|
- */
|
70
|
|
- public boolean isFatal() {
|
71
|
|
- return (errorLevel & ERROR_FATAL) == ERROR_FATAL;
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- /**
|
75
|
|
- * Check if this error is considered an error (less severe than fatal, worse than warning).
|
76
|
|
- *
|
77
|
|
- * @return Returns true for an "Error" level error, else false.
|
78
|
|
- */
|
79
|
|
- public boolean isError() {
|
80
|
|
- return (errorLevel & ERROR_ERROR) == ERROR_ERROR;
|
81
|
|
- }
|
82
|
|
-
|
83
|
|
- /**
|
84
|
|
- * Check if this error is considered a warning.
|
85
|
|
- *
|
86
|
|
- * @return Returns true for a warning, else false.
|
87
|
|
- */
|
88
|
|
- public boolean isWarning() {
|
89
|
|
- return (errorLevel & ERROR_WARNING) == ERROR_WARNING;
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- /**
|
93
|
|
- * Check if this error is considered a user-error rather than a server error.
|
94
|
|
- * For DMDirc this will cause the error not to be reported to the developers
|
95
|
|
- *
|
96
|
|
- * @return Returns true for a user error, else false.
|
97
|
|
- */
|
98
|
|
- public boolean isUserError() {
|
99
|
|
- return (errorLevel & ERROR_USER) == ERROR_USER;
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- /**
|
103
|
|
- * Check if this error was generated from an exception.
|
104
|
|
- *
|
105
|
|
- * @return Returns true if getException will return an exception.
|
106
|
|
- */
|
107
|
|
- public boolean isException() {
|
108
|
|
- return (errorLevel & ERROR_EXCEPTION) == ERROR_EXCEPTION;
|
109
|
|
- }
|
110
|
|
-
|
111
|
|
- /**
|
112
|
|
- * Check if this error has a lastLine parameter.
|
113
|
|
- *
|
114
|
|
- * @return Returns true if getLastLine returns anything non null, non empty.
|
115
|
|
- */
|
116
|
|
- public boolean hasLastLine() {
|
117
|
|
- return (lastLine != null && !lastLine.isEmpty());
|
118
|
|
- }
|
119
|
|
-
|
120
|
|
- /**
|
121
|
|
- * Set the Exception object.
|
122
|
|
- *
|
123
|
|
- * @param newException The exception object to store
|
124
|
|
- */
|
125
|
|
- public void setException(final Exception newException) {
|
126
|
|
- exceptionInfo = newException;
|
127
|
|
- if (!this.isException()) {
|
128
|
|
- this.errorLevel = this.errorLevel + ERROR_EXCEPTION;
|
129
|
|
- }
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- /**
|
133
|
|
- * Get the Exception object.
|
134
|
|
- *
|
135
|
|
- * @return Returns the exception object
|
136
|
|
- */
|
137
|
|
- public Exception getException() {
|
138
|
|
- return exceptionInfo;
|
139
|
|
- }
|
140
|
|
-
|
141
|
|
- /**
|
142
|
|
- * Get the full ErrorLevel.
|
143
|
|
- *
|
144
|
|
- * @return Returns the error level
|
145
|
|
- */
|
146
|
|
- public int getLevel() {
|
147
|
|
- return errorLevel;
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- /**
|
151
|
|
- * Get the Error information.
|
152
|
|
- *
|
153
|
|
- * @return Returns the error data
|
154
|
|
- */
|
155
|
|
- public String getData() {
|
156
|
|
- return errorData;
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- /**
|
160
|
|
- * Add to the error information.
|
161
|
|
- *
|
162
|
|
- * @param data Information to add to the end of the existing Data
|
163
|
|
- */
|
164
|
|
- public void appendData(final String data) {
|
165
|
|
- errorData = errorData + '[' + data + ']';
|
166
|
|
- }
|
167
|
|
-
|
168
|
|
- /**
|
169
|
|
- * Get the last line recieved from the server before this exception.
|
170
|
|
- *
|
171
|
|
- * @return Returns the error data
|
172
|
|
- */
|
173
|
|
- public String getLastLine() {
|
174
|
|
- return lastLine;
|
175
|
|
- }
|
|
31
|
+ /** Error is potentially Fatal, Desync 99% Guaranteed! */
|
|
32
|
+ public static final int ERROR_FATAL = 1;
|
|
33
|
+ /** Error is not fatal, but is more severe than a warning. */
|
|
34
|
+ public static final int ERROR_ERROR = 2;
|
|
35
|
+ /**
|
|
36
|
+ * Error was an unexpected occurance, but shouldn't be anything to worry
|
|
37
|
+ * about.
|
|
38
|
+ */
|
|
39
|
+ public static final int ERROR_WARNING = 4;
|
|
40
|
+ /** Error is a user-error rather than a server error. */
|
|
41
|
+ public static final int ERROR_USER = 8;
|
|
42
|
+ /** Error was an exception from elsewhere. */
|
|
43
|
+ public static final int ERROR_EXCEPTION = 16;
|
|
44
|
+
|
|
45
|
+ /** Store the Error level. */
|
|
46
|
+ private int errorLevel;
|
|
47
|
+ /** Store the Error Information. */
|
|
48
|
+ private String errorData;
|
|
49
|
+ /** Store the Exception object. */
|
|
50
|
+ private Exception exceptionInfo;
|
|
51
|
+
|
|
52
|
+ /** Last line of server input before this exception was triggered. */
|
|
53
|
+ private String lastLine = "";
|
|
54
|
+
|
|
55
|
+ /**
|
|
56
|
+ * Create a new Error.
|
|
57
|
+ *
|
|
58
|
+ * @param level
|
|
59
|
+ * Set the error level.
|
|
60
|
+ * @param data
|
|
61
|
+ * String containing information about the error.
|
|
62
|
+ * @param line
|
|
63
|
+ * The last line of data recieved from the server before this
|
|
64
|
+ * exception.
|
|
65
|
+ */
|
|
66
|
+ public ParserError(final int level, final String data, final String line) {
|
|
67
|
+ errorData = data;
|
|
68
|
+ errorLevel = level;
|
|
69
|
+ lastLine = line;
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ /**
|
|
73
|
+ * Check if this error is considered Fatal.
|
|
74
|
+ *
|
|
75
|
+ * @return Returns true for a fatal error, false for a non-fatal error
|
|
76
|
+ */
|
|
77
|
+ public boolean isFatal() {
|
|
78
|
+ return (errorLevel & ERROR_FATAL) == ERROR_FATAL;
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ /**
|
|
82
|
+ * Check if this error is considered an error (less severe than fatal, worse
|
|
83
|
+ * than warning).
|
|
84
|
+ *
|
|
85
|
+ * @return Returns true for an "Error" level error, else false.
|
|
86
|
+ */
|
|
87
|
+ public boolean isError() {
|
|
88
|
+ return (errorLevel & ERROR_ERROR) == ERROR_ERROR;
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ /**
|
|
92
|
+ * Check if this error is considered a warning.
|
|
93
|
+ *
|
|
94
|
+ * @return Returns true for a warning, else false.
|
|
95
|
+ */
|
|
96
|
+ public boolean isWarning() {
|
|
97
|
+ return (errorLevel & ERROR_WARNING) == ERROR_WARNING;
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ /**
|
|
101
|
+ * Check if this error is considered a user-error rather than a server
|
|
102
|
+ * error.
|
|
103
|
+ * For DMDirc this will cause the error not to be reported to the developers
|
|
104
|
+ *
|
|
105
|
+ * @return Returns true for a user error, else false.
|
|
106
|
+ */
|
|
107
|
+ public boolean isUserError() {
|
|
108
|
+ return (errorLevel & ERROR_USER) == ERROR_USER;
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ /**
|
|
112
|
+ * Check if this error was generated from an exception.
|
|
113
|
+ *
|
|
114
|
+ * @return Returns true if getException will return an exception.
|
|
115
|
+ */
|
|
116
|
+ public boolean isException() {
|
|
117
|
+ return (errorLevel & ERROR_EXCEPTION) == ERROR_EXCEPTION;
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ /**
|
|
121
|
+ * Check if this error has a lastLine parameter.
|
|
122
|
+ *
|
|
123
|
+ * @return Returns true if getLastLine returns anything non null, non empty.
|
|
124
|
+ */
|
|
125
|
+ public boolean hasLastLine() {
|
|
126
|
+ return lastLine != null && !lastLine.isEmpty();
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ /**
|
|
130
|
+ * Set the Exception object.
|
|
131
|
+ *
|
|
132
|
+ * @param newException
|
|
133
|
+ * The exception object to store
|
|
134
|
+ */
|
|
135
|
+ public void setException(final Exception newException) {
|
|
136
|
+ exceptionInfo = newException;
|
|
137
|
+ if (!isException()) {
|
|
138
|
+ errorLevel += ERROR_EXCEPTION;
|
|
139
|
+ }
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ /**
|
|
143
|
+ * Get the Exception object.
|
|
144
|
+ *
|
|
145
|
+ * @return Returns the exception object
|
|
146
|
+ */
|
|
147
|
+ public Exception getException() {
|
|
148
|
+ return exceptionInfo;
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ /**
|
|
152
|
+ * Get the full ErrorLevel.
|
|
153
|
+ *
|
|
154
|
+ * @return Returns the error level
|
|
155
|
+ */
|
|
156
|
+ public int getLevel() {
|
|
157
|
+ return errorLevel;
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ /**
|
|
161
|
+ * Get the Error information.
|
|
162
|
+ *
|
|
163
|
+ * @return Returns the error data
|
|
164
|
+ */
|
|
165
|
+ public String getData() {
|
|
166
|
+ return errorData;
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ /**
|
|
170
|
+ * Add to the error information.
|
|
171
|
+ *
|
|
172
|
+ * @param data
|
|
173
|
+ * Information to add to the end of the existing Data
|
|
174
|
+ */
|
|
175
|
+ public void appendData(final String data) {
|
|
176
|
+ errorData += '[' + data + ']';
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ /**
|
|
180
|
+ * Get the last line recieved from the server before this exception.
|
|
181
|
+ *
|
|
182
|
+ * @return Returns the error data
|
|
183
|
+ */
|
|
184
|
+ public String getLastLine() {
|
|
185
|
+ return lastLine;
|
|
186
|
+ }
|
176
|
187
|
|
177
|
188
|
}
|