Coverage Report - org.mule.expression.InboundAttachmentsMap
 
Classes in this File Line Coverage Branch Coverage Complexity
InboundAttachmentsMap
0%
0/22
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: InboundAttachmentsMap.java 20321 2010-11-24 15:21:24Z dfeist $
 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  
 package org.mule.expression;
 11  
 
 12  
 import org.mule.api.MuleMessage;
 13  
 
 14  
 import java.util.Collection;
 15  
 import java.util.HashMap;
 16  
 import java.util.Map;
 17  
 import java.util.Set;
 18  
 
 19  
 import javax.activation.DataHandler;
 20  
 
 21  
 /**
 22  
  * Creates a wrapper around Mule Message with a MAp facade used for allowing developers to add attachments to
 23  
  * an outgoing message in a transformer of component without needing to access the Mule API directly
 24  
  */
 25  0
 public class InboundAttachmentsMap implements Map<String, DataHandler>
 26  
 {
 27  
     private MuleMessage message;
 28  
 
 29  
     public InboundAttachmentsMap(MuleMessage message)
 30  0
     {
 31  0
         this.message = message;
 32  0
     }
 33  
 
 34  
     public int size()
 35  
     {
 36  0
         return message.getInboundAttachmentNames().size();
 37  
     }
 38  
 
 39  
     public boolean isEmpty()
 40  
     {
 41  0
         return message.getInboundAttachmentNames().size() == 0;
 42  
     }
 43  
 
 44  
     public boolean containsKey(Object key)
 45  
     {
 46  0
         return message.getInboundAttachmentNames().contains(key.toString());
 47  
     }
 48  
 
 49  
     public boolean containsValue(Object value)
 50  
     {
 51  0
         return values().contains(value);
 52  
     }
 53  
 
 54  
     public DataHandler get(Object key)
 55  
     {
 56  0
         return message.getInboundAttachment(key.toString());
 57  
     }
 58  
 
 59  
     public DataHandler put(String key, DataHandler value)
 60  
     {
 61  0
         throw new UnsupportedOperationException("put(): Inbound attachments are read-only");
 62  
     }
 63  
 
 64  
 
 65  
     public DataHandler remove(Object key)
 66  
     {
 67  0
         throw new UnsupportedOperationException("remove(): Inbound attachments are read-only");
 68  
     }
 69  
 
 70  
 
 71  
     public void putAll(Map<? extends String, ? extends DataHandler> map)
 72  
     {
 73  0
         for (Entry<? extends String, ? extends DataHandler> entry : map.entrySet())
 74  
         {
 75  0
             put(entry.getKey(), entry.getValue());
 76  
         }
 77  0
     }
 78  
 
 79  
     public void clear()
 80  
     {
 81  0
         throw new UnsupportedOperationException("clear");
 82  
     }
 83  
 
 84  
     public Set<String> keySet()
 85  
     {
 86  0
         return message.getInboundAttachmentNames();
 87  
     }
 88  
 
 89  
     public Collection<DataHandler> values()
 90  
     {
 91  0
         return getAttachments().values();
 92  
     }
 93  
 
 94  
     public Set<Entry<String, DataHandler>> entrySet()
 95  
     {
 96  0
         return getAttachments().entrySet();
 97  
     }
 98  
 
 99  
     //TODO Could optimise this to cache if no writes are made
 100  
     private Map<String, DataHandler> getAttachments()
 101  
     {
 102  0
         Map<String, DataHandler> props = new HashMap<String, DataHandler>();
 103  0
         for (String s : message.getInboundAttachmentNames())
 104  
         {
 105  0
             props.put(s, message.getInboundAttachment(s));
 106  
         }
 107  0
         return props;
 108  
     }
 109  
 }