1 /**
2  *  ServingXML
3  *
4  *  Copyright (C) 2006  Daniel Parker
5  *    daniel.parker@servingxml.com
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  **/
20 
21 package com.servingxml.util;
22 
23 import java.lang.reflect.InvocationTargetException;
24 
25 import org.xml.sax.XMLReader;
26 
27 /**
28  *
29  *
30  * @author Daniel A. Parker (daniel.parker@servingxml.com)
31  */
32 
33 public class ServingXmlException extends RuntimeException {
34   static final long serialVersionUID = 1732939618562742663L;
35 
ServingXmlException(String s)36   public ServingXmlException(String s) {
37     super(s);
38   }
ServingXmlException(String s, Throwable e)39   public ServingXmlException(String s, Throwable e) {
40     super(s, e);
41   }
42 
getContext(StringBuilder sb)43   public void getContext(StringBuilder sb) {
44   }
45 
getMessage(StringBuilder sb)46   public void getMessage(StringBuilder sb) {
47     sb.append(getMessage());
48   }
49 
fromInvocationTargetException(InvocationTargetException e)50   public static ServingXmlException fromInvocationTargetException(InvocationTargetException e) {
51     Throwable t = e.getTargetException();
52     ServingXmlException pe;
53     if (t != null) {
54       if (t instanceof ServingXmlException) {
55         pe = (ServingXmlException)t;
56       } else if (t.getMessage() != null) {
57         pe = new ServingXmlException(t.getMessage(),t);
58       } else if (t.getCause() != null && t.getCause().getMessage() != null) {
59         pe = new ServingXmlException(t.getCause().getMessage(),t.getCause());
60       } else if (e.getMessage() != null) {
61         pe = new ServingXmlException(e.getMessage(),e);
62       } else {
63         pe = new ServingXmlException("Unknown exception",t);
64       }
65     } else if (e.getMessage() != null) {
66       pe = new ServingXmlException(e.getMessage(),e);
67     } else {
68       pe = new ServingXmlException("Unknown exception",e);
69     }
70     return pe;
71   }
72 
createXmlReader()73   public XMLReader createXmlReader() {
74     return new ServingXmlFaultReader(ServingXmlFaultCodes.RECEIVER_CODE,getMessage());
75   }
76 
toString()77   public String toString() {
78     return getMessage();
79   }
80 
getSupplementaryMessage(StringBuilder sb)81   public void getSupplementaryMessage(StringBuilder sb) {
82   }
83 
supplementMessage(String message)84   public ServingXmlException supplementMessage(String message) {
85     return new SupplementaryServingXmlException(message, this);
86   }
87 
contextualizeMessage(String context)88   public ServingXmlException contextualizeMessage(String context) {
89     return new ContextualServingXmlException(context, this);
90   }
91 }
92 
93