01: /*
02: * Copyright 2002-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:
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
23: * on serialization of {@link RemoteInvocation} objects.
24: *
25: * Provides a "remoteInvocationFactory" property, with a
26: * {@link DefaultRemoteInvocationFactory} as default strategy.
27: *
28: * @author Juergen Hoeller
29: * @since 1.1
30: * @see #setRemoteInvocationFactory
31: * @see RemoteInvocation
32: * @see RemoteInvocationFactory
33: * @see DefaultRemoteInvocationFactory
34: */
35: public abstract class RemoteInvocationBasedAccessor extends
36: UrlBasedRemoteAccessor {
37:
38: private RemoteInvocationFactory remoteInvocationFactory = new DefaultRemoteInvocationFactory();
39:
40: /**
41: * Set the RemoteInvocationFactory to use for this accessor.
42: * Default is a {@link DefaultRemoteInvocationFactory}.
43: * <p>A custom invocation factory can add further context information
44: * to the invocation, for example user credentials.
45: */
46: public void setRemoteInvocationFactory(
47: RemoteInvocationFactory remoteInvocationFactory) {
48: this .remoteInvocationFactory = (remoteInvocationFactory != null ? remoteInvocationFactory
49: : new DefaultRemoteInvocationFactory());
50: }
51:
52: /**
53: * Return the RemoteInvocationFactory used by this accessor.
54: */
55: public RemoteInvocationFactory getRemoteInvocationFactory() {
56: return this .remoteInvocationFactory;
57: }
58:
59: /**
60: * Create a new RemoteInvocation object for the given AOP method invocation.
61: * <p>The default implementation delegates to the configured
62: * {@link #setRemoteInvocationFactory RemoteInvocationFactory}.
63: * This can be overridden in subclasses in order to provide custom RemoteInvocation
64: * subclasses, containing additional invocation parameters (e.g. user credentials).
65: * <p>Note that it is preferable to build a custom RemoteInvocationFactory
66: * as a reusable strategy, instead of overriding this method.
67: * @param methodInvocation the current AOP method invocation
68: * @return the RemoteInvocation object
69: * @see RemoteInvocationFactory#createRemoteInvocation
70: */
71: protected RemoteInvocation createRemoteInvocation(
72: MethodInvocation methodInvocation) {
73: return getRemoteInvocationFactory().createRemoteInvocation(
74: methodInvocation);
75: }
76:
77: /**
78: * Recreate the invocation result contained in the given RemoteInvocationResult object.
79: * <p>The default implementation calls the default <code>recreate()</code> method.
80: * This can be overridden in subclass to provide custom recreation, potentially
81: * processing the returned result object.
82: * @param result the RemoteInvocationResult to recreate
83: * @return a return value if the invocation result is a successful return
84: * @throws Throwable if the invocation result is an exception
85: * @see RemoteInvocationResult#recreate()
86: */
87: protected Object recreateRemoteInvocationResult(
88: RemoteInvocationResult result) throws Throwable {
89: return result.recreate();
90: }
91:
92: }
|