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.jaxrpc;
18:
19: import org.springframework.aop.framework.ProxyFactory;
20: import org.springframework.beans.factory.BeanClassLoaderAware;
21: import org.springframework.beans.factory.FactoryBean;
22: import org.springframework.util.ClassUtils;
23:
24: /**
25: * {@link org.springframework.beans.factory.FactoryBean} for a specific port of a
26: * JAX-RPC service. Exposes a proxy for the port, to be used for bean references.
27: * Inherits configuration properties from {@link JaxRpcPortClientInterceptor}.
28: *
29: * <p>This factory is typically used with an RMI service interface. Alternatively,
30: * this factory can also proxy a JAX-RPC service with a matching non-RMI business
31: * interface, i.e. an interface that mirrors the RMI service methods but does not
32: * declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the
33: * JAX-RPC stub will automatically get converted to Spring's unchecked
34: * RemoteAccessException.
35: *
36: * <p>If exposing the JAX-RPC port interface (i.e. an RMI interface) directly,
37: * setting "serviceInterface" is sufficient. If exposing a non-RMI business
38: * interface, the business interface needs to be set as "serviceInterface",
39: * and the JAX-RPC port interface as "portInterface".
40: *
41: * @author Juergen Hoeller
42: * @since 15.12.2003
43: * @see #setServiceInterface
44: * @see #setPortInterface
45: * @see LocalJaxRpcServiceFactoryBean
46: */
47: public class JaxRpcPortProxyFactoryBean extends
48: JaxRpcPortClientInterceptor implements FactoryBean,
49: BeanClassLoaderAware {
50:
51: private ClassLoader beanClassLoader = ClassUtils
52: .getDefaultClassLoader();
53:
54: private Object serviceProxy;
55:
56: public void setBeanClassLoader(ClassLoader classLoader) {
57: this .beanClassLoader = classLoader;
58: }
59:
60: public void afterPropertiesSet() {
61: if (getServiceInterface() == null) {
62: // Use JAX-RPC port interface (a traditional RMI interface)
63: // as service interface if none explicitly specified.
64: if (getPortInterface() != null) {
65: setServiceInterface(getPortInterface());
66: } else {
67: throw new IllegalArgumentException(
68: "Property 'serviceInterface' is required");
69: }
70: }
71: super .afterPropertiesSet();
72: this .serviceProxy = new ProxyFactory(getServiceInterface(),
73: this ).getProxy(this .beanClassLoader);
74: }
75:
76: public Object getObject() {
77: return this .serviceProxy;
78: }
79:
80: public Class getObjectType() {
81: return getServiceInterface();
82: }
83:
84: public boolean isSingleton() {
85: return true;
86: }
87:
88: }
|