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 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
34: UrlBasedRemoteAccessor {
35:
36: private RemoteInvocationFactory remoteInvocationFactory = new DefaultRemoteInvocationFactory();
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(
45: RemoteInvocationFactory remoteInvocationFactory) {
46: this .remoteInvocationFactory = (remoteInvocationFactory != null ? remoteInvocationFactory
47: : new DefaultRemoteInvocationFactory());
48: }
49:
50: /**
51: * Return the RemoteInvocationFactory used by this accessor.
52: */
53: public RemoteInvocationFactory getRemoteInvocationFactory() {
54: return this .remoteInvocationFactory;
55: }
56:
57: /**
58: * Create a new RemoteInvocation object for the given AOP method invocation.
59: * <p>The default implementation delegates to the configured
60: * {@link #setRemoteInvocationFactory RemoteInvocationFactory}.
61: * This can be overridden in subclasses in order to provide custom RemoteInvocation
62: * subclasses, containing additional invocation parameters (e.g. user credentials).
63: * <p>Note that it is preferable to build a custom RemoteInvocationFactory
64: * as a reusable strategy, instead of overriding this method.
65: * @param methodInvocation the current AOP method invocation
66: * @return the RemoteInvocation object
67: * @see RemoteInvocationFactory#createRemoteInvocation
68: */
69: protected RemoteInvocation createRemoteInvocation(
70: MethodInvocation methodInvocation) {
71: return getRemoteInvocationFactory().createRemoteInvocation(
72: methodInvocation);
73: }
74:
75: /**
76: * Recreate the invocation result contained in the given RemoteInvocationResult object.
77: * <p>The default implementation calls the default <code>recreate()</code> method.
78: * This can be overridden in subclass to provide custom recreation, potentially
79: * processing the returned result object.
80: * @param result the RemoteInvocationResult to recreate
81: * @return a return value if the invocation result is a successful return
82: * @throws Throwable if the invocation result is an exception
83: * @see RemoteInvocationResult#recreate()
84: */
85: protected Object recreateRemoteInvocationResult(
86: RemoteInvocationResult result) throws Throwable {
87: return result.recreate();
88: }
89:
90: }
|