Coverage Report - org.mule.expression.OutboundHeadersExpressionEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
OutboundHeadersExpressionEvaluator
0%
0/8
0%
0/2
0
OutboundHeadersExpressionEvaluator$SendHeadersMap
0%
0/24
0%
0/6
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.expression;
 8  
 
 9  
 import org.mule.api.MuleMessage;
 10  
 import org.mule.api.expression.ExpressionEvaluator;
 11  
 import org.mule.api.transport.PropertyScope;
 12  
 
 13  
 import java.util.Collection;
 14  
 import java.util.HashMap;
 15  
 import java.util.Map;
 16  
 import java.util.Set;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 /**
 22  
  * Creates a Map facade around a {@link org.mule.api.MuleMessage} instance to allow access to outbound
 23  
  * headers from within components and transformers without the these objects needing access to the Mule Message
 24  
  */
 25  0
 public class OutboundHeadersExpressionEvaluator implements ExpressionEvaluator
 26  
 {
 27  
     public static final String NAME = "outboundHeaders";
 28  
 
 29  
     /**
 30  
      * logger used by this class
 31  
      */
 32  0
     protected transient final Log logger = LogFactory.getLog(OutboundHeadersExpressionEvaluator.class);
 33  
 
 34  
 
 35  
     public Object evaluate(String expression, MuleMessage message)
 36  
     {
 37  0
         if (message == null)
 38  
         {
 39  0
             return null;
 40  
         }
 41  0
         return new SendHeadersMap(message);
 42  
     }
 43  
 
 44  
     /**
 45  
      * {@inheritDoc}
 46  
      */
 47  
     public String getName()
 48  
     {
 49  0
         return NAME;
 50  
     }
 51  
 
 52  
     /**
 53  
      * {@inheritDoc}
 54  
      */
 55  
     public void setName(String name)
 56  
     {
 57  0
         throw new UnsupportedOperationException("name");
 58  
     }
 59  
 
 60  
 
 61  0
     public static class SendHeadersMap implements Map<String, Object>
 62  
     {
 63  
         private MuleMessage message;
 64  
 
 65  
         public SendHeadersMap(MuleMessage message)
 66  0
         {
 67  0
             this.message = message;
 68  0
         }
 69  
 
 70  
         public int size()
 71  
         {
 72  0
             return message.getOutboundPropertyNames().size();
 73  
         }
 74  
 
 75  
         public boolean isEmpty()
 76  
         {
 77  0
             return message.getOutboundPropertyNames().size() == 0;
 78  
         }
 79  
 
 80  
         public boolean containsKey(Object key)
 81  
         {
 82  0
             return message.getOutboundPropertyNames().contains(key.toString());
 83  
         }
 84  
 
 85  
         public boolean containsValue(Object value)
 86  
         {
 87  0
             return values().contains(value);
 88  
         }
 89  
 
 90  
         public Object get(Object key)
 91  
         {
 92  0
             return message.getOutboundProperty(key.toString());
 93  
         }
 94  
 
 95  
         public Object put(String key, Object value)
 96  
         {
 97  0
             message.setOutboundProperty(key, value);
 98  0
             return value;
 99  
         }
 100  
 
 101  
 
 102  
         public Object remove(Object key)
 103  
         {
 104  0
             return message.removeProperty(key.toString(), PropertyScope.OUTBOUND);
 105  
         }
 106  
 
 107  
 
 108  
         public void putAll(Map<? extends String, ?> t)
 109  
         {
 110  0
             for (Entry<? extends String, ?> entry : t.entrySet())
 111  
             {
 112  0
                 put(entry.getKey(), entry.getValue());
 113  
             }
 114  0
         }
 115  
 
 116  
         public void clear()
 117  
         {
 118  0
             message.clearProperties(PropertyScope.OUTBOUND);
 119  0
         }
 120  
 
 121  
         public Set<String> keySet()
 122  
         {
 123  0
             return message.getOutboundPropertyNames();
 124  
         }
 125  
 
 126  
         public Collection<Object> values()
 127  
         {
 128  0
             return getPropertiesInScope(PropertyScope.OUTBOUND).values();
 129  
         }
 130  
 
 131  
         public Set<Entry<String, Object>> entrySet()
 132  
         {
 133  0
             return getPropertiesInScope(PropertyScope.OUTBOUND).entrySet();
 134  
         }
 135  
 
 136  
         //TODO Could optimise this to cache if no writes are made
 137  
         private Map<String, Object> getPropertiesInScope(PropertyScope scope)
 138  
         {
 139  0
             Map<String, Object> props = new HashMap<String, Object>();
 140  0
             for (String s : message.getPropertyNames(scope))
 141  
             {
 142  0
                 props.put(s, message.getProperty(s, scope));
 143  
             }
 144  0
             return props;
 145  
         }
 146  
     }
 147  
 }