Coverage Report - org.mule.routing.CorrelationPropertiesExpressionEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
CorrelationPropertiesExpressionEvaluator
0%
0/19
0%
0/12
4
 
 1  
 /*
 2  
  * $Id: CorrelationPropertiesExpressionEvaluator.java 11231 2008-03-06 21:17:37Z rossmason $
 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.routing;
 12  
 
 13  
 import org.mule.api.config.MuleProperties;
 14  
 import org.mule.api.transport.MessageAdapter;
 15  
 import org.mule.util.expression.MessageHeaderExpressionEvaluator;
 16  
 
 17  
 /**
 18  
  * <code>CorrelationPropertiesExpressionEvaluator</code> is a default implementation used for
 19  
  * getting the Correlation information from a message. This object is only used when
 20  
  * getting a specific property to be set on the message. When reading the property
 21  
  * the getProperty(...) or the direct property accessor will be used i.e.
 22  
  * message.getCorrelationId() or
 23  
  * message.getProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY)
 24  
  */
 25  0
 public class CorrelationPropertiesExpressionEvaluator extends MessageHeaderExpressionEvaluator
 26  
 {
 27  
     public final Object evaluate(String name, Object message)
 28  
     {
 29  
         Object result;
 30  0
         MessageAdapter msg = null;
 31  0
         if (message instanceof MessageAdapter)
 32  
         {
 33  0
             msg = (MessageAdapter) message;
 34  
         }
 35  0
         if (msg != null)
 36  
         {
 37  0
             if (MuleProperties.MULE_CORRELATION_ID_PROPERTY.equals(name))
 38  
             {
 39  0
                 result = getCorrelationId(msg);
 40  
             }
 41  0
             else if (MuleProperties.MULE_MESSAGE_ID_PROPERTY.equals(name))
 42  
             {
 43  0
                 result = getMessageId(msg);
 44  
             }
 45  
             else
 46  
             {
 47  0
                 throw new IllegalArgumentException("Property name: " + name
 48  
                                                    + " not recognised by the Correlation Property Extractor");
 49  
             }
 50  0
             if (result == null)
 51  
             {
 52  0
                 throw new IllegalArgumentException(
 53  
                     "Property Extractor cannot return a null value. Extractor is: " + getClass().getName());
 54  
             }
 55  
         }
 56  
         else
 57  
         {
 58  0
             return super.evaluate(name, message);
 59  
         }
 60  0
         return result;
 61  
     }
 62  
 
 63  
     public String getMessageId(MessageAdapter message)
 64  
     {
 65  0
         return message.getUniqueId();
 66  
     }
 67  
 
 68  
     public String getCorrelationId(MessageAdapter message)
 69  
     {
 70  0
         String id = message.getCorrelationId();
 71  0
         if (id == null)
 72  
         {
 73  0
             id = message.getUniqueId();
 74  
         }
 75  0
         return id;
 76  
     }
 77  
 }