00001
00017 package org.objectweb.jonas_ejb.container;
00018
00019 import java.rmi.RemoteException;
00020 import java.util.HashMap;
00021 import java.util.Map;
00022
00023 import javax.ejb.EJBException;
00024 import javax.naming.Context;
00025 import javax.naming.NamingException;
00026 import javax.naming.Reference;
00027 import javax.naming.StringRefAddr;
00028 import javax.xml.namespace.QName;
00029
00030 import org.apache.axis.AxisFault;
00031 import org.apache.axis.MessageContext;
00032 import org.apache.axis.handlers.ServiceInvocation;
00033
00034 import org.objectweb.jonas_ejb.deployment.api.MethodDesc;
00035 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
00036 import org.objectweb.jonas_ejb.lib.BeanNaming;
00037 import org.objectweb.jonas_ejb.lib.EJBInvocation;
00038
00039 import org.objectweb.jonas.common.Log;
00040
00041 import org.objectweb.util.monolog.api.BasicLevel;
00042 import org.objectweb.util.monolog.api.Logger;
00043
00048 public abstract class JServiceEndpointHome {
00049
00053 protected static Logger logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX);
00054 protected static Logger lognaming = Log.getLogger(Log.JONAS_NAMING_PREFIX);
00055
00056 protected SessionStatelessDesc dd;
00057
00058 protected JFactory bf;
00059
00060
00061 protected static Map sehomeList = new HashMap();
00062
00068 public JServiceEndpointHome(SessionStatelessDesc dd, JStatelessFactory bf) {
00069 logger.log(BasicLevel.DEBUG, "");
00070 this.dd = dd;
00071 this.bf = bf;
00072 }
00073
00078 protected void register() throws NamingException {
00079 logger.log(BasicLevel.DEBUG, "");
00080 String name = dd.getJndiServiceEndpointName();
00081
00082
00083 sehomeList.put(name, this);
00084
00085 Reference ref = new Reference("org.objectweb.jonas_ejb.container.JServiceEndpointHome",
00086 "org.objectweb.jonas_ejb.container.HomeFactory", null);
00087 ref.add(new StringRefAddr("bean.name", name));
00088 bf.getInitialContext().rebind(name, ref);
00089 }
00090
00094 protected void unregister() throws NamingException {
00095 logger.log(BasicLevel.DEBUG, "");
00096 String name = dd.getJndiServiceEndpointName();
00097
00098 bf.getInitialContext().unbind(name);
00099
00100 sehomeList.remove(name);
00101 }
00102
00109 public static JServiceEndpointHome getSEHome(String beanName) {
00110 logger.log(BasicLevel.DEBUG, "");
00111 JServiceEndpointHome seh = (JServiceEndpointHome) sehomeList.get(beanName);
00112 return seh;
00113 }
00114
00118 public JServiceEndpoint create() throws RemoteException {
00119 TraceEjb.interp.log(BasicLevel.DEBUG, "");
00120 RequestCtx rctx = bf.preInvoke(MethodDesc.TX_NOT_SET);
00121 bf.checkSecurity(null);
00122 JStatelessSwitch bs = null;
00123 try {
00124 bs = (JStatelessSwitch) ((JStatelessFactory) bf).createEJB();
00125 } catch (javax.ejb.AccessLocalException e) {
00126 throw new EJBException("Security Exception thrown by an enterprise Bean", e);
00127 } catch (EJBException e) {
00128 rctx.sysExc = e;
00129 throw e;
00130 } catch (RuntimeException e) {
00131 rctx.sysExc = e;
00132 throw new EJBException("RuntimeException thrown by an enterprise Bean", e);
00133 } catch (Error e) {
00134 rctx.sysExc = e;
00135 throw new EJBException("Error thrown by an enterprise Bean" + e);
00136 } catch (RemoteException e) {
00137 rctx.sysExc = e;
00138 throw new EJBException("Remote Exception raised:", e);
00139 } finally {
00140 bf.postInvoke(rctx);
00141 }
00142 return bs.getServiceEndpoint();
00143 }
00144
00149 public Context setCompCtx() {
00150 lognaming.log(BasicLevel.DEBUG, "");
00151 return bf.setComponentContext();
00152 }
00153
00158 public void resetCompCtx(Context ctx) {
00159 if (lognaming.isLoggable(BasicLevel.DEBUG)) {
00160 lognaming.log(BasicLevel.DEBUG, "reset ctx:" + ctx);
00161 }
00162 bf.resetComponentContext(ctx);
00163 }
00164
00168 public void checkSecurity(MessageContext msgContext) {
00169
00170 EJBInvocation ejb = new EJBInvocation();
00171 String qname = null;
00172 QName q = null;
00173 try {
00174 ServiceInvocation si = new ServiceInvocation(msgContext);
00175 qname = si.getMethodName();
00176 q = new QName(qname);
00177 ejb.methodPermissionSignature = BeanNaming.getSignature(bf.getEJBName(), msgContext.getOperationByQName(q).getMethod());
00178 } catch (AxisFault e ) {
00179
00180
00181 if (lognaming.isLoggable(BasicLevel.WARN ))
00182 lognaming.log(BasicLevel.WARN, "can't retreive the operation from message...can not check the security");
00183 return;
00184 }
00185
00186 bf.checkSecurity(ejb);
00187 }
00191 public abstract JServiceEndpoint createServiceEndpointObject() throws RemoteException;
00192
00193
00194 }
00195