1 /***
2 * Created on Jun 29, 2005, Copyright UC Regents
3 */
4 package org.telscenter.pas.messaging;
5
6 import java.util.HashSet;
7 import java.util.Iterator;
8 import java.util.Set;
9
10 import javax.jms.JMSException;
11 import javax.jms.Message;
12 import javax.jms.MessageListener;
13 import javax.jms.TextMessage;
14
15 /***
16 * @author turadg
17 */
18 public class PasCommandRepeater {
19
20 class MessageConverter implements MessageListener {
21
22 public void onMessage(Message message) {
23
24 String text;
25 try {
26 text = ((TextMessage) message).getText();
27 } catch (JMSException e) {
28
29 e.printStackTrace();
30 return;
31 }
32
33 if (text.startsWith(COMMANDS_FREEZE)) {
34 for (Iterator iter = commandListeners.iterator(); iter
35 .hasNext();) {
36 IPasCommandListener listener = (IPasCommandListener) iter
37 .next();
38 listener.freeze();
39 }
40 } else if (text.startsWith(COMMANDS_NOTIFY)) {
41 for (Iterator iter = commandListeners.iterator(); iter
42 .hasNext();) {
43 IPasCommandListener listener = (IPasCommandListener) iter
44 .next();
45 String restOfMessage = text.substring(COMMANDS_NOTIFY.length());
46 listener.displayMessage(restOfMessage);
47 }
48 } else if (text.startsWith(COMMANDS_RESUME)) {
49 for (Iterator iter = commandListeners.iterator(); iter
50 .hasNext();) {
51 IPasCommandListener listener = (IPasCommandListener) iter
52 .next();
53 listener.resume();
54 }
55 } else if (text.startsWith(COMMANDS_PROMPTEXPORTWORK)) {
56 for (Iterator iter = commandListeners.iterator(); iter
57 .hasNext();) {
58 IPasCommandListener listener = (IPasCommandListener) iter
59 .next();
60 listener.promptExportWork();
61 }
62 } else if (text.startsWith(COMMANDS_REPUBLISHSESSION)) {
63 for (Iterator iter = commandListeners.iterator(); iter
64 .hasNext();) {
65 IPasCommandListener listener = (IPasCommandListener) iter
66 .next();
67 listener.notifySession();
68 }
69 }
70 }
71 }
72
73 public static final String TOPIC_COMMANDS = "COMMAND";
74
75 public static final String COMMANDS_FREEZE = "/freeze";
76
77 public static final String COMMANDS_NOTIFY = "/notify ";
78
79 public static final String COMMANDS_PROMPTEXPORTWORK = "/pdf";
80
81 public static final String COMMANDS_REPUBLISHSESSION = "/republishSession";
82
83 public static final String COMMANDS_RESUME = "/resume";
84
85 private Set commandListeners = new HashSet();
86
87 public void addPasCommandListener(IPasCommandListener listener) {
88 commandListeners.add(listener);
89 }
90
91 public MessageListener getMessageConverter() {
92 return new MessageConverter();
93 }
94
95 }