package org.jboss.ejb.plugins.local;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import javax.naming.InitialContext;
import javax.ejb.EJBObject;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBException;
class StatelessSessionProxy extends LocalProxy
implements InvocationHandler
{
static final long serialVersionUID = 5677941766264344565L;
StatelessSessionProxy(String jndiName, BaseLocalProxyFactory factory)
{
super(jndiName, factory);
}
protected Object getId()
{
return jndiName;
}
public final Object invoke(final Object proxy, final Method m, Object[] args)
throws Throwable
{
Object retValue = null;
if (args == null)
args = EMPTY_ARGS;
if (m.equals(TO_STRING))
{
retValue = jndiName + ":Stateless";
}
else if (m.equals(EQUALS))
{
retValue = invoke(proxy, IS_IDENTICAL, args);
}
else if (m.equals(HASH_CODE))
{
retValue = new Integer(this.hashCode());
}
else if (m.equals(GET_PRIMARY_KEY))
{
if (proxy instanceof EJBObject)
{
throw new RemoteException("Call to getPrimaryKey not allowed on session bean");
}
if (proxy instanceof EJBLocalObject)
{
throw new EJBException("Call to getPrimaryKey not allowed on session bean");
}
}
else if (m.equals(GET_EJB_HOME))
{
InitialContext ctx = new InitialContext();
return ctx.lookup(jndiName);
}
else if (m.equals(IS_IDENTICAL))
{
retValue = isIdentical(args[0], jndiName + ":Stateless");
}
else
{
retValue = factory.invoke(jndiName, m, args);
}
return retValue;
}
}