Coverage Report - org.mule.transport.xmpp.XmppMuleMessageFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppMuleMessageFactory
0%
0/20
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: XmppMuleMessageFactory.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.xmpp;
 12  
 
 13  
 import org.mule.DefaultMuleMessage;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.transport.AbstractMuleMessageFactory;
 16  
 
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.jivesoftware.smack.packet.Message;
 21  
 import org.jivesoftware.smack.packet.Packet;
 22  
 
 23  
 public class XmppMuleMessageFactory extends AbstractMuleMessageFactory
 24  
 {
 25  
     public XmppMuleMessageFactory(MuleContext context)
 26  
     {
 27  0
         super(context);
 28  0
     }
 29  
 
 30  
     @Override
 31  
     protected Class<?>[] getSupportedTransportMessageTypes()
 32  
     {
 33  0
         return new Class[] { Packet.class };
 34  
     }
 35  
 
 36  
     @Override
 37  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 38  
     {
 39  0
         return transportMessage;
 40  
     }
 41  
 
 42  
     @Override
 43  
     protected void addProperties(DefaultMuleMessage message, Object transportMessage) throws Exception
 44  
     {
 45  0
         super.addProperties(message, transportMessage);
 46  
         
 47  0
         Packet packet = (Packet) transportMessage;
 48  
 
 49  0
         message.setUniqueId(packet.getPacketID());
 50  
         
 51  0
         Map<String, Object> properties = new HashMap<String, Object>();
 52  0
         addXmppPacketProperties(packet, properties);
 53  
 
 54  0
         if (packet instanceof Message)
 55  
         {
 56  0
             Message xmppMessage = (Message) packet;
 57  0
             addXmppMessageProperties(xmppMessage, properties);
 58  
         }
 59  
         
 60  0
         message.addInboundProperties(properties);
 61  0
     }
 62  
 
 63  
     private void addXmppPacketProperties(Packet packet, Map<String, Object> properties)
 64  
     {
 65  0
         for (String key : packet.getPropertyNames())
 66  
         {
 67  0
             properties.put(key, packet.getProperty(key));
 68  
         }        
 69  0
     }
 70  
 
 71  
     private void addXmppMessageProperties(Message message, Map<String, Object> properties)
 72  
     {
 73  0
         properties.put(XmppConnector.XMPP_SUBJECT, message.getSubject());
 74  0
         properties.put(XmppConnector.XMPP_THREAD, message.getThread());
 75  0
     }
 76  
 }
 77  
 
 78