< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/MessagingException.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  99      */
 100     public synchronized boolean setNextException(Exception ex) {
 101         Exception theEnd = this;
 102         while (theEnd instanceof MessagingException &&
 103                ((MessagingException)theEnd).next != null) {
 104             theEnd = ((MessagingException)theEnd).next;
 105         }
 106         // If the end is a MessagingException, we can add this
 107         // exception to the chain.
 108         if (theEnd instanceof MessagingException) {
 109             ((MessagingException)theEnd).next = ex;
 110             return true;
 111         } else
 112             return false;
 113     }
 114 
 115     /**
 116      * Produce the message, include the message from the nested
 117      * exception if there is one.
 118      */

 119     public String getMessage() {
 120         if (next == null)
 121             return super.getMessage();
 122         Exception n = next;
 123         String s = super.getMessage();
 124         StringBuilder sb = new StringBuilder(s == null ? "" : s);
 125         while (n != null) {
 126             sb.append(";\n  nested exception is:\n\t");
 127             if (n instanceof MessagingException) {
 128                 MessagingException mex = (MessagingException)n;
 129                 sb.append(n.getClass().toString());
 130                 String msg = mex.getSuperMessage();
 131                 if (msg != null) {
 132                     sb.append(": ");
 133                     sb.append(msg);
 134                 }
 135                 n = mex.next;
 136             } else {
 137                 sb.append(n.toString());
 138                 n = null;
   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  99      */
 100     public synchronized boolean setNextException(Exception ex) {
 101         Exception theEnd = this;
 102         while (theEnd instanceof MessagingException &&
 103                ((MessagingException)theEnd).next != null) {
 104             theEnd = ((MessagingException)theEnd).next;
 105         }
 106         // If the end is a MessagingException, we can add this
 107         // exception to the chain.
 108         if (theEnd instanceof MessagingException) {
 109             ((MessagingException)theEnd).next = ex;
 110             return true;
 111         } else
 112             return false;
 113     }
 114 
 115     /**
 116      * Produce the message, include the message from the nested
 117      * exception if there is one.
 118      */
 119     @Override
 120     public String getMessage() {
 121         if (next == null)
 122             return super.getMessage();
 123         Exception n = next;
 124         String s = super.getMessage();
 125         StringBuilder sb = new StringBuilder(s == null ? "" : s);
 126         while (n != null) {
 127             sb.append(";\n  nested exception is:\n\t");
 128             if (n instanceof MessagingException) {
 129                 MessagingException mex = (MessagingException)n;
 130                 sb.append(n.getClass().toString());
 131                 String msg = mex.getSuperMessage();
 132                 if (msg != null) {
 133                     sb.append(": ");
 134                     sb.append(msg);
 135                 }
 136                 n = mex.next;
 137             } else {
 138                 sb.append(n.toString());
 139                 n = null;
< prev index next >