Coverage Report - org.mule.routing.outbound.StaticRecipientList
 
Classes in this File Line Coverage Branch Coverage Complexity
StaticRecipientList
0%
0/17
0%
0/8
2.75
 
 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.routing.outbound;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.util.StringUtils;
 11  
 
 12  
 import java.util.ArrayList;
 13  
 import java.util.Arrays;
 14  
 import java.util.Collections;
 15  
 import java.util.List;
 16  
 
 17  
 /**
 18  
  * <code>StaticRecipientList</code> is used to dispatch a single event to multiple
 19  
  * recipients over the same transport. The recipient targets for this router can be
 20  
  * configured statically on the router itself.
 21  
  */
 22  
 
 23  
 // TODO I think the ExpressionRecipientList router does everything this router does and more.
 24  
 // Perhaps we should rename it to simply "RecipientList Router" and remove this one?
 25  0
 public class StaticRecipientList extends AbstractRecipientList
 26  
 {
 27  
     public static final String RECIPIENTS_PROPERTY = "recipients";
 28  
     public static final String RECIPIENT_DELIMITER = ",";
 29  
 
 30  0
     private volatile List recipients = Collections.EMPTY_LIST;
 31  
 
 32  
     protected List getRecipients(MuleEvent event)
 33  
     {
 34  0
         Object msgRecipients = event.getMessage().removeProperty(RECIPIENTS_PROPERTY);
 35  
 
 36  0
         if (msgRecipients == null)
 37  
         {
 38  0
             return recipients;
 39  
         }
 40  0
         else if (msgRecipients instanceof String)
 41  
         {
 42  0
             return Arrays.asList(StringUtils.splitAndTrim(msgRecipients.toString(), this.getListDelimiter()));
 43  
         }
 44  0
         else if (msgRecipients instanceof List)
 45  
         {
 46  0
             return new ArrayList((List) msgRecipients);
 47  
         }
 48  
         else
 49  
         {
 50  0
             logger.warn("Recipients on message are neither String nor List but: " + msgRecipients.getClass());
 51  0
             return Collections.EMPTY_LIST;
 52  
         }
 53  
     }
 54  
 
 55  
     public List getRecipients()
 56  
     {
 57  0
         return recipients;
 58  
     }
 59  
 
 60  
     public void setRecipients(List recipients)
 61  
     {
 62  0
         if (recipients != null)
 63  
         {
 64  0
             this.recipients = new ArrayList(recipients);
 65  
         }
 66  
         else
 67  
         {
 68  0
             this.recipients = Collections.EMPTY_LIST;
 69  
         }
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Overloading classes can change the delimiter used to separate entries in the
 74  
      * recipient list. By default a ',' is used.
 75  
      * 
 76  
      * @return The list delimiter to use
 77  
      */
 78  
     protected String getListDelimiter()
 79  
     {
 80  0
         return RECIPIENT_DELIMITER;
 81  
     }
 82  
 
 83  
 }