View Javadoc

1   /*
2    * $Id: StaticRecipientList.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.outbound;
12  
13  import org.mule.umo.UMOMessage;
14  import org.mule.util.StringUtils;
15  
16  import java.util.ArrayList;
17  import java.util.Arrays;
18  import java.util.Collections;
19  import java.util.List;
20  
21  /**
22   * <code>StaticRecipientList</code> is used to dispatch a single event to multiple
23   * recipients over the same transport. The recipient endpoints for this router can be
24   * configured statically on the router itself.
25   */
26  
27  public class StaticRecipientList extends AbstractRecipientList
28  {
29      public static final String RECIPIENTS_PROPERTY = "recipients";
30      public static final String RECIPIENT_DELIMITER = ",";
31  
32      private volatile List recipients = Collections.EMPTY_LIST;
33  
34      protected List getRecipients(UMOMessage message)
35      {
36          Object msgRecipients = message.removeProperty(RECIPIENTS_PROPERTY);
37  
38          if (msgRecipients == null)
39          {
40              return recipients;
41          }
42          else if (msgRecipients instanceof String)
43          {
44              return Arrays.asList(StringUtils.splitAndTrim(msgRecipients.toString(), this.getListDelimiter()));
45          }
46          else if (msgRecipients instanceof List)
47          {
48              return new ArrayList((List) msgRecipients);
49          }
50          else
51          {
52              logger.warn("Recipients on message are neither String nor List but: " + msgRecipients.getClass());
53              return Collections.EMPTY_LIST;
54          }
55      }
56  
57      public List getRecipients()
58      {
59          return recipients;
60      }
61  
62      public void setRecipients(List recipients)
63      {
64          if (recipients != null)
65          {
66              this.recipients = new ArrayList(recipients);
67          }
68          else
69          {
70              this.recipients = Collections.EMPTY_LIST;
71          }
72      }
73  
74      /**
75       * Overloading classes can change the delimiter used to separate entries in the
76       * recipient list. By default a ',' is used.
77       * 
78       * @return The list delimiter to use
79       */
80      protected String getListDelimiter()
81      {
82          return RECIPIENT_DELIMITER;
83      }
84  
85  
86  
87  }