KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > outbound > StaticRecipientList


1 /*
2  * $Id: StaticRecipientList.java 4259 2006-12-14 03:12:07Z aperepel $
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 MuleSource MPL
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 java.util.Collections JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.mule.umo.UMOMessage;
17 import org.mule.util.StringUtils;
18
19 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
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 JavaDoc RECIPIENTS_PROPERTY = "recipients";
30     public static final String JavaDoc RECIPIENT_DELIMITER = ",";
31
32     private volatile CopyOnWriteArrayList recipients = new CopyOnWriteArrayList();
33
34     protected List JavaDoc getRecipients(UMOMessage message)
35     {
36         Object JavaDoc msgRecipients = message.removeProperty(RECIPIENTS_PROPERTY);
37
38         if (msgRecipients == null)
39         {
40             return recipients;
41         }
42         else if (msgRecipients instanceof String JavaDoc)
43         {
44             return new CopyOnWriteArrayList(StringUtils.splitAndTrim(msgRecipients.toString(),
45                 getListDelimiter()));
46         }
47         else if (msgRecipients instanceof List JavaDoc)
48         {
49             return new CopyOnWriteArrayList((List JavaDoc)msgRecipients);
50         }
51         else
52         {
53             logger.warn("Recipients on message are neither String nor List but: " + msgRecipients.getClass());
54             return Collections.EMPTY_LIST;
55         }
56     }
57
58     public List JavaDoc getRecipients()
59     {
60         return recipients;
61     }
62
63     public void setRecipients(List JavaDoc recipients)
64     {
65         if (recipients != null)
66         {
67             this.recipients = new CopyOnWriteArrayList(recipients);
68         }
69         else
70         {
71             this.recipients = null;
72         }
73     }
74
75     /**
76      * Overloading classes can change the delimiter used to separate entries in the
77      * recipient list. By default a ',' is used.
78      *
79      * @return The list delimiter to use
80      */

81     protected String JavaDoc getListDelimiter()
82     {
83         return RECIPIENT_DELIMITER;
84     }
85
86 }
87
Popular Tags