Coverage Report - org.apache.camel.component.xmpp.XmppGroupChatProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppGroupChatProducer
0% 
0% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.xmpp;
 19  
 
 20  
 import org.apache.camel.Exchange;
 21  
 import org.apache.camel.impl.DefaultProducer;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 import org.jivesoftware.smack.GroupChat;
 25  
 import org.jivesoftware.smack.XMPPException;
 26  
 import org.jivesoftware.smack.packet.Message;
 27  
 
 28  
 /**
 29  
  * @version $Revision: 534145 $
 30  
  */
 31  
 public class XmppGroupChatProducer extends DefaultProducer {
 32  0
     private static final transient Log log = LogFactory.getLog(XmppGroupChatProducer.class);
 33  
     private final XmppEndpoint endpoint;
 34  
     private final String room;
 35  
     private GroupChat chat;
 36  
 
 37  
     public XmppGroupChatProducer(XmppEndpoint endpoint, String room) {
 38  0
         super(endpoint);
 39  0
         this.endpoint = endpoint;
 40  0
         this.room = room;
 41  0
         if (room == null) {
 42  0
             throw new IllegalArgumentException("No room property specified");
 43  
         }
 44  0
     }
 45  
 
 46  
     public void process(Exchange exchange) {
 47  
         // TODO it would be nice if we could reuse the message from the exchange
 48  0
         Message message = chat.createMessage();
 49  0
         message.setTo(room);
 50  0
         message.setFrom(endpoint.getUser());
 51  
 
 52  0
         endpoint.getBinding().populateXmppMessage(message, exchange);
 53  0
         if (log.isDebugEnabled()) {
 54  0
             log.debug(">>>> message: " + message.getBody());
 55  
         }
 56  
         try {
 57  0
             chat.sendMessage(message);
 58  
         }
 59  0
         catch (XMPPException e) {
 60  0
             throw new RuntimeXmppException(e);
 61  0
         }
 62  0
     }
 63  
 
 64  
     @Override
 65  
     protected void doStart() throws Exception {
 66  0
         super.doStart();
 67  0
         if (chat == null) {
 68  0
             chat = endpoint.getConnection().createGroupChat(room);
 69  
         }
 70  0
     }
 71  
 
 72  
     @Override
 73  
     protected void doStop() throws Exception {
 74  0
         if (chat != null) {
 75  0
             chat.leave();
 76  0
             chat = null;
 77  
         }
 78  0
         super.doStop();
 79  0
     }
 80  
 
 81  
     // Properties
 82  
     //-------------------------------------------------------------------------
 83  
     public GroupChat getChat() {
 84  0
         return chat;
 85  
     }
 86  
 
 87  
     public void setChat(GroupChat chat) {
 88  0
         this.chat = chat;
 89  0
     }
 90  
 
 91  
     public String getRoom() {
 92  0
         return room;
 93  
     }
 94  
 }