Coverage Report - org.apache.camel.component.xmpp.XmppMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppMessage
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 java.util.HashMap;
 20  
 import java.util.Iterator;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.camel.impl.DefaultMessage;
 24  
 
 25  
 import org.jivesoftware.smack.packet.Message;
 26  
 
 27  
 /**
 28  
  * Represents a {@link org.apache.camel.Message} for working with XMPP
 29  
  * 
 30  
  * @version $Revision:520964 $
 31  
  */
 32  0
 public class XmppMessage extends DefaultMessage {
 33  
     private Message xmppMessage;
 34  
 
 35  
     public XmppMessage() {
 36  0
         this(new Message());
 37  0
     }
 38  
 
 39  0
     public XmppMessage(Message jmsMessage) {
 40  0
         this.xmppMessage = jmsMessage;
 41  0
     }
 42  
 
 43  
     @Override
 44  
     public String toString() {
 45  0
         if (xmppMessage != null) {
 46  0
             return "XmppMessage: " + xmppMessage;
 47  
         } else {
 48  0
             return "XmppMessage: " + getBody();
 49  
         }
 50  
     }
 51  
 
 52  
     @Override
 53  
     public XmppExchange getExchange() {
 54  0
         return (XmppExchange)super.getExchange();
 55  
     }
 56  
 
 57  
     /**
 58  
      * Returns the underlying XMPP message
 59  
      * 
 60  
      * @return the underlying XMPP message
 61  
      */
 62  
     public Message getXmppMessage() {
 63  0
         return xmppMessage;
 64  
     }
 65  
 
 66  
     public void setXmppMessage(Message xmppMessage) {
 67  0
         this.xmppMessage = xmppMessage;
 68  0
     }
 69  
 
 70  
     public Object getHeader(String name) {
 71  0
         return xmppMessage.getProperty(name);
 72  
     }
 73  
 
 74  
     @Override
 75  
     public void setHeader(String name, Object value) {
 76  0
         if (value == null) {
 77  0
             xmppMessage.deleteProperty(name);
 78  0
         } else {
 79  0
             xmppMessage.setProperty(name, value);
 80  
         }
 81  0
     }
 82  
 
 83  
     @Override
 84  
     public Map<String, Object> getHeaders() {
 85  0
         Map<String, Object> answer = new HashMap<String, Object>();
 86  0
         Iterator iter = xmppMessage.getPropertyNames();
 87  0
         while (iter.hasNext()) {
 88  0
             String name = (String)iter.next();
 89  0
             answer.put(name, xmppMessage.getProperty(name));
 90  0
         }
 91  0
         return answer;
 92  
     }
 93  
 
 94  
     @Override
 95  
     public XmppMessage newInstance() {
 96  0
         return new XmppMessage();
 97  
     }
 98  
 
 99  
     @Override
 100  
     protected Object createBody() {
 101  0
         if (xmppMessage != null) {
 102  0
             return getExchange().getBinding().extractBodyFromXmpp(getExchange(), xmppMessage);
 103  
         }
 104  0
         return null;
 105  
     }
 106  
 }