01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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: *
26: * @author Keith Donald
27: */
28: public class MethodInvocationException extends NestedRuntimeException {
29:
30: /**
31: * The method signature.
32: * Transient because a MethodSignature is not Serializable.
33: */
34: private transient MethodSignature methodSignature;
35:
36: /**
37: * The method invocation argument values.
38: * Transient because we cannot guarantee that the arguments are Serializable.
39: */
40: private transient Object[] arguments;
41:
42: /**
43: * Signals that the method with the specified signature could not be invoked
44: * with the provided arguments.
45: * @param methodSignature the method signature
46: * @param arguments the arguments
47: * @param cause the root cause
48: */
49: public MethodInvocationException(MethodSignature methodSignature,
50: Object[] arguments, Throwable cause) {
51: super ("Unable to invoke method " + methodSignature
52: + " with arguments " + StylerUtils.style(arguments),
53: cause);
54: this .methodSignature = methodSignature;
55: this .arguments = arguments;
56: }
57:
58: /**
59: * Returns the invoked method's signature.
60: */
61: public MethodSignature getMethodSignature() {
62: return methodSignature;
63: }
64:
65: /**
66: * Returns the method invocation arguments.
67: */
68: public Object[] getArguments() {
69: return arguments;
70: }
71:
72: /**
73: * Returns the target root cause exception of the method invocation failure.
74: * @return the target throwable
75: */
76: public Throwable getTargetException() {
77: Throwable targetException = getCause();
78: while (targetException instanceof InvocationTargetException) {
79: targetException = ((InvocationTargetException) targetException)
80: .getTargetException();
81: }
82: return targetException;
83: }
84: }
|