View Javadoc

1   /*
2    * $Id: RoutingException.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.umo.routing;
12  
13  import org.mule.config.i18n.CoreMessages;
14  import org.mule.config.i18n.Message;
15  import org.mule.umo.MessagingException;
16  import org.mule.umo.UMOMessage;
17  import org.mule.umo.endpoint.UMOImmutableEndpoint;
18  
19  /**
20   * <code>RoutingException</code> is a base class for all routing exceptions.
21   * Routing exceptions are only thrown for InboundRouterCollection and
22   * OutboundRouterCollection and deriving types. Mule itself does not throw routing
23   * exceptions when routing internal events.
24   */
25  public class RoutingException extends MessagingException
26  {
27      /**
28       * Serial version
29       */
30      private static final long serialVersionUID = 2478458847072048645L;
31  
32      protected final transient UMOImmutableEndpoint endpoint;
33  
34      public RoutingException(UMOMessage message, UMOImmutableEndpoint endpoint)
35      {
36          super(generateMessage(null, endpoint), message);
37          this.endpoint = endpoint;
38      }
39  
40      public RoutingException(UMOMessage umoMessage, UMOImmutableEndpoint endpoint, Throwable cause)
41      {
42          super(generateMessage(null, endpoint), umoMessage, cause);
43          this.endpoint = endpoint;
44      }
45  
46      public RoutingException(Message message, UMOMessage umoMessage, UMOImmutableEndpoint endpoint)
47      {
48          super(generateMessage(message, endpoint), umoMessage);
49          this.endpoint = endpoint;
50      }
51  
52      public RoutingException(Message message,
53                              UMOMessage umoMessage,
54                              UMOImmutableEndpoint endpoint,
55                              Throwable cause)
56      {
57          super(generateMessage(message, endpoint), umoMessage, cause);
58          this.endpoint = endpoint;
59      }
60  
61      public UMOImmutableEndpoint getEndpoint()
62      {
63          return endpoint;
64      }
65  
66      private static Message generateMessage(Message message, UMOImmutableEndpoint endpoint)
67      {
68          Message m = CoreMessages.failedToRouterViaEndpoint(endpoint);
69          if (message != null)
70          {
71              message.setNextMessage(m);
72              return message;
73          }
74          else
75          {
76              return m;
77          }
78      }
79  }