00001 00026 package org.objectweb.jonas_ejb.container; 00027 00028 import javax.ejb.EJBException; 00029 import javax.ejb.EJBLocalHome; 00030 import javax.ejb.EJBLocalObject; 00031 import javax.ejb.RemoveException; 00032 00033 import org.objectweb.jonas_ejb.lib.EJBInvocation; 00034 00035 import org.objectweb.util.monolog.api.BasicLevel; 00036 00041 public abstract class JSessionLocal extends JLocal { 00042 00043 protected JSessionFactory bf; 00044 00045 protected JSessionSwitch bs; 00046 00051 public JSessionLocal(JSessionFactory bf) { 00052 super(bf); 00053 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00054 this.bf = bf; 00055 } 00056 00057 // -------------------------------------------------------------------------- 00058 // EJBLocalObject implementation 00059 // remove() is implemented in the generated part. 00060 // -------------------------------------------------------------------------- 00061 00062 public abstract void remove() throws RemoveException; 00063 00067 public EJBLocalHome getEJBLocalHome() { 00068 return bf.getLocalHome(); 00069 } 00070 00075 public Object getPrimaryKey() throws EJBException { 00076 throw new EJBException("Session bean has no primary key"); 00077 } 00078 00088 public boolean isIdentical(EJBLocalObject obj) { 00089 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00090 boolean ret = false; 00091 JSessionFactory sf = bf; 00092 if (sf.isStateful()) { 00093 // For stateful sessions, just compare both objects. 00094 if (obj != null) { 00095 ret = obj.equals(this); 00096 } 00097 } else { 00098 // In case of Stateless session bean, we must compare the 2 00099 // factories 00100 if (obj != null) { 00101 try { 00102 //a simple cast should work on a local object 00103 JSessionLocal ejb2 = (JSessionLocal) obj; 00104 JSessionSwitch bs2 = ejb2.getSessionSwitch(); 00105 JSessionFactory bf2 = bs2.getBeanFactory(); 00106 ret = bf2.equals(sf); 00107 } catch (Exception e) { 00108 TraceEjb.logger.log(BasicLevel.WARN, "exception:" + e); 00109 throw new EJBException("isIdentical failed", e); 00110 } 00111 } 00112 } 00113 return ret; 00114 } 00115 00116 // --------------------------------------------------------------- 00117 // other public methods, for internal use. 00118 // --------------------------------------------------------------- 00119 00124 public void setSessionSwitch(JSessionSwitch bs) { 00125 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00126 this.bs = bs; 00127 } 00128 00132 public JSessionSwitch getSessionSwitch() { 00133 return bs; 00134 } 00135 00142 public RequestCtx preInvoke(int txa) { 00143 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00144 RequestCtx rctx = bf.preInvoke(txa); 00145 bs.setMustCommit(rctx.mustCommit); // for remove stateful session 00146 bs.enlistConnections(rctx.currTx); // Enlist connection list to tx 00147 return rctx; 00148 } 00149 00155 public void checkSecurity(EJBInvocation ejbInv) { 00156 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00157 bf.checkSecurity(ejbInv); 00158 } 00159 00165 public void postInvoke(RequestCtx rctx) { 00166 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 00167 bs.delistConnections(rctx.currTx); 00168 // save current tx (for Stateful Bean Managed only) 00169 bs.saveBeanTx(); 00170 try { 00171 bf.postInvoke(rctx); 00172 } finally { 00173 if (rctx.sysExc != null) { 00174 bs.discardICtx(rctx.currTx); 00175 } else { 00176 bs.releaseICtx(rctx.currTx); 00177 } 00178 } 00179 } 00180 00181 }