JSessionContext.java

00001 
00026 package org.objectweb.jonas_ejb.container;
00027 
00028 import java.io.Serializable;
00029 import java.rmi.RemoteException;
00030 import java.util.List;
00031 
00032 import javax.ejb.EJBLocalObject;
00033 import javax.ejb.EJBObject;
00034 import javax.ejb.RemoveException;
00035 import javax.ejb.SessionBean;
00036 import javax.ejb.SessionContext;
00037 import javax.xml.rpc.handler.MessageContext;
00038 
00039 import org.objectweb.util.monolog.api.BasicLevel;
00040 
00048 public abstract class JSessionContext extends JContext implements SessionContext, Serializable {
00049 
00050     protected JSessionSwitch bs = null;
00051 
00052     protected boolean ismarkedremoved;
00053 
00059     public JSessionContext(JSessionFactory bf, SessionBean eb) {
00060         super(bf, eb);
00061         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00062         // session beans may have home or localHome
00063         this.home = bf.getHome();
00064         this.localhome = bf.getLocalHome();
00065     }
00066 
00067     // ------------------------------------------------------------------
00068     // SessionContext implementation
00069     // ------------------------------------------------------------------
00070 
00079     public EJBObject getEJBObject() throws IllegalStateException {
00080         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00081         if (ismarkedremoved || bs == null) {
00082             if (ismarkedremoved)
00083                 TraceEjb.logger.log(BasicLevel.ERROR, "marked removed");
00084             else
00085                 TraceEjb.logger.log(BasicLevel.ERROR, "no SessionSwitch");
00086             throw new IllegalStateException("getEJBObject: EJB is removed");
00087         }
00088         EJBObject ejbobject = bs.getRemote();
00089         if (ejbobject == null) {
00090             throw new IllegalStateException("No Remote Interface for this bean");
00091         }
00092         return ejbobject;
00093     }
00094 
00104     public EJBLocalObject getEJBLocalObject() throws IllegalStateException {
00105         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00106         if (ismarkedremoved || bs == null) {
00107             if (ismarkedremoved)
00108                 TraceEjb.logger.log(BasicLevel.ERROR, "marked removed");
00109             else
00110                 TraceEjb.logger.log(BasicLevel.ERROR, "no SessionSwitch");
00111             throw new IllegalStateException("getEJBLocalObject: EJB is removed");
00112         }
00113         EJBLocalObject ejblocalobject = bs.getLocal();
00114         if (ejblocalobject == null) throw new IllegalStateException("No Local Object for this bean");
00115         return ejblocalobject;
00116     }
00117 
00124     public abstract MessageContext getMessageContext() throws java.lang.IllegalStateException;
00125 
00130     public boolean getRollbackOnly() throws IllegalStateException {
00131         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00132 
00133         if (getState() < 2) {
00134             throw new IllegalStateException("the instance is not allowed to call this method");
00135         }
00136         return super.getRollbackOnly();
00137     }
00138     
00139     // -------------------------------------------------------------------
00140     // Other public methods
00141     // -------------------------------------------------------------------
00142 
00147     public void initSessionContext(JSessionSwitch bs) {
00148         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00149         this.bs = bs;
00150         ismarkedremoved = false;
00151     }
00152 
00159     // RemoteException is throwned to allow simpler genic templates
00160     public SessionBean getInstance() throws RemoteException {
00161         if (instance == null) {
00162             TraceEjb.logger.log(BasicLevel.ERROR, "null!");
00163             throw new RemoteException("No instance available");
00164         }
00165         return (SessionBean) instance;
00166     }
00167 
00171     public boolean isMarkedRemoved() {
00172         return ismarkedremoved;
00173     }
00174 
00175     // ------------------------------------------------------------------
00176     // Other methods
00177     // ------------------------------------------------------------------
00178 
00179     abstract public void setRemoved() throws RemoteException, RemoveException;
00180     abstract public void setConnectionList(List conlist);
00181 }

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