KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2007 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 org.aopalliance.intercept.MethodInvocation;
20
21 /**
22  * Abstract base class for remote service accessors that are based on serialization
23  * of {@link RemoteInvocation} objects. Provides a "remoteInvocationFactory" property,
24  * with a {@link DefaultRemoteInvocationFactory} as default.
25  *
26  * @author Juergen Hoeller
27  * @since 1.1
28  * @see #setRemoteInvocationFactory
29  * @see RemoteInvocation
30  * @see RemoteInvocationFactory
31  * @see DefaultRemoteInvocationFactory
32  */

33 public abstract class RemoteInvocationBasedAccessor extends UrlBasedRemoteAccessor {
34
35     private RemoteInvocationFactory remoteInvocationFactory = new DefaultRemoteInvocationFactory();
36
37
38     /**
39      * Set the RemoteInvocationFactory to use for this accessor.
40      * Default is a {@link DefaultRemoteInvocationFactory}.
41      * <p>A custom invocation factory can add further context information
42      * to the invocation, for example user credentials.
43      */

44     public void setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory) {
45         this.remoteInvocationFactory =
46                 (remoteInvocationFactory != null ? remoteInvocationFactory : new DefaultRemoteInvocationFactory());
47     }
48
49     /**
50      * Return the RemoteInvocationFactory used by this accessor.
51      */

52     public RemoteInvocationFactory getRemoteInvocationFactory() {
53         return this.remoteInvocationFactory;
54     }
55
56     /**
57      * Create a new RemoteInvocation object for the given AOP method invocation.
58      * <p>The default implementation delegates to the configured
59      * {@link #setRemoteInvocationFactory RemoteInvocationFactory}.
60      * This can be overridden in subclasses in order to provide custom RemoteInvocation
61      * subclasses, containing additional invocation parameters (e.g. user credentials).
62      * <p>Note that it is preferable to build a custom RemoteInvocationFactory
63      * as a reusable strategy, instead of overriding this method.
64      * @param methodInvocation the current AOP method invocation
65      * @return the RemoteInvocation object
66      * @see RemoteInvocationFactory#createRemoteInvocation
67      */

68     protected RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
69         return getRemoteInvocationFactory().createRemoteInvocation(methodInvocation);
70     }
71
72     /**
73      * Recreate the invocation result contained in the given RemoteInvocationResult object.
74      * <p>The default implementation calls the default <code>recreate()</code> method.
75      * This can be overridden in subclass to provide custom recreation, potentially
76      * processing the returned result object.
77      * @param result the RemoteInvocationResult to recreate
78      * @return a return value if the invocation result is a successful return
79      * @throws Throwable if the invocation result is an exception
80      * @see RemoteInvocationResult#recreate()
81      */

82     protected Object JavaDoc recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable JavaDoc {
83         return result.recreate();
84     }
85
86 }
87
Popular Tags