org.springframework.ejb.support
Class AbstractMessageDrivenBean

java.lang.Object
  extended byorg.springframework.ejb.support.AbstractEnterpriseBean
      extended byorg.springframework.ejb.support.AbstractMessageDrivenBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.MessageDrivenBean, java.io.Serializable
Direct Known Subclasses:
AbstractJmsMessageDrivenBean

public abstract class AbstractMessageDrivenBean
extends org.springframework.ejb.support.AbstractEnterpriseBean
implements javax.ejb.MessageDrivenBean

Convenient superclass for MDBs. Doesn't require JMS, as EJB 2.1 MDBs are no longer JMS-specific: see the AbstractJmsMessageDrivenBean subclass.

This class ensures that subclasses have access to the MessageDrivenContext provided by the EJB container, and implement a no argument ejbCreate() method as required by the EJB specification. This ejbCreate() method loads a BeanFactory, before invoking the onEjbCreate() method, which should contain subclass-specific initialization.

NB: We cannot use final methods to implement EJB API methods, as this violates the EJB specification. However, there should be no need to override the setMessageDrivenContext() or ejbCreate() methods.

Version:
$Id: AbstractMessageDrivenBean.java,v 1.5 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
AbstractMessageDrivenBean()
           
 
Method Summary
 void ejbCreate()
          Lifecycle method required by the EJB specification but not the MessageDrivenBean interface.
 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.MessageDrivenContext getMessageDrivenContext()
          Convenience method for subclasses to use.
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 setMessageDrivenContext(javax.ejb.MessageDrivenContext messageDrivenContext)
          Required lifecycle method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ejb.MessageDrivenBean
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

AbstractMessageDrivenBean

public AbstractMessageDrivenBean()
Method Detail

setMessageDrivenContext

public void setMessageDrivenContext(javax.ejb.MessageDrivenContext messageDrivenContext)
Required lifecycle method. Sets the MessageDriven context.

Specified by:
setMessageDrivenContext in interface javax.ejb.MessageDrivenBean
Parameters:
messageDrivenContext - MessageDrivenContext

getMessageDrivenContext

protected final javax.ejb.MessageDrivenContext getMessageDrivenContext()
Convenience method for subclasses to use.

Returns:
the MessageDrivenContext passed to this EJB by the EJB container

ejbCreate

public void ejbCreate()
Lifecycle method required by the EJB specification but not the MessageDrivenBean interface. This implementation loads the BeanFactory.

Don't override it (although it can't be made final): code 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 and the BeanFactory may require it.


onEjbCreate

protected abstract void onEjbCreate()
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.


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(), 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.