org.springframework.ejb.support
Class AbstractStatelessSessionBean

java.lang.Object
  extended byorg.springframework.ejb.support.AbstractEnterpriseBean
      extended byorg.springframework.ejb.support.AbstractSessionBean
          extended byorg.springframework.ejb.support.AbstractStatelessSessionBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.io.Serializable, javax.ejb.SessionBean

public abstract class AbstractStatelessSessionBean
extends org.springframework.ejb.support.AbstractSessionBean

Convenient superclass for stateless session beans (SLSBs), minimizing the work involved in implementing an SLSB and preventing common errors. Note that SLSBs are the most useful kind of EJB.

As the ejbActivate() and ejbPassivate() methods cannot be invoked on SLSBs, these methods are implemented to throw an exception and should not be overriden by subclasses. (Unfortunately the EJB specification forbids enforcing this by making EJB lifecycle methods final.)

There should be no need to override the setSessionContext() or ejbCreate() lifecycle methods.

Subclasses are left to implement the onEjbCreate() method to do whatever initialization they wish to do after their BeanFactory has already been loaded, and is available from the getBeanFactory() method.

This class provides the no-argument ejbCreate() method required by the EJB specification, but not the SessionBean interface, eliminating a common cause of EJB deployment failure.

Version:
$Id: AbstractStatelessSessionBean.java,v 1.7 2004/03/18 02:46:14 trisberg Exp $
Author:
Rod Johnson
See Also:
Serialized Form

Field Summary
static java.lang.String BEAN_FACTORY_PATH_ENVIRONMENT_KEY
           
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
AbstractStatelessSessionBean()
           
 
Method Summary
 void ejbActivate()
           
 void ejbCreate()
          This implementation loads the BeanFactory.
 void ejbPassivate()
           
 void ejbRemove()
          EJB lifecycle method, implemented to invoke onEjbRemote and unload the BeanFactory afterwards.
protected  BeanFactory getBeanFactory()
          May be called after ejbCreate().
protected  javax.ejb.SessionContext getSessionContext()
          Convenience method for subclasses.
protected abstract  void onEjbCreate()
          Subclasses must implement this method to do any initialization they would otherwise have done in an ejbCreate() method.
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(java.lang.String factoryKey)
          Set the bean factory locator key.
 void setSessionContext(javax.ejb.SessionContext sessionContext)
          Sets the session context.
 
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
ejbRemove
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

BEAN_FACTORY_PATH_ENVIRONMENT_KEY

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

AbstractStatelessSessionBean

public AbstractStatelessSessionBean()
Method Detail

ejbCreate

public void ejbCreate()
               throws javax.ejb.CreateException
This implementation loads the BeanFactory. A BeansException thrown by loadBeanFactory will simply get propagated, as it is a runtime exception.

Don't override it (although it can't be made final): code your own initialization in onEjbCreate(), which is called when the BeanFactory is available.

Unfortunately we can't load the BeanFactory in setSessionContext(), as resource manager access isn't permitted there - but the BeanFactory may require it.

Throws:
javax.ejb.CreateException

onEjbCreate

protected abstract void onEjbCreate()
                             throws javax.ejb.CreateException
Subclasses must implement this method to do any initialization they would otherwise have done in an ejbCreate() method. In contrast to ejbCreate, the BeanFactory will have been loaded here.

The same restrictions apply to the work of this method as to an ejbCreate() method.

Throws:
javax.ejb.CreateException

ejbActivate

public void ejbActivate()
                 throws javax.ejb.EJBException
Throws:
javax.ejb.EJBException
See Also:
This method always throws an exception, as it should not be invoked by the EJB container.

ejbPassivate

public void ejbPassivate()
                  throws javax.ejb.EJBException
Throws:
javax.ejb.EJBException
See Also:
This method always throws an exception, as it should not be invoked by the EJB container.

setSessionContext

public void setSessionContext(javax.ejb.SessionContext sessionContext)
Sets the session context.

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

Specified by:
setSessionContext in interface javax.ejb.SessionBean
Parameters:
sessionContext - SessionContext context for session

getSessionContext

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

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:
ejbCreate(), AbstractMessageDrivenBean.ejbCreate(), AbstractStatefulSessionBean.loadBeanFactory(), ContextJndiBeanFactoryLocator, JndiBeanFactoryLocator

setBeanFactoryLocatorKey

public void setBeanFactoryLocatorKey(java.lang.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:
AbstractEnterpriseBean.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:
AbstractEnterpriseBean.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.



Copyright (C) 2003-2004 The Spring Framework Project.