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