JSessionRemote.java

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     // EJBObject implementation
00070     // remove() is implemented in the generated part.
00071     // --------------------------------------------------------------------------
00072 
00078     public abstract void remove() throws RemoteException, RemoveException;
00079 
00083     public EJBHome getEJBHome() {
00084         /*
00085          * try/catch block is commented because the encapsulated code don't
00086          * throw a RemoteException
00087          * If the code changes and throws a such exception, let's think
00088          * to uncomment it
00089          *
00090          * try {
00091          */
00092 
00093         return bf.getHome();
00094 
00095         /*
00096          * } catch (RemoteException e) {
00097          * // check if rmi exception mapping is needed - if yes the method  rethrows it
00098          * RmiUtility.rethrowRmiException(e);
00099          * // if not, throws the exception just as it is
00100          * throw e;
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             // check if rmi exception mapping is needed - if yes the method rethrows it
00116             RmiUtility.rethrowRmiException(e);
00117             // if not, throws the exception just as it is
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                 // For stateful sessions, just compare both objects.
00136                 if (obj != null) {
00137                     ret = ((obj.equals(PortableRemoteObject.toStub(this))) || (obj.equals(this)));
00138                 }
00139             } else {
00140                 // In case of Stateless session bean, we must compare the 2 Home
00141                 // We cannot cast the remote EJBObject cbecause it's a stub.
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             // check if rmi exception mapping is needed - if yes the method
00150             // rethrows it
00151             RmiUtility.rethrowRmiException(e);
00152             // if not, throws the exception just as it is
00153             throw e;
00154         }
00155     }
00156 
00164     public Handle getHandle() throws RemoteException {
00165         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00166 
00167         /*
00168          * try/catch block is commented because the encapsulated code don't
00169          * throw a RemoteException
00170          * If the code changes and throws a such exception, let's think
00171          * to uncomment it
00172          *
00173          * try {
00174          */
00175         // for iiop, a specific interoperable Handle is created with the use of
00176         // HandleDelegate
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          * } catch (RemoteException e) {
00188          * // check if rmi exception mapping is needed - if yes the method  rethrows it
00189          * RmiUtility.rethrowRmiException(e);
00190          * // if not, throws the exception just as it is
00191          * throw e;
00192          * }
00193          */
00194 
00195     }
00196 
00197     // ---------------------------------------------------------------
00198     // other public methods, for internal use.
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); // for remove stateful session
00228         bs.enlistConnections(rctx.currTx); // Enlist connection list to tx
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         // save current tx (for Bean Managed only)
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 }

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