Coverage Report - org.mule.providers.jbi.JbiMessageAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
JbiMessageAdapter
0%
0/26
0%
0/3
1.5
 
 1  
 /*
 2  
  * $Id: JbiMessageAdapter.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.jbi;
 12  
 
 13  
 import org.mule.impl.ThreadSafeAccess;
 14  
 import org.mule.providers.AbstractMessageAdapter;
 15  
 import org.mule.umo.MessagingException;
 16  
 import org.mule.umo.provider.MessageTypeNotSupportedException;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.Set;
 20  
 
 21  
 import javax.activation.DataHandler;
 22  
 import javax.jbi.messaging.NormalizedMessage;
 23  
 
 24  
 /**
 25  
  * <code>JbiMessageAdapter</code> translates a JBI NormalizedMessage to a
 26  
  * UMOMessage
 27  
  * 
 28  
  * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
 29  
  * @version $Revision: 7976 $
 30  
  */
 31  
 
 32  
 public class JbiMessageAdapter extends AbstractMessageAdapter
 33  
 {
 34  
     /**
 35  
      * Serial version
 36  
      */
 37  
     private static final long serialVersionUID = 642776588124612798L;
 38  
 
 39  
     private final NormalizedMessage message;
 40  
 
 41  
     public JbiMessageAdapter(Object message) throws MessagingException
 42  0
     {
 43  0
         if (message instanceof NormalizedMessage)
 44  
         {
 45  0
             this.message = (NormalizedMessage)message;
 46  0
             for (Iterator iterator = this.message.getPropertyNames().iterator(); iterator.hasNext();)
 47  
             {
 48  0
                 String key = (String)iterator.next();
 49  0
                 Object value = this.message.getProperty(key);
 50  0
                 if (value != null)
 51  
                 {
 52  0
                     setProperty(key, value);
 53  
                 }
 54  
             }
 55  
         }
 56  
         else
 57  
         {
 58  0
             throw new MessageTypeNotSupportedException(message, getClass());
 59  
         }
 60  0
     }
 61  
 
 62  
     protected JbiMessageAdapter(JbiMessageAdapter template)
 63  
     {
 64  0
         super(template);
 65  0
         message = template.message;
 66  0
     }
 67  
 
 68  
     public void setProperty(Object key, Object value)
 69  
     {
 70  0
         message.setProperty(key.toString(), value);
 71  0
     }
 72  
 
 73  
     /**
 74  
      * Converts the message implementation into a String representation
 75  
      * 
 76  
      * @param encoding The encoding to use when transforming the message (if
 77  
      *            necessary). The parameter is used when converting from a byte array
 78  
      * @return String representation of the message payload
 79  
      * @throws Exception Implementation may throw an endpoint specific exception
 80  
      */
 81  
     public String getPayloadAsString(String encoding) throws Exception
 82  
     {
 83  0
         throw new UnsupportedOperationException("getPayloadAsString");
 84  
     }
 85  
 
 86  
     /**
 87  
      * Converts the message implementation into a String representation
 88  
      * 
 89  
      * @return String representation of the message
 90  
      * @throws Exception Implemetation may throw an endpoint specific exception
 91  
      */
 92  
     public byte[] getPayloadAsBytes() throws Exception
 93  
     {
 94  0
         throw new UnsupportedOperationException("getPayloadAsBytes");
 95  
     }
 96  
 
 97  
     public Object getPayload()
 98  
     {
 99  0
         return message;
 100  
     }
 101  
 
 102  
     public Object getProperty(Object key)
 103  
     {
 104  0
         return message.getProperty(key.toString());
 105  
     }
 106  
 
 107  
     public void addAttachment(String name, DataHandler dataHandler) throws Exception
 108  
     {
 109  0
         message.addAttachment(name, dataHandler);
 110  0
     }
 111  
 
 112  
     public void removeAttachment(String name) throws Exception
 113  
     {
 114  0
         message.removeAttachment(name);
 115  0
     }
 116  
 
 117  
     public DataHandler getAttachment(String name)
 118  
     {
 119  0
         return message.getAttachment(name);
 120  
     }
 121  
 
 122  
     public Set getAttachmentNames()
 123  
     {
 124  0
         return message.getAttachmentNames();
 125  
     }
 126  
 
 127  
     public ThreadSafeAccess newThreadCopy()
 128  
     {
 129  0
         return new JbiMessageAdapter(this);
 130  
     }
 131  
 
 132  
 }