1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xnap.plugin.opennap.net.msg.server;
22
23 import org.xnap.plugin.opennap.net.OpenNapServer;
24 import org.xnap.plugin.opennap.net.msg.Message;
25 import org.xnap.util.QuotedStringTokenizer;
26
27 public class ServerMessage extends Message {
28
29
30
31 protected OpenNapServer server;
32 protected String data;
33 protected boolean consumed = false;
34
35
36
37 protected ServerMessage(int type, String data, int argc)
38 throws InvalidMessageException
39 {
40 super(type);
41
42 this.data = data;
43
44 QuotedStringTokenizer t = new QuotedStringTokenizer(data);
45
46 if (t.countTokens() < argc) {
47 throw new InvalidMessageException("Wrong number of arguments.");
48 }
49
50 try {
51 parse(t);
52 }
53 catch (Exception e) {
54 throw new InvalidMessageException("Wrong type of argument.");
55 }
56 }
57
58
59
60 /***
61 * Tell message to handle itself.
62 */
63 public void received()
64 {
65 }
66
67 /***
68 * OvernetMessage can be consumed: if the right listener gets the message, he
69 * consumes it and the other listeners won't get it.
70 */
71 public void consume()
72 {
73 consumed = true;
74 }
75
76 /***
77 * See if message is already consumed.
78 */
79 public boolean isConsumed()
80 {
81 return consumed;
82 }
83
84 public OpenNapServer getServer()
85 {
86 return server;
87 }
88
89 public void setServer(OpenNapServer newValue)
90 {
91 server = newValue;
92 }
93
94 public String toString()
95 {
96 return data;
97 }
98
99 protected void parse(QuotedStringTokenizer t) throws Exception
100 {
101 }
102
103 }