01: package dalma.endpoints.irc;
02:
03: import f00f.net.irc.martyr.Command;
04: import f00f.net.irc.martyr.commands.MessageCommand;
05: import f00f.net.irc.martyr.commands.InviteCommand;
06:
07: import java.util.Observable;
08: import java.util.Observer;
09:
10: /**
11: * Listens to the incoming {@link Command} objects.
12: *
13: * @author Kohsuke Kawaguchi
14: */
15: final class MessageListener implements Observer {
16: private final IRCEndPoint endPoint;
17:
18: public MessageListener(IRCEndPoint endPoint) {
19: this .endPoint = endPoint;
20: }
21:
22: public void update(Observable _, Object cmd) {
23: handleCommand((Command) cmd);
24: }
25:
26: private void handleCommand(Command cmd) {
27: if (cmd instanceof MessageCommand) {
28: MessageCommand msgcmd = (MessageCommand) cmd;
29: endPoint.onMessageReceived(msgcmd);
30: }
31: if (cmd instanceof InviteCommand) {
32: InviteCommand invcmd = (InviteCommand) cmd;
33: endPoint.onInvite(invcmd);
34: }
35: }
36: }
|