Browse Source

* Server now handles errors thrown by the IRC Parser, and forwards them to Logger

git-svn-id: http://svn.dmdirc.com/trunk@186 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 years ago
parent
commit
83e2828095
1 changed files with 31 additions and 8 deletions
  1. 31
    8
      src/uk/org/ownage/dmdirc/Server.java

+ 31
- 8
src/uk/org/ownage/dmdirc/Server.java View File

@@ -24,12 +24,15 @@ package uk.org.ownage.dmdirc;
24 24
 
25 25
 import java.util.Hashtable;
26 26
 import uk.org.ownage.dmdirc.commandparser.ServerCommandParser;
27
+import uk.org.ownage.dmdirc.logger.ErrorLevel;
27 28
 import uk.org.ownage.dmdirc.parser.ChannelInfo;
29
+import uk.org.ownage.dmdirc.parser.ParserError;
28 30
 import uk.org.ownage.dmdirc.parser.ServerInfo;
29 31
 import uk.org.ownage.dmdirc.ui.MainFrame;
30 32
 import uk.org.ownage.dmdirc.ui.ServerFrame;
31 33
 import java.util.Vector;
32 34
 import uk.org.ownage.dmdirc.parser.IRCParser;
35
+import uk.org.ownage.dmdirc.logger.Logger;
33 36
 
34 37
 /**
35 38
  * The Server class represents the client's view of a server. It maintains
@@ -37,7 +40,7 @@ import uk.org.ownage.dmdirc.parser.IRCParser;
37 40
  * to the server
38 41
  * @author chris
39 42
  */
40
-public class Server {
43
+public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo {
41 44
     
42 45
     /**
43 46
      * Open channels that currently exist on the server
@@ -73,13 +76,9 @@ public class Server {
73 76
               
74 77
         parser = new IRCParser(new ServerInfo(server, port, password));
75 78
         
76
-        parser.addChannelSelfJoin(new IRCParser.IChannelSelfJoin() {
77
-            public void onChannelSelfJoin(IRCParser tParser, ChannelInfo cChannel) {
78
-                Server.this.addChannel(cChannel);
79
-            }
80
-            
81
-        });
82
-        
79
+        parser.addChannelSelfJoin(this);
80
+        parser.addErrorInfo(this);
81
+                
83 82
         Raw raw = new Raw(this);
84 83
               
85 84
         try {           
@@ -113,5 +112,29 @@ public class Server {
113 112
     private void addChannel(ChannelInfo chan) {
114 113
         channels.put(chan.getName(), new Channel(this, chan));
115 114
     }
115
+
116
+    public void onChannelSelfJoin(IRCParser tParser, ChannelInfo cChannel) {
117
+        addChannel(cChannel);
118
+    }
119
+
120
+    public void onErrorInfo(IRCParser tParser, ParserError errorInfo) {
121
+        ErrorLevel errorLevel;
122
+        if (errorInfo.isFatal()) {
123
+            errorLevel = ErrorLevel.FATAL;
124
+        } else if (errorInfo.isError()) {
125
+            errorLevel = ErrorLevel.ERROR;
126
+        } else if (errorInfo.isWarning()) {
127
+            errorLevel = ErrorLevel.WARNING;
128
+        } else {
129
+            Logger.error(ErrorLevel.WARNING, "Unknown error level for parser error: "+errorInfo.getData());
130
+            return;
131
+        }
132
+        
133
+        if (errorInfo.isException()) {
134
+            Logger.error(errorLevel, errorInfo.getException());
135
+        } else {
136
+            Logger.error(errorLevel, errorInfo.getData());
137
+        }
138
+    }
116 139
     
117 140
 }

Loading…
Cancel
Save