package org.jboss.ejb;
import org.jboss.ejb.txtimer.TimedObjectInvoker;
import org.jboss.invocation.Invocation;
import org.jboss.proxy.ejb.EJBMetaDataImpl;
import org.jboss.util.UnreachableStatementException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
import javax.ejb.HomeHandle;
import javax.ejb.RemoveException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;
public class StatelessSessionContainer extends SessionContainer
implements EJBProxyFactoryContainer, InstancePoolContainer
{
public void remove(Invocation mi)
throws RemoteException, RemoveException
{
log.debug("Useless invocation of remove() for stateless session bean");
}
public EJBLocalObject createLocalHome()
throws CreateException
{
if (localProxyFactory == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
createCount++;
return localProxyFactory.getStatelessSessionEJBLocalObject();
}
public void removeLocalHome(Object primaryKey)
{
log.debug("Useless invocation of remove(Object) for stateless session bean");
}
public EJBObject createHome()
throws RemoteException, CreateException
{
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
createCount++;
Object obj = ci.getStatelessSessionEJBObject();
return (EJBObject) obj;
}
public void removeHome(Handle handle)
throws RemoteException, RemoveException
{
throw new UnreachableStatementException();
}
public void removeHome(Object primaryKey)
throws RemoteException, RemoveException
{
throw new UnreachableStatementException();
}
protected void setupHomeMapping()
throws NoSuchMethodException
{
boolean debug = log.isDebugEnabled();
Map map = new HashMap();
if (homeInterface != null)
{
Method[] m = homeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
if (debug)
log.debug("Mapping " + m[i].getName());
map.put(m[i], getClass().getMethod(m[i].getName() + "Home", m[i].getParameterTypes()));
}
}
if (localHomeInterface != null)
{
Method[] m = localHomeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
if (debug)
log.debug("Mapping " + m[i].getName());
map.put(m[i], getClass().getMethod(m[i].getName() + "LocalHome", m[i].getParameterTypes()));
}
}
homeMapping = map;
}
Interceptor createContainerInterceptor()
{
return new ContainerInterceptor();
}
class ContainerInterceptor
extends AbstractContainerInterceptor
{
public Object invokeHome(Invocation mi) throws Exception
{
Method miMethod = mi.getMethod();
Method m = (Method) getHomeMapping().get(miMethod);
if (m == null)
{
String msg = "Invalid invocation, check your deployment packaging, method=" + miMethod;
throw new EJBException(msg);
}
try
{
return mi.performCall(StatelessSessionContainer.this, m, mi.getArguments());
}
catch (Exception e)
{
rethrow(e);
}
throw new org.jboss.util.UnreachableStatementException();
}
public Object invoke(Invocation mi) throws Exception
{
EnterpriseContext ctx = (EnterpriseContext) mi.getEnterpriseContext();
if (ctx.getTransaction() == null)
ctx.setTransaction(mi.getTransaction());
Method miMethod = mi.getMethod();
Map map = getBeanMapping();
Method m = (Method) map.get(miMethod);
if (m == null)
{
String msg = "Invalid invocation, check your deployment packaging, method=" + miMethod;
throw new EJBException(msg);
}
if (m.getDeclaringClass().equals(StatelessSessionContainer.class) ||
m.getDeclaringClass().equals(SessionContainer.class))
{
try
{
return mi.performCall(StatelessSessionContainer.this, m, new Object[]{mi});
}
catch (Exception e)
{
rethrow(e);
}
}
else {
try
{
Object bean = ctx.getInstance();
return mi.performCall(bean, m, mi.getArguments());
}
catch (Exception e)
{
rethrow(e);
}
}
throw new org.jboss.util.UnreachableStatementException();
}
}
}