00001
00026 package org.objectweb.jonas_ejb.container;
00027
00028 import java.rmi.Remote;
00029 import java.rmi.RemoteException;
00030
00031 import javax.ejb.EJBHome;
00032 import javax.ejb.EJBObject;
00033 import javax.ejb.Handle;
00034 import javax.ejb.RemoveException;
00035 import javax.rmi.PortableRemoteObject;
00036
00037 import org.objectweb.carol.rmi.exception.RmiUtility;
00038 import org.objectweb.carol.util.configuration.CarolCurrentConfiguration;
00039
00040 import org.objectweb.jonas_ejb.lib.EJBInvocation;
00041 import org.objectweb.jonas_ejb.svc.JHandleIIOP;
00042
00043 import org.objectweb.util.monolog.api.BasicLevel;
00044
00050 public abstract class JSessionRemote extends JRemote implements Remote {
00051
00052
00056 protected JSessionSwitch bs;
00057
00063 public JSessionRemote(JSessionFactory bf) throws RemoteException {
00064 super((JFactory) bf);
00065 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00066 }
00067
00068
00069
00070
00071
00072
00078 public abstract void remove() throws RemoteException, RemoveException;
00079
00083 public EJBHome getEJBHome() {
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 return bf.getHome();
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 }
00105
00110 public Object getPrimaryKey() throws RemoteException {
00111
00112 try {
00113 throw new RemoteException("Session bean has no primary key");
00114 } catch (RemoteException e) {
00115
00116 RmiUtility.rethrowRmiException(e);
00117
00118 throw e;
00119 }
00120 }
00121
00129 public boolean isIdentical(EJBObject obj) throws RemoteException {
00130 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00131 try {
00132 boolean ret = false;
00133 JSessionFactory sf = (JSessionFactory) bf;
00134 if (sf.isStateful()) {
00135
00136 if (obj != null) {
00137 ret = ((obj.equals(PortableRemoteObject.toStub(this))) || (obj.equals(this)));
00138 }
00139 } else {
00140
00141
00142 String myhome = getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName();
00143 if (obj != null) {
00144 ret = obj.getEJBHome().getEJBMetaData().getHomeInterfaceClass().getName().equals(myhome);
00145 }
00146 }
00147 return ret;
00148 } catch (RemoteException e) {
00149
00150
00151 RmiUtility.rethrowRmiException(e);
00152
00153 throw e;
00154 }
00155 }
00156
00164 public Handle getHandle() throws RemoteException {
00165 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 String protocol = CarolCurrentConfiguration.getCurrent().getCurrentRMIName();
00178 TraceEjb.interp.log(BasicLevel.DEBUG, "Current protocol=" + protocol);
00179
00180 if (protocol.equals("iiop")) {
00181 return new JHandleIIOP(this);
00182 } else {
00183 return new JSessionHandle(this);
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 }
00196
00197
00198
00199
00200
00205 public void setSessionSwitch(JSessionSwitch bs) {
00206 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00207 this.bs = bs;
00208 }
00209
00213 public JSessionSwitch getSessionSwitch() {
00214 return bs;
00215 }
00216
00224 public RequestCtx preInvoke(int txa) throws RemoteException {
00225 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00226 RequestCtx rctx = bf.preInvokeRemote(txa);
00227 bs.setMustCommit(rctx.mustCommit);
00228 bs.enlistConnections(rctx.currTx);
00229 return rctx;
00230 }
00231
00237 public void checkSecurity(EJBInvocation ejbInv) {
00238 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00239 bf.checkSecurity(ejbInv);
00240 }
00241
00248 public void postInvoke(RequestCtx rctx) throws RemoteException {
00249 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00250 bs.delistConnections(rctx.currTx);
00251
00252 bs.saveBeanTx();
00253 try {
00254 bf.postInvokeRemote(rctx);
00255 } finally {
00256 if (rctx.sysExc != null) {
00257 bs.discardICtx(rctx.currTx);
00258 } else {
00259 bs.releaseICtx(rctx.currTx);
00260 }
00261 }
00262 }
00263
00264 }