1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. package org.springframework.ejb.support;
  17. import org.springframework.beans.BeansException;
  18. import org.springframework.beans.FatalBeanException;
  19. /**
  20. * Convenient superclass for stateful session beans.
  21. * SFSBs should extend this class, leaving them to implement the
  22. * ejbActivate() and ejbPassivate() lifecycle methods to comply
  23. * with the requirements of the EJB specification.
  24. *
  25. * <p><b>Note: Subclasses should invoke the loadBeanFactory() method in
  26. * their custom ejbCreate and ejbActivate methods, and should invoke
  27. * the unloadBeanFactory() method in their ejbPassivate method.</b>
  28. *
  29. * <p><b>Note: The default BeanFactoryLocator used by this class's superclass
  30. * (ContextJndiBeanFactoryLocator) is <b>not</b> serializable. Therefore,
  31. * when using the default BeanFactoryLocator, or another variant which is
  32. * not serializable, subclasses must call setBeanFactoryLocator(null) in
  33. * ejbPassivate, with a corresponding call to setBeanFactoryLocator(xxx)
  34. * in ejbActivate unless relying on the default locator.
  35. *
  36. * @version $Id: AbstractStatefulSessionBean.java,v 1.9 2004/03/18 19:17:53 jhoeller Exp $
  37. * @author Rod Johnson
  38. * @author Colin Sampaleanu
  39. * @see org.springframework.context.access.ContextJndiBeanFactoryLocator
  40. */
  41. public abstract class AbstractStatefulSessionBean extends AbstractSessionBean {
  42. /**
  43. * Load a Spring BeanFactory namespace. Exposed for subclasses
  44. * to load a BeanFactory in their ejbCreate() methods. Those
  45. * callers would normally want to catch BeansException and
  46. * rethrow it as {@link javax.ejb.CreateException}. Unless
  47. * the BeanFactory is known to be serializable, this method
  48. * must also be called from ejbActivate(), to reload a context
  49. * removed via a call to unloadBeanFactory from ejbPassivate.
  50. */
  51. protected void loadBeanFactory() throws BeansException {
  52. super.loadBeanFactory();
  53. }
  54. /**
  55. * Unload the Spring BeanFactory instance.
  56. * The default ejbRemove method invokes this method, but subclasses
  57. * which override ejbRemove must invoke this method themselves.
  58. * Unless the BeanFactory is known to be serializable, this method
  59. * must also be called from ejbPassivate, with a corresponding call
  60. * to loadBeanFactory from ejbActivate.
  61. */
  62. protected void unloadBeanFactory() throws FatalBeanException {
  63. super.unloadBeanFactory();
  64. }
  65. }