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.jms.remoting;
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: * FactoryBean for JMS invoker proxies. Exposes the proxied service for use
26: * as a bean reference, using the specified service interface.
27: *
28: * <p>Serializes remote invocation objects and deserializes remote invocation
29: * result objects. Uses Java serialization just like RMI, but with the JMS
30: * provider as communication infrastructure.
31: *
32: * <p>To be configured with a {@link javax.jms.QueueConnectionFactory} and a
33: * target queue (either as {@link javax.jms.Queue} reference or as queue name).
34: *
35: * @author Juergen Hoeller
36: * @since 2.0
37: * @see #setConnectionFactory
38: * @see #setQueueName
39: * @see #setServiceInterface
40: * @see org.springframework.jms.remoting.JmsInvokerClientInterceptor
41: * @see org.springframework.jms.remoting.JmsInvokerServiceExporter
42: */
43: public class JmsInvokerProxyFactoryBean extends
44: JmsInvokerClientInterceptor implements FactoryBean,
45: BeanClassLoaderAware {
46:
47: private Class serviceInterface;
48:
49: private ClassLoader beanClassLoader = ClassUtils
50: .getDefaultClassLoader();
51:
52: private Object serviceProxy;
53:
54: /**
55: * Set the interface that the proxy must implement.
56: * @param serviceInterface the interface that the proxy must implement
57: * @throws IllegalArgumentException if the supplied <code>serviceInterface</code>
58: * is <code>null</code>, or if the supplied <code>serviceInterface</code>
59: * is not an interface type
60: */
61: public void setServiceInterface(Class serviceInterface) {
62: if (serviceInterface == null || !serviceInterface.isInterface()) {
63: throw new IllegalArgumentException(
64: "'serviceInterface' must be an interface");
65: }
66: this .serviceInterface = serviceInterface;
67: }
68:
69: public void setBeanClassLoader(ClassLoader classLoader) {
70: this .beanClassLoader = classLoader;
71: }
72:
73: public void afterPropertiesSet() {
74: super .afterPropertiesSet();
75: if (this .serviceInterface == null) {
76: throw new IllegalArgumentException(
77: "Property 'serviceInterface' is required");
78: }
79: this .serviceProxy = new ProxyFactory(this .serviceInterface,
80: this ).getProxy(this .beanClassLoader);
81: }
82:
83: public Object getObject() {
84: return this .serviceProxy;
85: }
86:
87: public Class getObjectType() {
88: return this .serviceInterface;
89: }
90:
91: public boolean isSingleton() {
92: return true;
93: }
94:
95: }
|