1 17 package org.apache.servicemix.components.jabber; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.messaging.MessageExchange; 21 import javax.jbi.messaging.NormalizedMessage; 22 23 import org.jivesoftware.smack.GroupChat; 24 import org.jivesoftware.smack.packet.Message; 25 26 32 public class JabberGroupChatSender extends JabberComponentSupport { 33 34 private GroupChat chat; 35 private String room; 36 37 public void afterPropertiesSet() throws Exception { 38 super.afterPropertiesSet(); 39 if (chat == null) { 40 if (room == null) { 41 throw new IllegalArgumentException ("You must specify the room property"); 42 } 43 } 44 } 45 46 public void start() throws JBIException { 47 super.start(); 48 if (chat == null) { 49 chat = getConnection().createGroupChat(room); 50 } 51 } 52 53 public void stop() throws JBIException { 54 if (chat != null) { 55 chat.leave(); 56 chat = null; 57 } 58 super.stop(); 59 } 60 61 public GroupChat getChat() { 64 return chat; 65 } 66 67 public void setChat(GroupChat chat) { 68 this.chat = chat; 69 } 70 71 public String getRoom() { 72 return room; 73 } 74 75 public void setRoom(String room) { 76 this.room = room; 77 } 78 79 80 protected void process(MessageExchange messageExchange, NormalizedMessage normalizedMessage) throws Exception { 83 Message message = chat.createMessage(); 84 getMarshaler().fromNMS(message, normalizedMessage); 85 chat.sendMessage(message); 86 done(messageExchange); 87 } 88 89 } 90 | Popular Tags |