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 // Copyright (C) 2007-2008 Julian Hyde
006 // All Rights Reserved.
007 // You must accept the terms of that agreement to use this software.
008 */
009 package org.olap4j.driver.xmla;
010
011 import org.olap4j.OlapException;
012 import org.olap4j.Cell;
013
014 import java.sql.SQLException;
015
016 /**
017 * Helper class which encapsulates policies which are
018 * common throughout a driver. These policies include exception handling
019 * and factory methods.
020 *
021 * @author Luc Boudreau
022 * @version $Id: XmlaHelper.java 236 2009-05-12 07:42:17Z jhyde $
023 */
024 public class XmlaHelper {
025
026 public OlapException createException(String msg) {
027 return new OlapException(msg);
028 }
029
030 public OlapException createException(Throwable cause) {
031 return new OlapException(cause.getMessage(), cause);
032 }
033
034 public OlapException createException(String msg, Throwable cause) {
035 return new OlapException(msg, cause);
036 }
037
038 public OlapException createException(Cell context, String msg) {
039 OlapException exception = new OlapException(msg);
040 exception.setContext(context);
041 return exception;
042 }
043
044 public OlapException createException(
045 Cell context, String msg, Throwable cause)
046 {
047 OlapException exception = new OlapException(msg, cause);
048 exception.setContext(context);
049 return exception;
050 }
051
052 public OlapException toOlapException(SQLException e) {
053 if (e instanceof OlapException) {
054 return (OlapException) e;
055 } else {
056 return new OlapException(null, e);
057 }
058 }
059 }
060
061 // End XmlaHelper.java