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.ejb.support;
18:
19: import org.springframework.beans.BeansException;
20: import org.springframework.beans.FatalBeanException;
21:
22: /**
23: * Convenient superclass for stateful session beans.
24: * SFSBs should extend this class, leaving them to implement the
25: * <code>ejbActivate()</code> and <code>ejbPassivate()</code> lifecycle
26: * methods to comply with the requirements of the EJB specification.
27: *
28: * <p><b>Note: Subclasses should invoke the <code>loadBeanFactory()</code>
29: * method in their custom <code>ejbCreate()</code> and <code>ejbActivate()</code>
30: * methods, and should invoke the <code>unloadBeanFactory()</code> method in
31: * their <code>ejbPassivate</code> method.</b>
32: *
33: * <p><b>Note: The default BeanFactoryLocator used by this class's superclass
34: * (ContextJndiBeanFactoryLocator) is <b>not</b> serializable. Therefore,
35: * when using the default BeanFactoryLocator, or another variant which is
36: * not serializable, subclasses must call <code>setBeanFactoryLocator(null)</code>
37: * in <code>ejbPassivate()</code>, with a corresponding call to
38: * <code>setBeanFactoryLocator(xxx)</code> in <code>ejbActivate()</code>
39: * unless relying on the default locator.
40: *
41: * @author Rod Johnson
42: * @author Colin Sampaleanu
43: * @see org.springframework.context.access.ContextJndiBeanFactoryLocator
44: */
45: public abstract class AbstractStatefulSessionBean extends
46: AbstractSessionBean {
47:
48: /**
49: * Load a Spring BeanFactory namespace. Exposed for subclasses
50: * to load a BeanFactory in their <code>ejbCreate()</code> methods.
51: * Those callers would normally want to catch BeansException and
52: * rethrow it as {@link javax.ejb.CreateException}. Unless the
53: * BeanFactory is known to be serializable, this method must also
54: * be called from <code>ejbActivate()</code>, to reload a context
55: * removed via a call to <code>unloadBeanFactory()</code> from
56: * the <code>ejbPassivate()</code> implementation.
57: */
58: protected void loadBeanFactory() throws BeansException {
59: super .loadBeanFactory();
60: }
61:
62: /**
63: * Unload the Spring BeanFactory instance. The default <code>ejbRemove</code>
64: * method invokes this method, but subclasses which override
65: * <code>ejbRemove</code> must invoke this method themselves.
66: * <p>Unless the BeanFactory is known to be serializable, this method
67: * must also be called from <code>ejbPassivate()</code>, with a corresponding
68: * call to <code>loadBeanFactory()</code> from <code>ejbActivate()</code>.
69: */
70: protected void unloadBeanFactory() throws FatalBeanException {
71: super.unloadBeanFactory();
72: }
73:
74: }
|