1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.net.msg.client;
21
22 import java.io.IOException;
23 import java.util.Hashtable;
24
25 import org.xnap.XNap;
26 import org.xnap.plugin.opennap.net.msg.ExceptionListener;
27 import org.xnap.plugin.opennap.net.msg.Message;
28 import org.xnap.plugin.opennap.util.OpenNapServerVersion;
29
30 public class ClientMessage extends Message implements Comparable {
31
32
33
34 /***
35 * Priority for urgent messages.
36 */
37 public static int PRIORITY_HIGH = 3;
38
39 /***
40 * Priority for normal messages.
41 */
42 public static int PRIORITY_NORMAL = 2;
43
44 /***
45 * Priority for not so urgent messages.
46 */
47 public static int PRIORITY_LOW = 1;
48
49
50
51 public String data;
52 public Hashtable ht;
53 public ExceptionListener listener;
54
55
56
57 protected ClientMessage(int type, String data)
58 {
59 super(type);
60
61 this.data = data;
62 }
63
64 protected ClientMessage(int type)
65 {
66 this(type, "");
67 }
68
69
70
71 public void add(OpenNapServerVersion sv, String d)
72 {
73 if (ht == null) {
74 ht = new Hashtable();
75 }
76 ht.put(sv, d);
77 }
78
79 public int compareTo(Object o)
80 {
81 return getPriority() - ((ClientMessage)o).getPriority();
82 }
83
84 /***
85 * Notifies the exception listener that the message could not
86 * be sent.
87 */
88 public void failed()
89 {
90 if (listener != null) {
91 listener.exceptionThrown
92 (new IOException(XNap.tr("Server disconnected")));
93 }
94 }
95
96 public ExceptionListener getExceptionListener()
97 {
98 return listener;
99 }
100
101 public void setExceptionListener(ExceptionListener newValue)
102 {
103 listener = newValue;
104 }
105
106 public String getData(OpenNapServerVersion version)
107 {
108 if (ht != null) {
109 OpenNapServerVersion sv = version.getNextVersion();
110 while (sv != null) {
111 Object d = ht.get(sv);
112 if (d != null) {
113 return (String)d;
114 }
115 else {
116 sv = sv.getNextVersion();
117 }
118 }
119 }
120
121 return data;
122 }
123
124 public String getData()
125 {
126 return data;
127 }
128
129 public int getPriority()
130 {
131 return PRIORITY_NORMAL;
132 }
133
134 public int getType()
135 {
136 return type;
137 }
138
139 }