1
2
3
4
5
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
19
20
21
22
23
24
25 public class StaticRecipientList extends AbstractRecipientList
26 {
27 public static final String RECIPIENTS_PROPERTY = "recipients";
28 public static final String RECIPIENT_DELIMITER = ",";
29
30 private volatile List recipients = Collections.EMPTY_LIST;
31
32 protected List getRecipients(MuleEvent event)
33 {
34 Object msgRecipients = event.getMessage().removeProperty(RECIPIENTS_PROPERTY);
35
36 if (msgRecipients == null)
37 {
38 return recipients;
39 }
40 else if (msgRecipients instanceof String)
41 {
42 return Arrays.asList(StringUtils.splitAndTrim(msgRecipients.toString(), this.getListDelimiter()));
43 }
44 else if (msgRecipients instanceof List)
45 {
46 return new ArrayList((List) msgRecipients);
47 }
48 else
49 {
50 logger.warn("Recipients on message are neither String nor List but: " + msgRecipients.getClass());
51 return Collections.EMPTY_LIST;
52 }
53 }
54
55 public List getRecipients()
56 {
57 return recipients;
58 }
59
60 public void setRecipients(List recipients)
61 {
62 if (recipients != null)
63 {
64 this.recipients = new ArrayList(recipients);
65 }
66 else
67 {
68 this.recipients = Collections.EMPTY_LIST;
69 }
70 }
71
72
73
74
75
76
77
78 protected String getListDelimiter()
79 {
80 return RECIPIENT_DELIMITER;
81 }
82
83 }