View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.util;
    19
    20  import org.apache.commons.logging.Log;
    21  import org.apache.commons.logging.LogFactory;
    22
    23  import javax.jms.JMSException;
    24  import java.io.IOException;
    25
    26  /***
    27   * A helper class for creating new JMS exceptions
    28   *
    29   * @version $Revision: 1.11 $
    30   */
    31  public class JMSExceptionHelper {
    32
    33      private static final Log log = LogFactory.getLog(JMSExceptionHelper.class);
    34
    35      public static JMSException newJMSException(String message, Throwable cause) {
    36          if (cause instanceof Exception) {
    37              return newJMSException(message, (Exception) cause);
    38          }
    39          else {
    40              // lets wrap in an Exception
    41              return newJMSException(message, new Exception(cause));
    42          }
    43      }
    44
    45      public static JMSException newJMSException(String message, Exception cause) {
    46          // we should turn off warn level logging other than when debugging etc
    47          log.trace(message, cause);
    48          //log.warn(message, cause);
    49          JMSException jmsEx = new JMSException(message);
    50          jmsEx.setLinkedException(cause);
    51          jmsEx.initCause(cause);
    52          return jmsEx;
    53      }
    54
    55      public static JMSException newJMSException(Throwable e) {
    56          if (e instanceof JMSException) {
    57              return (JMSException) e;
    58          }
    59          else {
    60              return newJMSException(e.getMessage(), e);
    61          }
    62      }
    63
    64      public static IOException newIOException(JMSException e) {
    65          IOException answer = new IOException(e.getMessage());
    66          answer.setStackTrace(e.getStackTrace());
    67          return answer;
    68      }
    69
    70  }