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