001/* 002// $Id: XmlaHelper.java 482 2012-01-05 23:27:27Z jhyde $ 003// 004// Licensed to Julian Hyde under one or more contributor license 005// agreements. See the NOTICE file distributed with this work for 006// additional information regarding copyright ownership. 007// 008// Julian Hyde licenses this file to you under the Apache License, 009// Version 2.0 (the "License"); you may not use this file except in 010// compliance with the License. You may obtain a copy of the License at: 011// 012// http://www.apache.org/licenses/LICENSE-2.0 013// 014// Unless required by applicable law or agreed to in writing, software 015// distributed under the License is distributed on an "AS IS" BASIS, 016// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017// See the License for the specific language governing permissions and 018// limitations under the License. 019*/ 020package org.olap4j.driver.xmla; 021 022import org.olap4j.Cell; 023import org.olap4j.OlapException; 024 025import java.sql.SQLException; 026 027/** 028 * Helper class which encapsulates policies which are 029 * common throughout a driver. These policies include exception handling 030 * and factory methods. 031 * 032 * @author Luc Boudreau 033 * @version $Id: XmlaHelper.java 482 2012-01-05 23:27:27Z jhyde $ 034 */ 035public class XmlaHelper { 036 037 public OlapException createException(String msg) { 038 return new OlapException(msg); 039 } 040 041 public OlapException createException(Throwable cause) { 042 return new OlapException(cause.getMessage(), cause); 043 } 044 045 public OlapException createException(String msg, Throwable cause) { 046 return new OlapException(msg, cause); 047 } 048 049 public OlapException createException(Cell context, String msg) { 050 OlapException exception = new OlapException(msg); 051 exception.setContext(context); 052 return exception; 053 } 054 055 public OlapException createException( 056 Cell context, String msg, Throwable cause) 057 { 058 OlapException exception = new OlapException(msg, cause); 059 exception.setContext(context); 060 return exception; 061 } 062 063 public OlapException toOlapException(SQLException e) { 064 if (e instanceof OlapException) { 065 return (OlapException) e; 066 } else { 067 return new OlapException(null, e); 068 } 069 } 070} 071 072// End XmlaHelper.java