00001
00026 package org.objectweb.jonas_ejb.container;
00027
00028 import java.rmi.NoSuchObjectException;
00029 import java.rmi.RemoteException;
00030
00031 import javax.ejb.EJBHome;
00032 import javax.ejb.EJBMetaData;
00033 import javax.ejb.Handle;
00034 import javax.ejb.HomeHandle;
00035 import javax.ejb.RemoveException;
00036 import javax.naming.NamingException;
00037 import javax.rmi.PortableRemoteObject;
00038
00039 import org.objectweb.carol.util.configuration.CarolCurrentConfiguration;
00040 import org.objectweb.carol.util.csiv2.SasHelper;
00041
00042 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
00043 import org.objectweb.jonas_ejb.lib.EJBInvocation;
00044 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
00045 import org.objectweb.jonas_ejb.deployment.api.SessionDesc;
00046 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
00047 import org.objectweb.jonas_ejb.svc.JHomeHandleIIOP;
00048 import org.objectweb.jonas_ejb.svc.JMetaData;
00049
00050 import org.objectweb.util.monolog.api.BasicLevel;
00051
00057 public abstract class JHome extends PortableRemoteObject implements EJBHome {
00058
00059 protected JMetaData ejbMetaData = null;
00060 protected BeanDesc dd;
00061 protected JFactory bf;
00062 protected boolean unregistered = true;
00063
00070 public JHome(BeanDesc dd, JFactory bf) throws RemoteException {
00071 TraceEjb.interp.log(BasicLevel.DEBUG, "JHome constructor");
00072 this.dd = dd;
00073 this.bf = bf;
00074 }
00075
00076
00077
00078
00079
00085 public EJBMetaData getEJBMetaData() throws RemoteException {
00086
00087 TraceEjb.interp.log(BasicLevel.DEBUG, "JHome getEJBMetaData");
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 if (ejbMetaData == null) {
00098
00099 if (dd instanceof SessionDesc) {
00100 boolean isSession = true;
00101 boolean isStatelessSession = (dd instanceof SessionStatelessDesc);
00102 Class primaryKeyClass = null;
00103 ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass);
00104 } else if (dd instanceof EntityDesc) {
00105 boolean isSession = false;
00106 boolean isStatelessSession = false;
00107 Class primaryKeyClass = ((EntityDesc) dd).getPrimaryKeyClass();
00108 ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass);
00109 }
00110 }
00111 return ejbMetaData;
00112
00113
00114
00115
00116
00117
00118
00119
00120 }
00121
00129 public HomeHandle getHomeHandle() throws java.rmi.RemoteException {
00130 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 String protocol = CarolCurrentConfiguration.getCurrent().getCurrentRMIName();
00143 TraceEjb.interp.log(BasicLevel.DEBUG, "Current protocol=" + protocol);
00144
00145 if (protocol.equals("iiop")) {
00146 return new JHomeHandleIIOP(this, bf.myClassLoader());
00147 } else {
00148 return new JHomeHandle(dd.getJndiName());
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 }
00160
00168 public abstract void remove(Handle handle) throws RemoteException, RemoveException;
00169
00176 public abstract void remove(Object primaryKey) throws RemoteException, RemoveException;
00177
00178
00179
00180
00181
00186 protected void register() throws NamingException {
00187 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00188 String name = dd.getJndiName();
00189
00190
00191 SasHelper.rebind(name, this, dd.getSasComponent());
00192
00193 unregistered = false;
00194 }
00195
00200 protected void unregister() throws NamingException {
00201 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00202 String name = dd.getJndiName();
00203
00204 bf.getInitialContext().unbind(name);
00205
00206 try {
00207 PortableRemoteObject.unexportObject(this);
00208 } catch (NoSuchObjectException e) {
00209 TraceEjb.interp.log(BasicLevel.ERROR, "unexportObject(JHome) failed: " + e);
00210 }
00211 unregistered = true;
00212 }
00213
00219 public String getJndiName() {
00220 return dd.getJndiName();
00221 }
00222
00229 public RequestCtx preInvoke(int txa) throws RemoteException {
00230 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00231 return bf.preInvokeRemote(txa);
00232 }
00233
00239 public void checkSecurity(EJBInvocation ejbInv) {
00240 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00241 bf.checkSecurity(ejbInv);
00242 }
00243
00249 public void postInvoke(RequestCtx rctx) throws RemoteException {
00250 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00251 bf.postInvokeRemote(rctx);
00252 }
00253
00257 public BeanDesc getDd() {
00258 return dd;
00259 }
00263 public JFactory getBf() {
00264 return bf;
00265 }
00266 }