1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.core;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 /***
25 *
26 * @author Christoph Walcher
27 */
28 public class InstantMessenger {
29 private Map protocols;
30
31 /*** Creates a new instance of InstantMessenger */
32 public InstantMessenger() {
33 protocols = new HashMap();
34 }
35
36 /***Create a unconnected IMConnection using the given protocol
37 * @param protocolName
38 * @return
39 * @throws NoSuchProtocolException
40 */
41 public IMConnection createConnection(String protocolName)
42 throws NoSuchProtocolException {
43 return lookupProtocol(protocolName).createConnection();
44 }
45
46 /***
47 * @param protocolName
48 * @return
49 * @throws NoSuchProtocolException
50 */
51 public Protocol lookupProtocol(String protocolName)
52 throws NoSuchProtocolException {
53 if (protocols.containsKey(protocolName)) {
54 return (Protocol)protocols.get(protocolName);
55 }
56 else {
57 throw new NoSuchProtocolException();
58 }
59 }
60
61 /***
62 * @param protocolName
63 * @param protocol
64 */
65 public void registerProtocol(String protocolName, Protocol protocol) {
66 if (protocolName == null) {
67 throw new IllegalArgumentException("Parameter protocolName " +
68 "must not be null");
69 }
70
71 if (protocol == null) {
72 throw new IllegalArgumentException("Parameter protocol must not be null. " +
73 "Use unregister to remove a registered protocol.");
74 }
75
76 protocols.put(protocolName, protocol);
77 }
78
79 /***
80 * @param protocolName
81 * @return
82 * @throws NoSuchProtocolException
83 */
84 public Protocol unregisterProtocol(String protocolName)
85 throws NoSuchProtocolException {
86
87 if (!protocols.containsKey(protocolName)) {
88 throw new NoSuchProtocolException();
89 }
90
91 return (Protocol)protocols.remove(protocolName);
92 }
93 }