KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > xmla > XmlaException


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/xmla/XmlaException.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2004-2005 TONBELLER AG
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.xmla;
11
12 import mondrian.olap.MondrianException;
13
14 /**
15  * An exception thrown while processing an XMLA request. The faultcode
16  * corresponds to the SOAP Fault faultcode and the faultstring
17  * to the SOAP Fault faultstring.
18  *
19  * @author <a>Richard M. Emberson</a>
20  * @version $Id: //open/mondrian/src/main/mondrian/xmla/XmlaException.java#3 $
21  */

22 public class XmlaException extends MondrianException {
23
24     public static String JavaDoc formatFaultCode(XmlaException xex) {
25         return formatFaultCode(xex.getFaultCode(), xex.getCode());
26     }
27     public static String JavaDoc formatFaultCode(String JavaDoc faultCode, String JavaDoc code) {
28         return formatFaultCode(XmlaConstants.SOAP_PREFIX,
29                 faultCode, code);
30     }
31     public static String JavaDoc formatFaultCode(String JavaDoc nsPrefix,
32                 String JavaDoc faultCode, String JavaDoc code) {
33         return nsPrefix +
34             ':' +
35             faultCode +
36             '.' +
37             code;
38     }
39     public static String JavaDoc formatDetail(String JavaDoc msg) {
40         return XmlaConstants.FAULT_FS_PREFIX + msg;
41     }
42
43     public static Throwable JavaDoc getRootCause(Throwable JavaDoc throwable) {
44         Throwable JavaDoc t = throwable;
45         while (t.getCause() != null) {
46             t = t.getCause();
47         }
48         return t;
49     }
50
51     private final String JavaDoc faultCode;
52     private final String JavaDoc code;
53     private final String JavaDoc faultString;
54
55     public XmlaException(
56             String JavaDoc faultCode,
57             String JavaDoc code,
58             String JavaDoc faultString,
59             Throwable JavaDoc cause) {
60         super(faultString, cause);
61         this.faultCode = faultCode;
62         this.code = code;
63         this.faultString = faultString;
64     }
65
66     public String JavaDoc getFaultCode() {
67         return faultCode;
68     }
69     public String JavaDoc getCode() {
70         return code;
71     }
72     public String JavaDoc getFaultString() {
73         return faultString;
74     }
75     public String JavaDoc getDetail() {
76         Throwable JavaDoc t = getCause();
77         t = getRootCause(t);
78         String JavaDoc detail = t.getMessage();
79         return (detail != null)
80             ? detail
81             : t.getClass().getName();
82     }
83 }
84
85
Popular Tags