View Javadoc
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.endpoint.OutboundEndpoint;
10  import org.mule.config.i18n.CoreMessages;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * A Split message contains one or more message parts with an endpoint associated with each part.
17   * This class is used by the Message Splitter routers ({@link org.mule.routing.outbound.AbstractRoundRobinMessageSplitter})
18   * to define a mapping between message parts and the endpoint to dispatch on.
19   */
20  public class SplitMessage
21  {
22      private List parts = new ArrayList();
23  
24      public void addPart(Object part, OutboundEndpoint endpoint)
25      {
26          parts.add(new MessagePart(endpoint, part));
27      }
28  
29      public MessagePart getPart(int i)
30      {
31          return (MessagePart) parts.get(i);
32      }
33  
34      public int size()
35      {
36          return parts.size();
37      }
38  
39      public class MessagePart
40      {
41          private Object part;
42          private OutboundEndpoint endpoint;
43  
44          public MessagePart(OutboundEndpoint endpoint, Object part)
45          {
46              if (endpoint == null)
47              {
48                  throw new IllegalArgumentException(CoreMessages.objectIsNull("splitter endpoint").getMessage());
49              }
50  
51              if (part == null)
52              {
53                  throw new IllegalArgumentException(CoreMessages.objectIsNull("splitter messagePart").getMessage());
54              }
55              this.endpoint = endpoint;
56              this.part = part;
57          }
58  
59          public OutboundEndpoint getEndpoint()
60          {
61              return endpoint;
62          }
63  
64          public Object getPart()
65          {
66              return part;
67          }
68  
69  
70          public String toString()
71          {
72              final StringBuffer sb = new StringBuffer();
73              sb.append("MessagePart");
74              sb.append("{endpoint=").append(endpoint.getName());
75              sb.append(", part=").append(part);
76              sb.append('}');
77              return sb.toString();
78          }
79      }
80  }