KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jxpath > JXPathException


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

16 package org.apache.commons.jxpath;
17
18 /**
19  * Thrown in various situations by JXPath; may contain a nested exception.
20  *
21  * @author Dmitri Plotnikov
22  * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:42 $
23  */

24
25 public class JXPathException extends RuntimeException JavaDoc {
26
27     /** @serial */
28     private Throwable JavaDoc exception;
29
30     /**
31      * Create a new <code>JXPathException</code> with no
32      * detail mesage.
33      */

34
35      public JXPathException() {
36          super();
37          this.exception = null;
38      }
39
40     /**
41      * Create a new <code>JXPathException</code> with
42      * the <code>String </code> specified as an error message.
43      *
44      * @param msg The error message for the exception.
45      */

46     public JXPathException(String JavaDoc msg) {
47         super(msg);
48         this.exception = null;
49     }
50
51
52     /**
53      * Create a new <code>JXPathException</code> with a
54      * given <code>Throwable</code> base cause of the error.
55      *
56      * @param e The exception to be encapsulated in a
57      * JXPathException.
58      */

59     public JXPathException(Throwable JavaDoc e) {
60         super(e.toString());
61         this.exception = e;
62     }
63
64     /**
65      * Create a new <code>JXPathException</code> with the
66      * given <code>Exception</code> base cause and detail message.
67      *
68      * @param e The exception to be encapsulated in a
69      * JXPathException
70      * @param msg The detail message.
71      */

72     public JXPathException(String JavaDoc msg, Throwable JavaDoc e) {
73         super(msg);
74         this.exception = e;
75     }
76
77
78     /**
79      * Return the message (if any) for this error . If there is no
80      * message for the exception and there is an encapsulated
81      * exception then the message of that exception will be returned.
82      *
83      * @return The error message.
84      */

85     public String JavaDoc getMessage() {
86         String JavaDoc message = super.getMessage();
87
88         if (exception != null) {
89             if (message == null) {
90                 if (exception.getMessage() != null) {
91                     return exception.getMessage();
92                 }
93                 else {
94                     return exception.getClass().getName();
95                 }
96             }
97             else {
98                 if (exception.getMessage() != null) {
99                     return message + "; " + exception.getMessage();
100                 }
101                 else {
102                     return message + "; " + exception.getClass().getName();
103                 }
104             }
105         }
106
107         return message;
108     }
109
110     /**
111      * Return the actual exception (if any) that caused this exception to
112      * be raised.
113      *
114      * @return The encapsulated exception, or null if there is none.
115      */

116     public Throwable JavaDoc getException() {
117         return exception;
118     }
119 }
Popular Tags