View Javadoc

1   /*
2    * $Id: OutboundPassThroughRouter.java 19547 2010-09-10 12:22:31Z 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  
11  package org.mule.routing.outbound;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.processor.MessageProcessor;
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 Service.
25   */
26  public class OutboundPassThroughRouter extends FilteringOutboundRouter
27  {
28      public OutboundPassThroughRouter()
29      {
30          super();
31      }
32  
33      @Override
34      public void addRoute(MessageProcessor target) throws MuleException
35      {
36          if (target == null)
37          {
38              return;
39          }
40          if (routes.size() == 1)
41          {
42              throw new IllegalArgumentException("Only one target can be set on the PassThrough router");
43          }
44          super.addRoute(target);
45      }
46  
47      @Override
48      public void setRoutes(List<MessageProcessor> endpoints) throws MuleException
49      {
50          if (endpoints.size() > 1)
51          {
52              throw new IllegalArgumentException("Only one endpoint can be set on the PassThrough router");
53          }
54          super.setRoutes(endpoints);
55      }
56  
57      @Override
58      public void setFilter(Filter filter)
59      {
60          throw new UnsupportedOperationException(
61              "The Pass Through cannot use filters, use the FilteringOutboundRouter instead");
62      }
63  
64      @Override
65      public MuleEvent route(MuleEvent event) throws RoutingException
66      {
67          if (routes == null || routes.size() == 0)
68          {
69              return event;
70          }
71          return super.route(event);
72      }
73  }