001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2006-2009 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.xmla; 011 012import 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 */ 021public class XmlaException extends MondrianException { 022 023 public static String formatFaultCode(XmlaException xex) { 024 return formatFaultCode(xex.getFaultCode(), xex.getCode()); 025 } 026 public static String formatFaultCode(String faultCode, String code) { 027 return formatFaultCode( 028 XmlaConstants.SOAP_PREFIX, 029 faultCode, code); 030 } 031 032 public static String formatFaultCode( 033 String nsPrefix, 034 String faultCode, String code) 035 { 036 return nsPrefix 037 + ':' 038 + faultCode 039 + '.' 040 + code; 041 } 042 public static String formatDetail(String msg) { 043 return XmlaConstants.FAULT_FS_PREFIX + msg; 044 } 045 046 public static Throwable getRootCause(Throwable throwable) { 047 Throwable t = throwable; 048 while (t.getCause() != null) { 049 t = t.getCause(); 050 } 051 return t; 052 } 053 054 private final String faultCode; 055 private final String code; 056 private final String faultString; 057 058 public XmlaException( 059 String faultCode, 060 String code, 061 String faultString, 062 Throwable cause) 063 { 064 super(faultString, cause); 065 this.faultCode = faultCode; 066 this.code = code; 067 this.faultString = faultString; 068 } 069 070 public String getFaultCode() { 071 return faultCode; 072 } 073 public String getCode() { 074 return code; 075 } 076 public String getFaultString() { 077 return faultString; 078 } 079 public String getDetail() { 080 Throwable t = getCause(); 081 t = getRootCause(t); 082 String detail = t.getMessage(); 083 return (detail != null) 084 ? detail 085 : t.getClass().getName(); 086 } 087} 088 089// End XmlaException.java 090