File Source: ParserError.java
/*
P/P * Method: com.dmdirc.parser.irc.ParserError__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.parser.irc;
24
25 /**
26 * IRC Parser Error.
27 *
28 * @author Shane Mc Cormack
29 */
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 */
/*
P/P * Method: void com.dmdirc.parser.irc.ParserError(int, String, String)
*
* Postconditions:
* this.errorData == data
* init'ed(this.errorData)
* this.errorLevel == level
* init'ed(this.errorLevel)
* this.lastLine == line
* init'ed(this.lastLine)
*/
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() {
/*
P/P * Method: bool isFatal()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: bool isError()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: bool isWarning()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: bool isUserError()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: bool isException()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: bool hasLastLine()
*
* Preconditions:
* init'ed(this.lastLine)
*
* Postconditions:
* init'ed(return_value)
*/
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) {
/*
P/P * Method: void setException(Exception)
*
* Preconditions:
* (soft) this.errorLevel <= 4_294_967_279
*
* Postconditions:
* this.errorLevel == One-of{old this.errorLevel, old this.errorLevel + 16}
* init'ed(this.errorLevel)
* this.exceptionInfo == newException
* init'ed(this.exceptionInfo)
*
* Test Vectors:
* this.errorLevel & 16: {16}, {0..15}
*/
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() {
/*
P/P * Method: Exception getException()
*
* Preconditions:
* init'ed(this.exceptionInfo)
*
* Postconditions:
* return_value == this.exceptionInfo
* init'ed(return_value)
*/
138 return exceptionInfo;
139 }
140
141 /**
142 * Get the full ErrorLevel.
143 *
144 * @return Returns the error level
145 */
146 public int getLevel() {
/*
P/P * Method: int getLevel()
*
* Preconditions:
* init'ed(this.errorLevel)
*
* Postconditions:
* return_value == this.errorLevel
* init'ed(return_value)
*/
147 return errorLevel;
148 }
149
150 /**
151 * Get the Error information.
152 *
153 * @return Returns the error data
154 */
155 public String getData() {
/*
P/P * Method: String getData()
*
* Preconditions:
* init'ed(this.errorData)
*
* Postconditions:
* return_value == this.errorData
* init'ed(return_value)
*/
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) {
/*
P/P * Method: void appendData(String)
*
* Preconditions:
* init'ed(this.errorData)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.errorData == &java.lang.StringBuilder:toString(...)
*/
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() {
/*
P/P * Method: String getLastLine()
*
* Preconditions:
* init'ed(this.lastLine)
*
* Postconditions:
* return_value == this.lastLine
* init'ed(return_value)
*/
174 return lastLine;
175 }
176
177 }
SofCheck Inspector Build Version : 2.17854
| ParserError.java |
2009-Jun-25 01:54:24 |
| ParserError.class |
2009-Sep-02 17:04:12 |