KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > umo > MessagingException


1 /*
2  * $Id: MessagingException.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.impl.MuleMessage;
16 import org.mule.impl.RequestContext;
17 import org.mule.providers.NullPayload;
18
19 import java.util.Map JavaDoc;
20
21 /**
22  * <code>MessagingException</code> is a general message exception thrown when
23  * errors specific to Message processing occur.
24  *
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @version $Revision: 3798 $
27  */

28
29 public class MessagingException extends UMOException
30 {
31     /**
32      * Serial version
33      */

34     private static final long serialVersionUID = 6941498759267936649L;
35     /**
36      * The UMOMessage being processed when the error occurred
37      */

38     protected transient UMOMessage umoMessage = null;
39
40     public MessagingException(Message message, UMOMessage umoMessage)
41     {
42         super();
43         this.umoMessage = umoMessage;
44         setMessage(generateMessage(message));
45     }
46
47     public MessagingException(Message message, UMOMessage umoMessage, Throwable JavaDoc cause)
48     {
49         super(cause);
50         this.umoMessage = umoMessage;
51         setMessage(generateMessage(message));
52     }
53
54     public MessagingException(Message message, Object JavaDoc payload)
55     {
56         super();
57         if (payload == null)
58         {
59             this.umoMessage = RequestContext.getEventContext().getMessage();
60         }
61         else
62         {
63             this.umoMessage = new MuleMessage(payload, (Map JavaDoc)null);
64         }
65         setMessage(generateMessage(message));
66     }
67
68     public MessagingException(Message message, Object JavaDoc payload, Throwable JavaDoc cause)
69     {
70         super(cause);
71         if (payload == null)
72         {
73             this.umoMessage = RequestContext.getEventContext().getMessage();
74         }
75         else
76         {
77             this.umoMessage = new MuleMessage(payload, (Map JavaDoc)null);
78         }
79         setMessage(generateMessage(message));
80     }
81
82     private String JavaDoc generateMessage(Message message)
83     {
84         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(80);
85
86         if (message != null)
87         {
88             buf.append(message.getMessage()).append(". ");
89         }
90
91         if (umoMessage != null)
92         {
93             Object JavaDoc payload = umoMessage.getPayload();
94             if (payload == null)
95             {
96                 payload = new NullPayload();
97             }
98
99             buf.append(Messages.get(Messages.MESSAGE_IS_OF_TYPE_X, payload.getClass().getName()));
100             addInfo("Payload", payload.toString());
101         }
102         else
103         {
104             buf.append("The current UMOMessage is null! Please report this to dev@mule.codehaus.org.");
105             addInfo("Payload", new NullPayload().toString());
106         }
107
108         return buf.toString();
109     }
110
111     public UMOMessage getUmoMessage()
112     {
113         return umoMessage;
114     }
115
116 }
117
Popular Tags