View Javadoc

1   /*
2    * $Id$
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;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleMessage;
15  import org.mule.config.i18n.CoreMessages;
16  
17  import java.util.Collection;
18  import java.util.LinkedList;
19  import java.util.List;
20  
21  /**
22   * Splits a message that has a list payload invoking the next message processor one
23   * for each item in the list in order.
24   * <p>
25   * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/Sequencer.html">http://www.eaipatterns.com/Sequencer.html</a>
26   */
27  public class CollectionSplitter extends AbstractSplitter
28  {
29  
30      protected List<MuleMessage> splitMessage(MuleEvent event)
31      {
32          MuleMessage message = event.getMessage();
33          if (message.getPayload() instanceof Collection)
34          {
35              return new LinkedList((Collection) message.getPayload());
36          }
37          else
38          {
39              throw new IllegalArgumentException(CoreMessages.objectNotOfCorrectType(
40                  message.getPayload().getClass(), List.class).getMessage());
41          }
42      }
43  
44  }