001 /* 002 // $Id: //open/mondrian/src/main/mondrian/xmla/XmlaException.java#4 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2004-2005 TONBELLER AG 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.xmla; 011 012 import mondrian.olap.MondrianException; 013 014 /** 015 * An exception thrown while processing an XMLA request. The faultcode 016 * corresponds to the SOAP Fault faultcode and the faultstring 017 * to the SOAP Fault faultstring. 018 * 019 * @author <a>Richard M. Emberson</a> 020 * @version $Id: //open/mondrian/src/main/mondrian/xmla/XmlaException.java#4 $ 021 */ 022 public class XmlaException extends MondrianException { 023 024 public static String formatFaultCode(XmlaException xex) { 025 return formatFaultCode(xex.getFaultCode(), xex.getCode()); 026 } 027 public static String formatFaultCode(String faultCode, String code) { 028 return formatFaultCode(XmlaConstants.SOAP_PREFIX, 029 faultCode, code); 030 } 031 public static String formatFaultCode(String nsPrefix, 032 String faultCode, String code) { 033 return nsPrefix + 034 ':' + 035 faultCode + 036 '.' + 037 code; 038 } 039 public static String formatDetail(String msg) { 040 return XmlaConstants.FAULT_FS_PREFIX + msg; 041 } 042 043 public static Throwable getRootCause(Throwable throwable) { 044 Throwable t = throwable; 045 while (t.getCause() != null) { 046 t = t.getCause(); 047 } 048 return t; 049 } 050 051 private final String faultCode; 052 private final String code; 053 private final String faultString; 054 055 public XmlaException( 056 String faultCode, 057 String code, 058 String faultString, 059 Throwable cause) { 060 super(faultString, cause); 061 this.faultCode = faultCode; 062 this.code = code; 063 this.faultString = faultString; 064 } 065 066 public String getFaultCode() { 067 return faultCode; 068 } 069 public String getCode() { 070 return code; 071 } 072 public String getFaultString() { 073 return faultString; 074 } 075 public String getDetail() { 076 Throwable t = getCause(); 077 t = getRootCause(t); 078 String detail = t.getMessage(); 079 return (detail != null) 080 ? detail 081 : t.getClass().getName(); 082 } 083 } 084 085 // End XmlaException.java 086