站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

AbstractStatefulSessionBean (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.ejb.support
Class AbstractStatefulSessionBean

java.lang.Object
  extended by org.springframework.ejb.support.AbstractStatefulSessionBean
All Implemented Interfaces:
Serializable, EnterpriseBean, SessionBean, SmartSessionBean

public abstract class AbstractStatefulSessionBean
extends Object

Convenient superclass for stateful session beans. SFSBs should extend this class, leaving them to implement the ejbActivate() and ejbPassivate() lifecycle methods to comply with the requirements of the EJB specification.

Note: Subclasses should invoke the loadBeanFactory() method in their custom ejbCreate() and ejbActivate() methods, and should invoke the unloadBeanFactory() method in their ejbPassivate method.

Note: The default BeanFactoryLocator used by this class's superclass (ContextJndiBeanFactoryLocator) is not serializable. Therefore, when using the default BeanFactoryLocator, or another variant which is not serializable, subclasses must call setBeanFactoryLocator(null) in ejbPassivate(), with a corresponding call to setBeanFactoryLocator(xxx) in ejbActivate() unless relying on the default locator.

Author:
Rod Johnson, Colin Sampaleanu
See Also:
ContextJndiBeanFactoryLocator, Serialized Form

Field Summary
static String BEAN_FACTORY_PATH_ENVIRONMENT_KEY
           
 
Constructor Summary
AbstractStatefulSessionBean()
           
 
Method Summary
 void ejbRemove()
          EJB lifecycle method, implemented to invoke onEjbRemote and unload the BeanFactory afterwards.
protected  BeanFactory getBeanFactory()
          May be called after ejbCreate().
 SessionContext getSessionContext()
          Convenience method for subclasses.
protected  void loadBeanFactory()
          Load a Spring BeanFactory namespace.
protected  void onEjbRemove()
          Subclasses must implement this method to do any initialization they would otherwise have done in an ejbRemove() method.
 void setBeanFactoryLocator(BeanFactoryLocator beanFactoryLocator)
          Set the BeanFactoryLocator to use for this EJB.
 void setBeanFactoryLocatorKey(String factoryKey)
          Set the bean factory locator key.
 void setSessionContext(SessionContext sessionContext)
          Set the session context.
protected  void unloadBeanFactory()
          Unload the Spring BeanFactory instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ejb.SessionBean
ejbActivate, ejbPassivate, ejbRemove
 

Field Detail

BEAN_FACTORY_PATH_ENVIRONMENT_KEY

public static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY
See Also:
Constant Field Values
Constructor Detail

AbstractStatefulSessionBean

public AbstractStatefulSessionBean()
Method Detail

loadBeanFactory

protected void loadBeanFactory()
                        throws BeansException
Load a Spring BeanFactory namespace. Exposed for subclasses to load a BeanFactory in their ejbCreate() methods. Those callers would normally want to catch BeansException and rethrow it as CreateException. Unless the BeanFactory is known to be serializable, this method must also be called from ejbActivate(), to reload a context removed via a call to unloadBeanFactory() from the ejbPassivate() implementation.

Throws:
BeansException
See Also:
AbstractStatelessSessionBean.ejbCreate()

unloadBeanFactory

protected void unloadBeanFactory()
                          throws FatalBeanException
Unload the Spring BeanFactory instance. The default ejbRemove method invokes this method, but subclasses which override ejbRemove must invoke this method themselves.

Unless the BeanFactory is known to be serializable, this method must also be called from ejbPassivate(), with a corresponding call to loadBeanFactory() from ejbActivate().

Throws:
FatalBeanException

setSessionContext

public void setSessionContext(SessionContext sessionContext)
Set the session context.

If overriding this method, be sure to invoke this form of it first.

Specified by:
setSessionContext in interface SessionBean
Parameters:
sessionContext - the SessionContext for this EJB

getSessionContext

public final SessionContext getSessionContext()
Convenience method for subclasses. Return the EJB context saved on initialization.

Specified by:
getSessionContext in interface SmartSessionBean
Returns:
the SessionContext saved on initialization by this class's implementation of the setSessionContext method

setBeanFactoryLocator

public void setBeanFactoryLocator(BeanFactoryLocator beanFactoryLocator)
Set the BeanFactoryLocator to use for this EJB. Default is a ContextJndiBeanFactoryLocator.

Can be invoked before loadBeanFactory, for example in constructor or setSessionContext if you want to override the default locator.

Note that the BeanFactory is automatically loaded by the ejbCreate implementations of AbstractStatelessSessionBean and AbstractMessageDriverBean but needs to be explicitly loaded in custom AbstractStatefulSessionBean ejbCreate methods.

See Also:
AbstractStatelessSessionBean.ejbCreate(), AbstractMessageDrivenBean.ejbCreate(), loadBeanFactory(), ContextJndiBeanFactoryLocator

setBeanFactoryLocatorKey

public void setBeanFactoryLocatorKey(String factoryKey)
Set the bean factory locator key.

In case of the default BeanFactoryLocator implementation, ContextJndiBeanFactoryLocator, this is the JNDI path. The default value of this property is "java:comp/env/ejb/BeanFactoryPath".

Can be invoked before loadBeanFactory, for example in constructor or setSessionContext if you want to override the default locator key.

See Also:
BEAN_FACTORY_PATH_ENVIRONMENT_KEY

getBeanFactory

protected BeanFactory getBeanFactory()
May be called after ejbCreate().

Returns:
the bean factory

ejbRemove

public void ejbRemove()
EJB lifecycle method, implemented to invoke onEjbRemote and unload the BeanFactory afterwards.

Don't override it (although it can't be made final): code your shutdown in onEjbRemove.

See Also:
onEjbRemove()

onEjbRemove

protected void onEjbRemove()
Subclasses must implement this method to do any initialization they would otherwise have done in an ejbRemove() method. The BeanFactory will be unloaded afterwards.

This implementation is empty, to be overridden in subclasses. The same restrictions apply to the work of this method as to an ejbRemove() method.


The Spring Framework

Copyright © 2002-2007 The Spring Framework.