|
@@ -23,10 +23,10 @@
|
23
|
23
|
*/
|
24
|
24
|
|
25
|
25
|
package com.dmdirc.parser;
|
26
|
|
-import com.dmdirc.parser.callbacks.interfaces.INumeric;
|
|
26
|
+
|
27
|
27
|
import com.dmdirc.parser.callbacks.CallbackOnNumeric;
|
|
28
|
+
|
28
|
29
|
import java.util.Hashtable;
|
29
|
|
-import java.util.Enumeration;
|
30
|
30
|
|
31
|
31
|
/**
|
32
|
32
|
* IRC Parser Processing Manager.
|
|
@@ -40,7 +40,7 @@ public class ProcessingManager {
|
40
|
40
|
IRCParser myParser = null;
|
41
|
41
|
|
42
|
42
|
/** Hashtable used to store the different types of IRCProcessor known. */
|
43
|
|
- private Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
|
|
43
|
+ private final Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
|
44
|
44
|
|
45
|
45
|
/**
|
46
|
46
|
* Constructor to create a ProcessingManager
|
|
@@ -54,7 +54,7 @@ public class ProcessingManager {
|
54
|
54
|
/**
|
55
|
55
|
* Debugging Data to the console.
|
56
|
56
|
*/
|
57
|
|
- private void DoDebug(String line, Object... args) {
|
|
57
|
+ private void DoDebug(final String line, final Object... args) {
|
58
|
58
|
myParser.callDebugInfo(myParser.DEBUG_PROCESSOR, line, args);
|
59
|
59
|
}
|
60
|
60
|
|
|
@@ -129,18 +129,13 @@ public class ProcessingManager {
|
129
|
129
|
public void empty() {
|
130
|
130
|
processHash.clear();
|
131
|
131
|
}
|
132
|
|
-
|
133
|
|
- /** Empty clone method to prevent cloning to get more copies of the ProcessingManager */
|
134
|
|
- public Object clone() throws CloneNotSupportedException {
|
135
|
|
- throw new CloneNotSupportedException();
|
136
|
|
- }
|
137
|
132
|
|
138
|
133
|
/**
|
139
|
134
|
* Add new Process type.
|
140
|
135
|
*
|
141
|
136
|
* @param processor IRCProcessor subclass for the processor.
|
142
|
137
|
*/
|
143
|
|
- public void addProcessor(IRCProcessor processor) {
|
|
138
|
+ public void addProcessor(final IRCProcessor processor) {
|
144
|
139
|
// handles() returns a String array of all the tokens
|
145
|
140
|
// that this processor will parse.
|
146
|
141
|
addProcessor(processor.handles(), processor);
|
|
@@ -152,7 +147,7 @@ public class ProcessingManager {
|
152
|
147
|
* @param processor IRCProcessor subclass for the processor.
|
153
|
148
|
* @param handles String Array of tokens to add this processor as a hadler for
|
154
|
149
|
*/
|
155
|
|
- public void addProcessor(String[] handles, IRCProcessor processor) {
|
|
150
|
+ public void addProcessor(final String[] handles, final IRCProcessor processor) {
|
156
|
151
|
DoDebug("Adding processor: "+processor.getName());
|
157
|
152
|
|
158
|
153
|
try {
|
|
@@ -175,12 +170,10 @@ public class ProcessingManager {
|
175
|
170
|
*
|
176
|
171
|
* @param processor IRCProcessor subclass for the processor.
|
177
|
172
|
*/
|
178
|
|
- public void delProcessor(IRCProcessor processor) {
|
|
173
|
+ public void delProcessor(final IRCProcessor processor) {
|
179
|
174
|
IRCProcessor testProcessor;
|
180
|
|
- String elementName;
|
181
|
175
|
DoDebug("Deleting processor: "+processor.getName());
|
182
|
|
- for (Enumeration e = processHash.keys(); e.hasMoreElements();) {
|
183
|
|
- elementName = (String)e.nextElement();
|
|
176
|
+ for (String elementName : processHash.keySet()) {
|
184
|
177
|
DoDebug("\t Checking handler for: "+elementName);
|
185
|
178
|
testProcessor = processHash.get(elementName);
|
186
|
179
|
if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
|
|
@@ -196,7 +189,7 @@ public class ProcessingManager {
|
196
|
189
|
* @param sParam Type of line to process ("005", "PRIVMSG" etc)
|
197
|
190
|
* @return IRCProcessor for the given param.
|
198
|
191
|
*/
|
199
|
|
- public IRCProcessor getProcessor(String sParam) throws ProcessorNotFound {
|
|
192
|
+ public IRCProcessor getProcessor(final String sParam) throws ProcessorNotFound {
|
200
|
193
|
if (processHash.containsKey(sParam.toLowerCase())) {
|
201
|
194
|
return processHash.get(sParam.toLowerCase());
|
202
|
195
|
} else {
|
|
@@ -211,7 +204,7 @@ public class ProcessingManager {
|
211
|
204
|
* @param token IRCTokenised line to process
|
212
|
205
|
* @throws ProcessorNotFound exception if no processors exists to handle the line
|
213
|
206
|
*/
|
214
|
|
- public void process(String sParam, String[] token) throws ProcessorNotFound {
|
|
207
|
+ public void process(final String sParam, final String[] token) throws ProcessorNotFound {
|
215
|
208
|
IRCProcessor messageProcessor = null;
|
216
|
209
|
try {
|
217
|
210
|
messageProcessor = getProcessor(sParam);
|
|
@@ -219,9 +212,9 @@ public class ProcessingManager {
|
219
|
212
|
} catch (ProcessorNotFound p) {
|
220
|
213
|
throw p;
|
221
|
214
|
} catch (Exception e) {
|
222
|
|
- StringBuilder line = new StringBuilder();
|
|
215
|
+ final StringBuilder line = new StringBuilder();
|
223
|
216
|
for (int i = 0; i < token.length; ++i ) { line.append(" ").append(token[i]); }
|
224
|
|
- ParserError ei = new ParserError(ParserError.ERROR_WARNING,"Exception in Parser. [Param: "+sParam+"] [Processor: "+messageProcessor+"]", line.toString().trim());
|
|
217
|
+ final ParserError ei = new ParserError(ParserError.ERROR_WARNING,"Exception in Parser. [Param: "+sParam+"] [Processor: "+messageProcessor+"]", line.toString().trim());
|
225
|
218
|
ei.setException(e);
|
226
|
219
|
myParser.callErrorInfo(ei);
|
227
|
220
|
} finally {
|
|
@@ -241,8 +234,8 @@ public class ProcessingManager {
|
241
|
234
|
* @param token IRC Tokenised line
|
242
|
235
|
* @return true if a method was called, false otherwise
|
243
|
236
|
*/
|
244
|
|
- protected boolean callNumeric(int numeric, String[] token) {
|
245
|
|
- CallbackOnNumeric cb = (CallbackOnNumeric)myParser.getCallbackManager().getCallbackType("OnNumeric");
|
|
237
|
+ protected boolean callNumeric(final int numeric, final String[] token) {
|
|
238
|
+ final CallbackOnNumeric cb = (CallbackOnNumeric)myParser.getCallbackManager().getCallbackType("OnNumeric");
|
246
|
239
|
if (cb != null) { return cb.call(numeric, token); }
|
247
|
240
|
return false;
|
248
|
241
|
}
|