JStatefulFactory.java

00001 
00026 package org.objectweb.jonas_ejb.container;
00027 
00028 import java.rmi.RemoteException;
00029 
00030 import javax.ejb.EJBException;
00031 import javax.ejb.SessionBean;
00032 import javax.ejb.TimerService;
00033 
00034 import org.objectweb.jonas_ejb.deployment.api.SessionDesc;
00035 import org.objectweb.jonas_ejb.deployment.api.SessionStatefulDesc;
00036 import org.objectweb.jonas_ejb.lib.EJBInvocation;
00037 
00038 import org.objectweb.util.monolog.api.BasicLevel;
00039 
00044 public class JStatefulFactory extends JSessionFactory {
00045 
00046     JStatefulPool statefulPool;
00047 
00054     public JStatefulFactory(SessionStatefulDesc dd, JContainer cont, JStatefulPool sfp) {
00055         super((SessionDesc) dd, cont);
00056         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00057         isSynchro = javax.ejb.SessionSynchronization.class.isAssignableFrom(beanclass);
00058         isStateful = true;
00059         statefulPool = sfp;
00060     }
00061 
00062     // ---------------------------------------------------------------
00063     // BeanFactory implementation
00064     // ---------------------------------------------------------------
00065 
00069     public int getPoolSize() {
00070         return 0; // TODO
00071     }
00072 
00076     public void reduceCache() {
00077     }
00078 
00082     public void initInstancePool() {
00083     }
00084     
00085     // ---------------------------------------------------------------
00086     // preInvoke / postInvoke
00087     // ---------------------------------------------------------------
00088 
00095     public RequestCtx preInvoke(int txa) {
00096         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00097         RequestCtx rctx = super.preInvoke(txa);
00098         return rctx;
00099     }
00100 
00106      public void checkSecurity(EJBInvocation ejbInv) {
00107          TraceEjb.interp.log(BasicLevel.DEBUG, "");
00108          super.checkSecurity(ejbInv);
00109      }
00110 
00116     public void postInvoke(RequestCtx rctx) {
00117         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00118         super.postInvoke(rctx);
00119     }
00120 
00121     // ---------------------------------------------------------------
00122     // other public methods
00123     // ---------------------------------------------------------------
00124 
00129     public TimerService getTimerService() {
00130         throw new EJBException("No TimerService for Stateful Session beans");
00131     }
00132 
00137     public JSessionSwitch createNewSession() throws RemoteException {
00138         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00139         JStatefulSwitch bs = new JStatefulSwitch(this, statefulPool);
00140         return bs;
00141     }
00142 
00148     public JSessionContext getJContext(JSessionSwitch ss) {
00149         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00150         JStatefulContext bctx = null;
00151         try {
00152             bctx = createNewInstance(ss);
00153         } catch (Exception e) {
00154             throw new EJBException("Cannot create a new instance " + e);
00155         }
00156         return bctx;
00157     }
00158 
00159     // ---------------------------------------------------------------
00160     // private methods
00161     // ---------------------------------------------------------------
00162 
00166     private JStatefulContext createNewInstance(JSessionSwitch ss) throws Exception {
00167         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00168         // create the bean instance
00169         SessionBean bean = null;
00170         try {
00171             bean = (SessionBean) beanclass.newInstance();
00172         } catch (InstantiationException e) {
00173             TraceEjb.logger.log(BasicLevel.ERROR, ejbname + " cannot instantiate session bean");
00174             throw e;
00175         } catch (IllegalAccessException e) {
00176             TraceEjb.logger.log(BasicLevel.ERROR, ejbname + " cannot instantiate session bean");
00177             throw e;
00178         }
00179         // create a new StatefulContext and bind it to the instance
00180         JStatefulContext bctx = new JStatefulContext(this, bean, isSynchro);
00181         bean.setSessionContext(bctx);
00182         bctx.setState(1);
00183         return bctx;
00184     }
00185 
00186 }

Generated on Tue Feb 15 15:05:42 2005 for JOnAS by  doxygen 1.3.9.1