KickJava   Java API By Example, From Geeks To Geeks.

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


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 remote SLSB proxies.
28  * If you want control over interceptor chaining, use an AOP ProxyFactoryBean
29  * with SimpleRemoteSlsbInvokerInterceptor rather than rely on this class.</p>
30  *
31  * <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
32  * how to specify the JNDI location of the target EJB.</p>
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  * <p>This proxy factory is typically used with an RMI business interface, which serves
44  * as super-interface of the EJB component interface. Alternatively, this factory
45  * can also proxy a remote SLSB with a matching non-RMI business interface, i.e. an
46  * interface that mirrors the EJB business methods but does not declare RemoteExceptions.
47  * In the latter case, RemoteExceptions thrown by the EJB stub will automatically get
48  * converted to Spring's unchecked RemoteAccessException.</p>
49  *
50  * @author Rod Johnson
51  * @author Colin Sampaleanu
52  * @author Juergen Hoeller
53  * @since 09.05.2003
54  * @see org.springframework.remoting.RemoteAccessException
55  * @see AbstractSlsbInvokerInterceptor#setLookupHomeOnStartup
56  * @see AbstractSlsbInvokerInterceptor#setCacheHome
57  * @see AbstractRemoteSlsbInvokerInterceptor#setRefreshHomeOnConnectFailure
58  */

59 public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSlsbInvokerInterceptor
60     implements FactoryBean, BeanClassLoaderAware {
61
62     /** The business interface of the EJB we're proxying */
63     private Class JavaDoc businessInterface;
64
65     private ClassLoader JavaDoc beanClassLoader = ClassUtils.getDefaultClassLoader();
66
67     /** EJBObject */
68     private Object JavaDoc proxy;
69
70
71     /**
72      * Set the business interface of the EJB we're proxying.
73      * This will normally be a super-interface of the EJB remote component interface.
74      * Using a business methods interface is a best practice when implementing EJBs.
75      * <p>You can also specify a matching non-RMI business interface, i.e. an interface
76      * that mirrors the EJB business methods but does not declare RemoteExceptions.
77      * In this case, RemoteExceptions thrown by the EJB stub will automatically get
78      * converted to Spring's generic RemoteAccessException.
79      * @param businessInterface the business interface of the EJB
80      */

81     public void setBusinessInterface(Class JavaDoc businessInterface) {
82         this.businessInterface = businessInterface;
83     }
84
85     /**
86      * Return the business interface of the EJB we're proxying.
87      */

88     public Class JavaDoc getBusinessInterface() {
89         return this.businessInterface;
90     }
91
92     public void setBeanClassLoader(ClassLoader JavaDoc classLoader) {
93         this.beanClassLoader = classLoader;
94     }
95
96     public void afterPropertiesSet() throws NamingException JavaDoc {
97         super.afterPropertiesSet();
98         if (this.businessInterface == null) {
99             throw new IllegalArgumentException JavaDoc("businessInterface is required");
100         }
101         this.proxy = new ProxyFactory(this.businessInterface, this).getProxy(this.beanClassLoader);
102     }
103
104
105     public Object JavaDoc getObject() {
106         return this.proxy;
107     }
108
109     public Class JavaDoc getObjectType() {
110         return this.businessInterface;
111     }
112
113     public boolean isSingleton() {
114         return true;
115     }
116
117 }
118
Popular Tags