KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > jabber > JabberGroupChatSender


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
27  * Sends one way messages to a Jabber {@link GroupChat} and receives inbound messages
28  * from the chat
29  *
30  * @version $Revision: 426415 $
31  */

32 public class JabberGroupChatSender extends JabberComponentSupport {
33
34     private GroupChat chat;
35     private String JavaDoc room;
36
37     public void afterPropertiesSet() throws Exception JavaDoc {
38         super.afterPropertiesSet();
39         if (chat == null) {
40             if (room == null) {
41                 throw new IllegalArgumentException JavaDoc("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     // Properties
62
//-------------------------------------------------------------------------
63
public GroupChat getChat() {
64         return chat;
65     }
66
67     public void setChat(GroupChat chat) {
68         this.chat = chat;
69     }
70
71     public String JavaDoc getRoom() {
72         return room;
73     }
74
75     public void setRoom(String JavaDoc room) {
76         this.room = room;
77     }
78
79
80     // Implementation methods
81
//-------------------------------------------------------------------------
82
protected void process(MessageExchange messageExchange, NormalizedMessage normalizedMessage) throws Exception JavaDoc {
83         Message message = chat.createMessage();
84         getMarshaler().fromNMS(message, normalizedMessage);
85         chat.sendMessage(message);
86         done(messageExchange);
87     }
88
89 }
90
Popular Tags