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