KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > JMSExceptionSupport


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.util;
19
20 import javax.jms.JMSException JavaDoc;
21 import javax.jms.MessageEOFException JavaDoc;
22 import javax.jms.MessageFormatException JavaDoc;
23
24 final public class JMSExceptionSupport {
25
26     public static JMSException JavaDoc create(String JavaDoc msg, Throwable JavaDoc cause) {
27         JMSException JavaDoc exception = new JMSException JavaDoc(msg);
28         exception.initCause(cause);
29         return exception;
30     }
31
32     public static JMSException JavaDoc create(String JavaDoc msg, Exception JavaDoc cause) {
33         JMSException JavaDoc exception = new JMSException JavaDoc(msg);
34         exception.setLinkedException(cause);
35         exception.initCause(cause);
36         return exception;
37     }
38     
39     public static JMSException JavaDoc create(Throwable JavaDoc cause) {
40         if (cause instanceof JMSException JavaDoc) {
41             return (JMSException JavaDoc) cause;
42         }
43         String JavaDoc msg = cause.getMessage();
44         if( msg==null || msg.length()==0 )
45             msg = cause.toString();
46         JMSException JavaDoc exception = new JMSException JavaDoc(msg);
47         exception.initCause(cause);
48         return exception;
49     }
50
51     public static JMSException JavaDoc create(Exception JavaDoc cause) {
52         if (cause instanceof JMSException JavaDoc) {
53             return (JMSException JavaDoc) cause;
54         }
55         String JavaDoc msg = cause.getMessage();
56         if( msg==null || msg.length()==0 )
57             msg = cause.toString();
58         JMSException JavaDoc exception = new JMSException JavaDoc(msg);
59         exception.setLinkedException(cause);
60         exception.initCause(cause);
61         return exception;
62     }
63
64     public static MessageEOFException JavaDoc createMessageEOFException(Exception JavaDoc cause) {
65         String JavaDoc msg = cause.getMessage();
66         if( msg==null || msg.length()==0 )
67             msg = cause.toString();
68         MessageEOFException JavaDoc exception = new MessageEOFException JavaDoc(msg);
69         exception.setLinkedException(cause);
70         exception.initCause(cause);
71         return exception;
72     }
73     
74     public static MessageFormatException JavaDoc createMessageFormatException(Exception JavaDoc cause) {
75         String JavaDoc msg = cause.getMessage();
76         if( msg==null || msg.length()==0 )
77             msg = cause.toString();
78         MessageFormatException JavaDoc exception = new MessageFormatException JavaDoc(msg);
79         exception.setLinkedException(cause);
80         exception.initCause(cause);
81         return exception;
82     }
83 }
84
Popular Tags