View Javadoc

1   /*
2    * $Id: OutboundPassThroughRouter.java 10961 2008-02-22 19:01:02Z dfeist $
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 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.outbound;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.MuleSession;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.api.routing.RoutingException;
17  import org.mule.api.routing.filter.Filter;
18  
19  import java.util.List;
20  
21  /**
22   * <code>OutboundPassThroughRouter</code> allows outbound routing over a single
23   * endpoint without any filtering. This class is used by Mule when a single outbound
24   * router is set on a UMODescriptor.
25   * 
26   */
27  public class OutboundPassThroughRouter extends FilteringOutboundRouter
28  {
29      public OutboundPassThroughRouter()
30      {
31          super();
32      }
33  
34  
35      public void addEndpoint(OutboundEndpoint endpoint)
36      {
37          if (endpoint == null)
38          {
39              return;
40          }
41          if (endpoints.size() == 1)
42          {
43              throw new IllegalArgumentException("Only one endpoint can be set on the PassThrough router");
44          }
45          super.addEndpoint(endpoint);
46      }
47  
48      public void setEndpoints(List endpoints)
49      {
50          if (endpoints.size() > 1)
51          {
52              throw new IllegalArgumentException("Only one endpoint can be set on the PassThrough router");
53          }
54          super.setEndpoints(endpoints);
55      }
56  
57      public void setFilter(Filter filter)
58      {
59          throw new UnsupportedOperationException(
60              "The Pass Through cannot use filters, use the FilteringOutboundRouter instead");
61      }
62  
63      public MuleMessage route(MuleMessage message, MuleSession session, boolean synchronous)
64          throws RoutingException
65      {
66          if (endpoints == null || endpoints.size() == 0)
67          {
68              return message;
69          }
70          return super.route(message, session, synchronous);
71      }
72  }