01: /*
02: * Copyright 2002-2005 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.rmi;
18:
19: import java.lang.reflect.InvocationTargetException;
20: import java.rmi.Remote;
21:
22: import org.springframework.remoting.support.RemoteInvocation;
23: import org.springframework.remoting.support.RemoteInvocationBasedExporter;
24:
25: /**
26: * Convenient superclass for RMI-based remote exporters. Provides a facility
27: * to automatically wrap a given plain Java service object with am
28: * RmiInvocationWrapper, exposing the RmiInvocationHandler interface.
29: *
30: * <p>With an RMI invoker, RMI communication works on the RmiInvocationHandler
31: * level, needing only one stub for any service. Service interfaces do not have to
32: * extend <code>java.rmi.Remote</code> or throw <code>java.rmi.RemoteException</code>
33: * on all methods, but in and out parameters have to be serializable.
34: *
35: * @author Juergen Hoeller
36: * @since 1.2.5
37: * @see RmiServiceExporter
38: * @see JndiRmiServiceExporter
39: */
40: public abstract class RmiBasedExporter extends
41: RemoteInvocationBasedExporter {
42:
43: /**
44: * Determine the object to export: either the service object itself
45: * or a RmiInvocationWrapper in case of a non-RMI service object.
46: * @return the RMI object to export
47: * @see #setService
48: * @see #setServiceInterface
49: */
50: protected Remote getObjectToExport() {
51: // determine remote object
52: if (getService() instanceof Remote
53: && ((getServiceInterface() == null) || Remote.class
54: .isAssignableFrom(getServiceInterface()))) {
55: // conventional RMI service
56: return (Remote) getService();
57: } else {
58: // RMI invoker
59: if (logger.isDebugEnabled()) {
60: logger.debug("RMI service [" + getService()
61: + "] is an RMI invoker");
62: }
63: return new RmiInvocationWrapper(getProxyForService(), this );
64: }
65: }
66:
67: /**
68: * Redefined here to be visible to RmiInvocationWrapper.
69: * Simply delegates to the corresponding superclass method.
70: */
71: protected Object invoke(RemoteInvocation invocation,
72: Object targetObject) throws NoSuchMethodException,
73: IllegalAccessException, InvocationTargetException {
74:
75: return super.invoke(invocation, targetObject);
76: }
77:
78: }
|