KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > support > RemoteInvocationResult


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
17 package org.springframework.remoting.support;
18
19 import java.io.Serializable JavaDoc;
20 import java.lang.reflect.InvocationTargetException JavaDoc;
21
22 /**
23  * Encapsulates a remote invocation result, holding a result value or an exception.
24  * Used for HTTP-based serialization invokers.
25  *
26  * <p>This is an SPI class, typically not used directly by applications.
27  * Can be subclassed for additional invocation parameters.
28  *
29  * @author Juergen Hoeller
30  * @since 1.1
31  * @see RemoteInvocation
32  */

33 public class RemoteInvocationResult implements Serializable JavaDoc {
34
35     /** Use serialVersionUID from Spring 1.1 for interoperability */
36     private static final long serialVersionUID = 2138555143707773549L;
37
38
39     private Object JavaDoc value;
40
41     private Throwable JavaDoc exception;
42
43
44     /**
45      * Create a new RemoteInvocationResult for the given result value.
46      * @param value the result value returned by a successful invocation
47      * of the target method
48      */

49     public RemoteInvocationResult(Object JavaDoc value) {
50         this.value = value;
51     }
52
53     /**
54      * Create a new RemoteInvocationResult for the given exception.
55      * @param exception the exception thrown by an unsuccessful invocation
56      * of the target method
57      */

58     public RemoteInvocationResult(Throwable JavaDoc exception) {
59         this.exception = exception;
60     }
61
62     /**
63      * Return the result value returned by a successful invocation
64      * of the target method, if any.
65      * @see #hasException
66      */

67     public Object JavaDoc getValue() {
68         return this.value;
69     }
70
71     /**
72      * Return the exception thrown by an unsuccessful invocation
73      * of the target method, if any.
74      * @see #hasException
75      */

76     public Throwable JavaDoc getException() {
77         return this.exception;
78     }
79
80     /**
81      * Return whether this invocation result holds an exception.
82      * If this returns <code>false</code>, the result value applies
83      * (even if <code>null</code>).
84      * @see #getValue
85      * @see #getException
86      */

87     public boolean hasException() {
88         return (this.exception != null);
89     }
90
91
92     /**
93      * Recreate the invocation result, either returning the result value
94      * in case of a successful invocation of the target method, or
95      * rethrowing the exception thrown by the target method.
96      * @return the result value, if any
97      * @throws Throwable the exception, if any
98      */

99     public Object JavaDoc recreate() throws Throwable JavaDoc {
100         if (this.exception != null) {
101             Throwable JavaDoc exToThrow = this.exception;
102             if (this.exception instanceof InvocationTargetException JavaDoc) {
103                 exToThrow = ((InvocationTargetException JavaDoc) this.exception).getTargetException();
104             }
105             RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow);
106             throw exToThrow;
107         }
108         else {
109             return this.value;
110         }
111     }
112
113 }
114
Popular Tags