KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > rmi > RmiBasedExporter


1 /*
2  * Copyright 2002-2005 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.rmi;
18
19 import java.lang.reflect.InvocationTargetException JavaDoc;
20 import java.rmi.Remote JavaDoc;
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 RemoteInvocationBasedExporter {
41
42     /**
43      * Determine the object to export: either the service object itself
44      * or a RmiInvocationWrapper in case of a non-RMI service object.
45      * @return the RMI object to export
46      * @see #setService
47      * @see #setServiceInterface
48      */

49     protected Remote JavaDoc getObjectToExport() {
50         // determine remote object
51
if (getService() instanceof Remote JavaDoc &&
52                 ((getServiceInterface() == null) || Remote JavaDoc.class.isAssignableFrom(getServiceInterface()))) {
53             // conventional RMI service
54
return (Remote JavaDoc) getService();
55         }
56         else {
57             // RMI invoker
58
if (logger.isDebugEnabled()) {
59                 logger.debug("RMI service [" + getService() + "] is an RMI invoker");
60             }
61             return new RmiInvocationWrapper(getProxyForService(), this);
62         }
63     }
64
65     /**
66      * Redefined here to be visible to RmiInvocationWrapper.
67      * Simply delegates to the corresponding superclass method.
68      */

69     protected Object JavaDoc invoke(RemoteInvocation invocation, Object JavaDoc targetObject)
70             throws NoSuchMethodException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
71
72         return super.invoke(invocation, targetObject);
73     }
74
75 }
76
Popular Tags