KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > method > MethodInvocationException


1 /*
2  * Copyright 2002-2006 the original author or authors.
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.springframework.binding.method;
17
18 import java.lang.reflect.InvocationTargetException JavaDoc;
19
20 import org.springframework.core.NestedRuntimeException;
21 import org.springframework.core.style.StylerUtils;
22
23 /**
24  * Base class for exceptions that report a method invocation failure.
25  * @author Keith Donald
26  */

27 public class MethodInvocationException extends NestedRuntimeException {
28
29     /**
30      * The method key.
31      */

32     private ClassMethodKey methodKey;
33
34     /**
35      * The method invocation argument values.
36      */

37     private Object JavaDoc[] arguments;
38
39     /**
40      * Signals that the method with the specified signature could not be invoked
41      * with the provided arguments.
42      * @param methodKey the method sig
43      * @param arguments the arguments
44      * @param cause the root cause
45      */

46     public MethodInvocationException(ClassMethodKey methodKey, Object JavaDoc[] arguments, Exception JavaDoc cause) {
47         super("Unable to invoke method " + methodKey + " with arguments " + StylerUtils.style(arguments), cause);
48     }
49
50     /**
51      * Returns the invoked method's signature.
52      */

53     public ClassMethodKey getMethodKey() {
54         return methodKey;
55     }
56
57     /**
58      * Returns the method invocation arguments;
59      */

60     public Object JavaDoc[] getArguments() {
61         return arguments;
62     }
63
64     /**
65      * Returns the target root cause exception of the method invocation failure.
66      * @return the target throwable
67      */

68     public Throwable JavaDoc getTargetException() {
69         if (getCause() instanceof InvocationTargetException JavaDoc) {
70             return ((InvocationTargetException JavaDoc)getCause()).getTargetException();
71         }
72         else {
73             return getCause();
74         }
75     }
76 }
Popular Tags