Coverage Report - org.apache.camel.component.xmpp.XmppGroupChatProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppGroupChatProducer
0% 
0% 
0
 
 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.camel.component.xmpp;
 18  
 
 19  
 import org.apache.camel.Exchange;
 20  
 import org.apache.camel.impl.DefaultProducer;
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.jivesoftware.smack.GroupChat;
 24  
 import org.jivesoftware.smack.XMPPException;
 25  
 import org.jivesoftware.smack.packet.Message;
 26  
 
 27  
 /**
 28  
  * @version $Revision: 563665 $
 29  
  */
 30  
 public class XmppGroupChatProducer extends DefaultProducer {
 31  0
     private static final transient Log LOG = LogFactory.getLog(XmppGroupChatProducer.class);
 32  
     private final XmppEndpoint endpoint;
 33  
     private final String room;
 34  
     private GroupChat chat;
 35  
 
 36  
     public XmppGroupChatProducer(XmppEndpoint endpoint, String room) {
 37  0
         super(endpoint);
 38  0
         this.endpoint = endpoint;
 39  0
         this.room = room;
 40  0
         if (room == null) {
 41  0
             throw new IllegalArgumentException("No room property specified");
 42  
         }
 43  0
     }
 44  
 
 45  
     public void process(Exchange exchange) {
 46  
         // TODO it would be nice if we could reuse the message from the exchange
 47  0
         Message message = chat.createMessage();
 48  0
         message.setTo(room);
 49  0
         message.setFrom(endpoint.getUser());
 50  
 
 51  0
         endpoint.getBinding().populateXmppMessage(message, exchange);
 52  0
         if (LOG.isDebugEnabled()) {
 53  0
             LOG.debug(">>>> message: " + message.getBody());
 54  
         }
 55  
         try {
 56  0
             chat.sendMessage(message);
 57  0
         } catch (XMPPException e) {
 58  0
             throw new RuntimeXmppException(e);
 59  0
         }
 60  0
     }
 61  
 
 62  
     @Override
 63  
     protected void doStart() throws Exception {
 64  0
         super.doStart();
 65  0
         if (chat == null) {
 66  0
             chat = endpoint.getConnection().createGroupChat(room);
 67  
         }
 68  0
     }
 69  
 
 70  
     @Override
 71  
     protected void doStop() throws Exception {
 72  0
         if (chat != null) {
 73  0
             chat.leave();
 74  0
             chat = null;
 75  
         }
 76  0
         super.doStop();
 77  0
     }
 78  
 
 79  
     // Properties
 80  
     // -------------------------------------------------------------------------
 81  
     public GroupChat getChat() {
 82  0
         return chat;
 83  
     }
 84  
 
 85  
     public void setChat(GroupChat chat) {
 86  0
         this.chat = chat;
 87  0
     }
 88  
 
 89  
     public String getRoom() {
 90  0
         return room;
 91  
     }
 92  
 }