Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | /* |
aoqi@0 | 27 | * @(#)MessagingException.java 1.10 02/06/13 |
aoqi@0 | 28 | */ |
aoqi@0 | 29 | |
aoqi@0 | 30 | |
aoqi@0 | 31 | |
aoqi@0 | 32 | package com.sun.xml.internal.messaging.saaj.packaging.mime; |
aoqi@0 | 33 | |
aoqi@0 | 34 | |
aoqi@0 | 35 | /** |
aoqi@0 | 36 | * The base class for all exceptions thrown by the Messaging classes |
aoqi@0 | 37 | * |
aoqi@0 | 38 | * @author John Mani |
aoqi@0 | 39 | * @author Bill Shannon |
aoqi@0 | 40 | */ |
aoqi@0 | 41 | |
aoqi@0 | 42 | public class MessagingException extends Exception { |
aoqi@0 | 43 | |
aoqi@0 | 44 | /** |
aoqi@0 | 45 | * The next exception in the chain. |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * @serial |
aoqi@0 | 48 | */ |
aoqi@0 | 49 | private Exception next; |
aoqi@0 | 50 | |
aoqi@0 | 51 | /** |
aoqi@0 | 52 | * Constructs a MessagingException with no detail message. |
aoqi@0 | 53 | */ |
aoqi@0 | 54 | public MessagingException() { |
aoqi@0 | 55 | super(); |
aoqi@0 | 56 | } |
aoqi@0 | 57 | |
aoqi@0 | 58 | /** |
aoqi@0 | 59 | * Constructs a MessagingException with the specified detail message. |
aoqi@0 | 60 | * @param s the detail message |
aoqi@0 | 61 | */ |
aoqi@0 | 62 | public MessagingException(String s) { |
aoqi@0 | 63 | super(s); |
aoqi@0 | 64 | } |
aoqi@0 | 65 | |
aoqi@0 | 66 | /** |
aoqi@0 | 67 | * Constructs a MessagingException with the specified |
aoqi@0 | 68 | * Exception and detail message. The specified exception is chained |
aoqi@0 | 69 | * to this exception. |
aoqi@0 | 70 | * @param s the detail message |
aoqi@0 | 71 | * @param e the embedded exception |
aoqi@0 | 72 | * @see #getNextException |
aoqi@0 | 73 | * @see #setNextException |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | public MessagingException(String s, Exception e) { |
aoqi@0 | 76 | super(s); |
aoqi@0 | 77 | next = e; |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Get the next exception chained to this one. If the |
aoqi@0 | 82 | * next exception is a MessagingException, the chain |
aoqi@0 | 83 | * may extend further. |
aoqi@0 | 84 | * |
aoqi@0 | 85 | * @return next Exception, null if none. |
aoqi@0 | 86 | */ |
aoqi@0 | 87 | public Exception getNextException() { |
aoqi@0 | 88 | return next; |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | /** |
aoqi@0 | 92 | * Add an exception to the end of the chain. If the end |
aoqi@0 | 93 | * is <strong>not</strong> a MessagingException, this |
aoqi@0 | 94 | * exception cannot be added to the end. |
aoqi@0 | 95 | * |
aoqi@0 | 96 | * @param ex the new end of the Exception chain |
aoqi@0 | 97 | * @return <code>true</code> if the this Exception |
aoqi@0 | 98 | * was added, <code>false</code> otherwise. |
aoqi@0 | 99 | */ |
aoqi@0 | 100 | public synchronized boolean setNextException(Exception ex) { |
aoqi@0 | 101 | Exception theEnd = this; |
aoqi@0 | 102 | while (theEnd instanceof MessagingException && |
aoqi@0 | 103 | ((MessagingException)theEnd).next != null) { |
aoqi@0 | 104 | theEnd = ((MessagingException)theEnd).next; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | // If the end is a MessagingException, we can add this |
aoqi@0 | 107 | // exception to the chain. |
aoqi@0 | 108 | if (theEnd instanceof MessagingException) { |
aoqi@0 | 109 | ((MessagingException)theEnd).next = ex; |
aoqi@0 | 110 | return true; |
aoqi@0 | 111 | } else |
aoqi@0 | 112 | return false; |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | /** |
aoqi@0 | 116 | * Produce the message, include the message from the nested |
aoqi@0 | 117 | * exception if there is one. |
aoqi@0 | 118 | */ |
aoqi@0 | 119 | public String getMessage() { |
aoqi@0 | 120 | if (next == null) |
aoqi@0 | 121 | return super.getMessage(); |
aoqi@0 | 122 | Exception n = next; |
aoqi@0 | 123 | String s = super.getMessage(); |
aoqi@0 | 124 | StringBuffer sb = new StringBuffer(s == null ? "" : s); |
aoqi@0 | 125 | while (n != null) { |
aoqi@0 | 126 | sb.append(";\n nested exception is:\n\t"); |
aoqi@0 | 127 | if (n instanceof MessagingException) { |
aoqi@0 | 128 | MessagingException mex = (MessagingException)n; |
aoqi@0 | 129 | sb.append(n.getClass().toString()); |
aoqi@0 | 130 | String msg = mex.getSuperMessage(); |
aoqi@0 | 131 | if (msg != null) { |
aoqi@0 | 132 | sb.append(": "); |
aoqi@0 | 133 | sb.append(msg); |
aoqi@0 | 134 | } |
aoqi@0 | 135 | n = mex.next; |
aoqi@0 | 136 | } else { |
aoqi@0 | 137 | sb.append(n.toString()); |
aoqi@0 | 138 | n = null; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | return sb.toString(); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | private String getSuperMessage() { |
aoqi@0 | 145 | return super.getMessage(); |
aoqi@0 | 146 | } |
aoqi@0 | 147 | } |