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.rmi;
18:
19: import java.lang.reflect.InvocationTargetException;
20: import java.rmi.RemoteException;
21:
22: import org.springframework.remoting.support.RemoteInvocation;
23: import org.springframework.util.Assert;
24:
25: /**
26: * Server-side implementation of {@link RmiInvocationHandler}. An instance
27: * of this class exists for each remote object. Automatically created
28: * by {@link RmiServiceExporter} for non-RMI service implementations.
29: *
30: * <p>This is an SPI class, not to be used directly by applications.
31: *
32: * @author Juergen Hoeller
33: * @since 14.05.2003
34: * @see RmiServiceExporter
35: */
36: class RmiInvocationWrapper implements RmiInvocationHandler {
37:
38: private final Object wrappedObject;
39:
40: private final RmiBasedExporter rmiExporter;
41:
42: /**
43: * Create a new RmiInvocationWrapper for the given object
44: * @param wrappedObject the object to wrap with an RmiInvocationHandler
45: * @param rmiExporter the RMI exporter to handle the actual invocation
46: */
47: public RmiInvocationWrapper(Object wrappedObject,
48: RmiBasedExporter rmiExporter) {
49: Assert.notNull(wrappedObject, "Object to wrap is required");
50: Assert.notNull(rmiExporter, "RMI exporter is required");
51: this .wrappedObject = wrappedObject;
52: this .rmiExporter = rmiExporter;
53: }
54:
55: /**
56: * Exposes the exporter's service interface, if any, as target interface.
57: * @see RmiBasedExporter#getServiceInterface()
58: */
59: public String getTargetInterfaceName() {
60: Class ifc = this .rmiExporter.getServiceInterface();
61: return (ifc != null ? ifc.getName() : null);
62: }
63:
64: /**
65: * Delegates the actual invocation handling to the RMI exporter.
66: * @see RmiBasedExporter#invoke(org.springframework.remoting.support.RemoteInvocation, Object)
67: */
68: public Object invoke(RemoteInvocation invocation)
69: throws RemoteException, NoSuchMethodException,
70: IllegalAccessException, InvocationTargetException {
71:
72: return this.rmiExporter.invoke(invocation, this.wrappedObject);
73: }
74:
75: }
|