1 25 26 package org.objectweb.jonas_ejb.container; 27 28 import java.rmi.NoSuchObjectException ; 29 import java.rmi.RemoteException ; 30 31 import javax.ejb.EJBHome ; 32 import javax.ejb.EJBMetaData ; 33 import javax.ejb.Handle ; 34 import javax.ejb.HomeHandle ; 35 import javax.ejb.RemoveException ; 36 import javax.naming.NamingException ; 37 import javax.rmi.PortableRemoteObject ; 38 39 import org.objectweb.carol.util.configuration.ConfigurationRepository; 40 import org.objectweb.carol.util.csiv2.SasHelper; 41 42 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 43 import org.objectweb.jonas_ejb.deployment.api.EntityDesc; 44 import org.objectweb.jonas_ejb.deployment.api.SessionDesc; 45 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc; 46 import org.objectweb.jonas_ejb.lib.EJBInvocation; 47 import org.objectweb.jonas_ejb.svc.JHomeHandleIIOP; 48 import org.objectweb.jonas_ejb.svc.JMetaData; 49 50 import org.objectweb.util.monolog.api.BasicLevel; 51 52 57 public abstract class JHome extends PortableRemoteObject implements EJBHome { 58 59 protected JMetaData ejbMetaData = null; 60 protected BeanDesc dd; 61 protected JFactory bf; 62 protected boolean unregistered = true; 63 64 70 public JHome(BeanDesc dd, JFactory bf) throws RemoteException { 71 if (TraceEjb.isDebugIc()) { 72 TraceEjb.interp.log(BasicLevel.DEBUG, "JHome constructor"); 73 } 74 this.dd = dd; 75 this.bf = bf; 76 } 77 78 82 87 public EJBMetaData getEJBMetaData() throws RemoteException { 88 89 if (TraceEjb.isDebugIc()) { 90 TraceEjb.interp.log(BasicLevel.DEBUG, "JHome getEJBMetaData"); 91 } 92 93 101 if (ejbMetaData == null) { 102 103 if (dd instanceof SessionDesc) { 104 boolean isSession = true; 105 boolean isStatelessSession = (dd instanceof SessionStatelessDesc); 106 Class primaryKeyClass = null; 107 ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass); 108 } else if (dd instanceof EntityDesc) { 109 boolean isSession = false; 110 boolean isStatelessSession = false; 111 Class primaryKeyClass = ((EntityDesc) dd).getPrimaryKeyClass(); 112 ejbMetaData = new JMetaData(this, dd.getHomeClass(), dd.getRemoteClass(), isSession, isStatelessSession, primaryKeyClass); 113 } 114 } 115 return ejbMetaData; 116 124 } 125 126 133 public HomeHandle getHomeHandle() throws java.rmi.RemoteException { 134 if (TraceEjb.isDebugIc()) { 135 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 136 } 137 138 146 String protocol = ConfigurationRepository.getCurrentConfiguration().getProtocol().getName(); 149 if (TraceEjb.isDebugIc()) { 150 TraceEjb.interp.log(BasicLevel.DEBUG, "Current protocol = " + protocol); 151 } 152 if (protocol.equals("iiop")) { 153 return new JHomeHandleIIOP(this, bf.myClassLoader()); 154 } else { 155 return new JHomeHandle(dd.getJndiName()); 156 } 157 158 166 } 167 168 175 public abstract void remove(Handle handle) throws RemoteException , RemoveException ; 176 177 183 public abstract void remove(Object primaryKey) throws RemoteException , RemoveException ; 184 185 189 193 protected void register() throws NamingException { 194 if (TraceEjb.isDebugIc()) { 195 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 196 } 197 String name = dd.getJndiName(); 198 199 SasHelper.rebind(name, this, dd.getSasComponent()); 201 202 unregistered = false; 203 } 204 205 209 protected void unregister() throws NamingException { 210 if (TraceEjb.isDebugIc()) { 211 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 212 } 213 String name = dd.getJndiName(); 214 bf.getInitialContext().unbind(name); 216 217 try { 218 PortableRemoteObject.unexportObject(this); 219 } catch (NoSuchObjectException e) { 220 TraceEjb.interp.log(BasicLevel.ERROR, "unexportObject(JHome) failed", e); 221 } 222 unregistered = true; 223 } 224 225 230 public String getJndiName() { 231 return dd.getJndiName(); 232 } 233 234 240 public RequestCtx preInvoke(int txa) throws RemoteException { 241 if (TraceEjb.isDebugIc()) { 242 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 243 } 244 return bf.preInvokeRemote(txa); 245 } 246 247 252 public void checkSecurity(EJBInvocation ejbInv) { 253 if (TraceEjb.isDebugIc()) { 254 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 255 } 256 bf.checkSecurity(ejbInv); 257 } 258 259 264 public void postInvoke(RequestCtx rctx) throws RemoteException { 265 if (TraceEjb.isDebugIc()) { 266 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 267 } 268 bf.postInvokeRemote(rctx); 269 } 270 271 274 public BeanDesc getDd() { 275 return dd; 276 } 277 280 public JFactory getBf() { 281 return bf; 282 } 283 } 284 | Popular Tags |