KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > remoting > JmsInvokerProxyFactoryBean


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.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 proxies. Exposes the proxied service for use
26  * as a bean reference, using the specified service interface.
27  *
28  * <p>For configuration details, see the
29  * {@link JmsInvokerClientInterceptor} javadoc.
30  *
31  * @author Juergen Hoeller
32  * @since 2.0
33  * @see #setConnectionFactory
34  * @see #setQueueName
35  * @see #setServiceInterface
36  * @see org.springframework.jms.remoting.JmsInvokerClientInterceptor
37  * @see org.springframework.jms.remoting.JmsInvokerServiceExporter
38  */

39 public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor
40         implements FactoryBean, BeanClassLoaderAware {
41
42     private Class JavaDoc serviceInterface;
43
44     private ClassLoader JavaDoc beanClassLoader = ClassUtils.getDefaultClassLoader();
45
46     private Object JavaDoc serviceProxy;
47
48
49     /**
50      * Set the interface that the proxy must implement.
51      * @param serviceInterface the interface that the proxy must implement
52      * @throws IllegalArgumentException if the supplied <code>serviceInterface</code>
53      * is <code>null</code>, or if the supplied <code>serviceInterface</code>
54      * is not an interface type
55      */

56     public void setServiceInterface(Class JavaDoc serviceInterface) {
57         if (serviceInterface == null || !serviceInterface.isInterface()) {
58             throw new IllegalArgumentException JavaDoc("'serviceInterface' must be an interface");
59         }
60         this.serviceInterface = serviceInterface;
61     }
62
63     public void setBeanClassLoader(ClassLoader JavaDoc classLoader) {
64         this.beanClassLoader = classLoader;
65     }
66
67     public void afterPropertiesSet() {
68         super.afterPropertiesSet();
69         if (this.serviceInterface == null) {
70             throw new IllegalArgumentException JavaDoc("Property 'serviceInterface' is required");
71         }
72         this.serviceProxy = new ProxyFactory(this.serviceInterface, this).getProxy(this.beanClassLoader);
73     }
74
75
76     public Object JavaDoc getObject() {
77         return this.serviceProxy;
78     }
79
80     public Class JavaDoc getObjectType() {
81         return this.serviceInterface;
82     }
83
84     public boolean isSingleton() {
85         return true;
86     }
87
88 }
89
Popular Tags