Coverage Report - org.mule.routing.outbound.ExpressionRecipientList
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionRecipientList
0%
0/30
0%
0/12
0
 
 1  
 /*
 2  
  * $Id: StaticRecipientList.java 10489 2008-01-23 17:53:38Z 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  
 
 11  
 package org.mule.routing.outbound;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.expression.ExpressionManager;
 15  
 import org.mule.api.routing.CouldNotRouteOutboundMessageException;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.util.StringUtils;
 18  
 
 19  
 import java.text.MessageFormat;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Arrays;
 22  
 import java.util.List;
 23  
 
 24  0
 public class ExpressionRecipientList extends AbstractRecipientList
 25  
 {
 26  
     public static final String DEFAULT_SELECTOR_PROPERTY = "recipients";
 27  
     public static final String DEFAULT_SELECTOR_EVALUATOR = "header";
 28  
     public static final String DEFAULT_SELECTOR_EXPRESSION = DEFAULT_SELECTOR_PROPERTY;
 29  
 
 30  0
     private String expression = DEFAULT_SELECTOR_EXPRESSION;
 31  0
     private String evaluator = DEFAULT_SELECTOR_EVALUATOR;
 32  
     private String customEvaluator;
 33  
     private String fullExpression;
 34  
 
 35  
     @Override
 36  
     protected List getRecipients(MuleEvent event) throws CouldNotRouteOutboundMessageException
 37  
     {
 38  0
         String expr = getFullExpression();
 39  0
         if (!muleContext.getExpressionManager().isValidExpression(expr))
 40  
         {
 41  0
             throw new CouldNotRouteOutboundMessageException(
 42  
                     CoreMessages.expressionInvalidForProperty("expression", expr), event, null);
 43  
         }
 44  
 
 45  0
         Object msgRecipients = muleContext.getExpressionManager().evaluate(expr, event.getMessage());
 46  0
         if (msgRecipients == null)
 47  
         {
 48  0
             throw new CouldNotRouteOutboundMessageException(
 49  
                     CoreMessages.propertyIsNotSetOnEvent(getFullExpression()), event, null);
 50  
         }
 51  0
         else if (msgRecipients instanceof String)
 52  
         {
 53  0
             return Arrays.asList(StringUtils.splitAndTrim(msgRecipients.toString(), " ,;:"));
 54  
         }
 55  0
         else if (msgRecipients instanceof List)
 56  
         {
 57  0
             return new ArrayList((List) msgRecipients);
 58  
         }
 59  
         else
 60  
         {
 61  0
             logger.error("Recipients on message are neither String nor List but: " + msgRecipients.getClass());
 62  0
             throw new CouldNotRouteOutboundMessageException(
 63  
                     CoreMessages.propertyIsNotSupportedType(getFullExpression(), new Class[]{String.class, List.class}, msgRecipients.getClass()), event, null);
 64  
         }
 65  
     }
 66  
 
 67  
     public String getFullExpression()
 68  
     {
 69  0
         if (fullExpression == null)
 70  
         {
 71  0
             if (evaluator.equalsIgnoreCase("custom"))
 72  
             {
 73  0
                 evaluator = customEvaluator;
 74  
             }
 75  0
             fullExpression = MessageFormat.format("{0}{1}:{2}{3}",
 76  
                                                   ExpressionManager.DEFAULT_EXPRESSION_PREFIX,
 77  
                                                   evaluator, expression,
 78  
                                                   ExpressionManager.DEFAULT_EXPRESSION_POSTFIX);
 79  0
             logger.debug("Full expression for EndpointSelector is: " + fullExpression);
 80  
         }
 81  0
         return fullExpression;
 82  
     }
 83  
 
 84  
     public String getExpression()
 85  
     {
 86  0
         return expression;
 87  
     }
 88  
 
 89  
     public void setExpression(String expression)
 90  
     {
 91  0
         this.expression = expression;
 92  0
     }
 93  
 
 94  
     public String getCustomEvaluator()
 95  
     {
 96  0
         return customEvaluator;
 97  
     }
 98  
 
 99  
     public void setCustomEvaluator(String customEvaluator)
 100  
     {
 101  0
         this.customEvaluator = customEvaluator;
 102  0
     }
 103  
 
 104  
     public String getEvaluator()
 105  
     {
 106  0
         return evaluator;
 107  
     }
 108  
 
 109  
     public void setEvaluator(String evaluator)
 110  
     {
 111  0
         this.evaluator = evaluator;
 112  0
     }
 113  
 }