org.springframework.ejb.support
Class AbstractMessageDrivenBean

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

public abstract class AbstractMessageDrivenBean
extends AbstractEnterpriseBean
implements MessageDrivenBean

Convenient base class for EJB 2.x 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-arg ejbCreate() method as required by the EJB specification. This ejbCreate() method loads a BeanFactory, before invoking the onEjbCreate() method, which is supposed to 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.

Author:
Rod Johnson
See Also:
Serialized Form

Field Summary
protected  Log logger
          Logger available to subclasses
 
Fields inherited from class org.springframework.ejb.support.AbstractEnterpriseBean
BEAN_FACTORY_PATH_ENVIRONMENT_KEY
 
Constructor Summary
AbstractMessageDrivenBean()
           
 
Method Summary
 void ejbCreate()
          Lifecycle method required by the EJB specification but not the MessageDrivenBean interface.
protected  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.
 void setMessageDrivenContext(MessageDrivenContext messageDrivenContext)
          Required lifecycle method.
 
Methods inherited from class org.springframework.ejb.support.AbstractEnterpriseBean
ejbRemove, getBeanFactory, onEjbRemove, setBeanFactoryLocator, setBeanFactoryLocatorKey
 
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 Log logger
Logger available to subclasses

Constructor Detail

AbstractMessageDrivenBean

public AbstractMessageDrivenBean()
Method Detail

setMessageDrivenContext

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

Specified by:
setMessageDrivenContext in interface MessageDrivenBean
Parameters:
messageDrivenContext - MessageDrivenContext

getMessageDrivenContext

protected final 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.