1 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 ; 20 21 28 29 public class MessagingException extends UMOException 30 { 31 34 private static final long serialVersionUID = 6941498759267936649L; 35 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 cause) 48 { 49 super(cause); 50 this.umoMessage = umoMessage; 51 setMessage(generateMessage(message)); 52 } 53 54 public MessagingException(Message message, Object 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 )null); 64 } 65 setMessage(generateMessage(message)); 66 } 67 68 public MessagingException(Message message, Object payload, Throwable 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 )null); 78 } 79 setMessage(generateMessage(message)); 80 } 81 82 private String generateMessage(Message message) 83 { 84 StringBuffer buf = new StringBuffer (80); 85 86 if (message != null) 87 { 88 buf.append(message.getMessage()).append(". "); 89 } 90 91 if (umoMessage != null) 92 { 93 Object 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 |