KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > jaxrpc > JaxRpcPortProxyFactoryBean


1 /*
2  * Copyright 2002-2007 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.jaxrpc;
18
19 import javax.xml.rpc.ServiceException JavaDoc;
20
21 import org.springframework.aop.framework.ProxyFactory;
22 import org.springframework.beans.factory.BeanClassLoaderAware;
23 import org.springframework.beans.factory.FactoryBean;
24 import org.springframework.util.ClassUtils;
25
26 /**
27  * FactoryBean for a specific port of a JAX-RPC service.
28  * Exposes a proxy for the port, to be used for bean references.
29  * Inherits configuration properties from {@link JaxRpcPortClientInterceptor}.
30  *
31  * <p>This factory is typically used with an RMI service interface. Alternatively,
32  * this factory can also proxy a JAX-RPC service with a matching non-RMI business
33  * interface, i.e. an interface that mirrors the RMI service methods but does not
34  * declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the
35  * JAX-RPC stub will automatically get converted to Spring's unchecked
36  * RemoteAccessException.
37  *
38  * <p>If exposing the JAX-RPC port interface (i.e. an RMI interface) directly,
39  * setting "serviceInterface" is sufficient. If exposing a non-RMI business
40  * interface, the business interface needs to be set as "serviceInterface",
41  * and the JAX-RPC port interface as "portInterface".
42  *
43  * @author Juergen Hoeller
44  * @since 15.12.2003
45  * @see #setServiceInterface
46  * @see #setPortInterface
47  * @see LocalJaxRpcServiceFactoryBean
48  */

49 public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor
50         implements FactoryBean, BeanClassLoaderAware {
51
52     private ClassLoader JavaDoc beanClassLoader = ClassUtils.getDefaultClassLoader();
53
54     private Object JavaDoc serviceProxy;
55
56
57     public void setBeanClassLoader(ClassLoader JavaDoc classLoader) {
58         this.beanClassLoader = classLoader;
59     }
60
61     public void afterPropertiesSet() throws ServiceException JavaDoc {
62         if (getServiceInterface() == null) {
63             // Use JAX-RPC port interface (a traditional RMI interface)
64
// as service interface if none explicitly specified.
65
if (getPortInterface() != null) {
66                 setServiceInterface(getPortInterface());
67             }
68             else {
69                 throw new IllegalArgumentException JavaDoc("Property 'serviceInterface' is required");
70             }
71         }
72         super.afterPropertiesSet();
73         this.serviceProxy = new ProxyFactory(getServiceInterface(), this).getProxy(this.beanClassLoader);
74     }
75
76
77     public Object JavaDoc getObject() {
78         return this.serviceProxy;
79     }
80
81     public Class JavaDoc getObjectType() {
82         return getServiceInterface();
83     }
84
85     public boolean isSingleton() {
86         return true;
87     }
88
89 }
90
Popular Tags