View Javadoc

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