KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > ejb > access > LocalStatelessSessionProxyFactoryBean


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.ejb.access;
18
19 import javax.naming.NamingException 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  * <p>Convenient factory for local Stateless Session Bean (SLSB) proxies.
28  * If you want control over interceptor chaining, use an AOP ProxyFactoryBean
29  * with LocalSlsbInvokerInterceptor rather than rely on this class.
30  *
31  * <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
32  * how to specify the JNDI location of the target EJB.
33  *
34  * <p>In a bean container, this class is normally best used as a singleton. However,
35  * if that bean container pre-instantiates singletons (as do the XML ApplicationContext
36  * variants) you may have a problem if the bean container is loaded before the EJB
37  * container loads the target EJB. That is because by default the JNDI lookup will be
38  * performed in the init method of this class and cached, but the EJB will not have been
39  * bound at the target location yet. The best solution is to set the lookupHomeOnStartup
40  * property to false, in which case the home will be fetched on first access to the EJB.
41  * (This flag is only true by default for backwards compatibility reasons).</p>
42  *
43  * @author Rod Johnson
44  * @author Colin Sampaleanu
45  * @since 09.05.2003
46  * @see AbstractSlsbInvokerInterceptor#setLookupHomeOnStartup
47  * @see AbstractSlsbInvokerInterceptor#setCacheHome
48  */

49 public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInterceptor
50         implements FactoryBean, BeanClassLoaderAware {
51
52     /** The business interface of the EJB we're proxying */
53     private Class JavaDoc businessInterface;
54
55     private ClassLoader JavaDoc beanClassLoader = ClassUtils.getDefaultClassLoader();
56
57     /** EJBLocalObject */
58     private Object JavaDoc proxy;
59
60
61     /**
62      * Set the business interface of the EJB we're proxying.
63      * This will normally be a super-interface of the EJB local component interface.
64      * Using a business methods interface is a best practice when implementing EJBs.
65      * @param businessInterface set the business interface of the EJB
66      */

67     public void setBusinessInterface(Class JavaDoc businessInterface) {
68         this.businessInterface = businessInterface;
69     }
70
71     /**
72      * Return the business interface of the EJB we're proxying.
73      */

74     public Class JavaDoc getBusinessInterface() {
75         return this.businessInterface;
76     }
77
78     public void setBeanClassLoader(ClassLoader JavaDoc classLoader) {
79         this.beanClassLoader = classLoader;
80     }
81
82     public void afterPropertiesSet() throws NamingException JavaDoc {
83         super.afterPropertiesSet();
84         if (this.businessInterface == null) {
85             throw new IllegalArgumentException JavaDoc("businessInterface is required");
86         }
87         this.proxy = new ProxyFactory(this.businessInterface, this).getProxy(this.beanClassLoader);
88     }
89
90
91     public Object JavaDoc getObject() {
92         return this.proxy;
93     }
94
95     public Class JavaDoc getObjectType() {
96         return this.businessInterface;
97     }
98
99     public boolean isSingleton() {
100         return true;
101     }
102
103 }
104
Popular Tags