001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.activemq.util; 019 020 import org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 023 import javax.jms.JMSException; 024 import java.io.IOException; 025 026 /** 027 * A helper class for creating new JMS exceptions 028 * 029 * @version $Revision: 1.1.1.1 $ 030 */ 031 public class JMSExceptionHelper { 032 033 private static final Log log = LogFactory.getLog(JMSExceptionHelper.class); 034 035 public static JMSException newJMSException(String message, Throwable cause) { 036 if (cause instanceof Exception) { 037 return newJMSException(message, (Exception) cause); 038 } 039 else { 040 // lets wrap in an Exception 041 return newJMSException(message, new Exception(cause)); 042 } 043 } 044 045 public static JMSException newJMSException(String message, Exception cause) { 046 // we should turn off warn level logging other than when debugging etc 047 log.trace(message, cause); 048 //log.warn(message, cause); 049 JMSException jmsEx = new JMSException(message); 050 jmsEx.setLinkedException(cause); 051 jmsEx.initCause(cause); 052 return jmsEx; 053 } 054 055 public static JMSException newJMSException(Throwable e) { 056 if (e instanceof JMSException) { 057 return (JMSException) e; 058 } 059 else { 060 return newJMSException(e.getMessage(), e); 061 } 062 } 063 064 public static IOException newIOException(JMSException e) { 065 IOException answer = new IOException(e.getMessage()); 066 answer.setStackTrace(e.getStackTrace()); 067 return answer; 068 } 069 070 }