KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > util > ReflectionException


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.util;
8
9
10 /**
11  * This class is a generic reflection exception that is to
12  * be used to wrap up any exceptions that are thrown from
13  * the java.lang.Class methods and java.lang.reflect.Method
14  * methods.
15  *
16  * @author Brian Pontarelli
17  */

18 public class ReflectionException extends BaseException {
19
20     protected Throwable JavaDoc target;
21
22
23     /** Constructs a new empty reflection exception */
24     public ReflectionException() { }
25
26     /**
27      * Constructs a new reflection exception with the given error message
28      *
29      * @param msg The error message for this Exception
30      */

31     public ReflectionException(String JavaDoc msg) {
32         super(msg);
33     }
34
35     /**
36      * <p>
37      * Constructs a new reflection exception with the given error message and
38      * given root cause exception. The root cause exception is the exception
39      * used in the new JDK 1.4 exception stack. The exceptions that are normally
40      * used for the root cause are all the exceptions that occur when doing
41      * reflective operations
42      * </p>
43      *
44      * @param msg The exceptions error message
45      * @param cause The root cause throwable
46      */

47     public ReflectionException(String JavaDoc msg, Throwable JavaDoc cause) {
48         super(msg, cause);
49     }
50
51     /**
52      * <p>
53      * Constructs a new reflection exception with the given error message and
54      * given root cause exception. The root cause exception is the exception
55      * used in the new JDK 1.4 exception stack. The exceptions that are normally
56      * used for the root cause are all the exceptions that occur when doing
57      * reflective operations
58      * </p>
59      *
60      * @param cause The root cause throwable
61      */

62     public ReflectionException(Throwable JavaDoc cause) {
63         super(cause);
64     }
65
66     /**
67      * <p>
68      * Constructs a new reflection exception with the given error message and
69      * given root cause exception.
70      * </p>
71      *
72      * <p>
73      * The root cause exception is the exception used in the new JDK 1.4 exception
74      * stack. The exceptions that are normally used for the root cause are all
75      * the exceptions that occur when doing reflective operations.
76      * </p>
77      *
78      * <p>
79      * The second exception parameter is the target exception. This is the
80      * exception that is thrown from method that is invoked using the the {@link
81      * ReflectionTools#invokeMethod(java.lang.reflect.Method, Object, Object [])
82      * invokeMethod()}. That is, if the method invoked threw any exception,
83      * that exception would be contained here.
84      * </p>
85      *
86      * <p>
87      * See the javadoc for the invokeMethod method for more information.
88      * </p>
89      *
90      * @param msg The exceptions error message
91      * @param cause The root cause throwable
92      * @param target The target exception from the invocation (if applicable)
93      */

94     public ReflectionException(String JavaDoc msg, Throwable JavaDoc cause, Throwable JavaDoc target) {
95         super(msg, cause);
96         this.target = target;
97     }
98
99     /**
100      * Returns the target exception which is any exception that was thrown when
101      * a method was invoked using reflection.
102      *
103      * @return The Exception that was thrown from a Method invocation
104      */

105     public Throwable JavaDoc getTarget() {
106         return target;
107     }
108
109     /**
110      * Returns the full string of the exception as described by Throwable.toString()
111      * and also appends
112      */

113     public String JavaDoc toFullString() {
114         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
115         buf.append(super.toString());
116         buf.append("\nTarget: ");
117         buf.append(target);
118         return buf.toString();
119     }
120 }
Popular Tags