package org.jboss.proxy.ejb;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.InvocationContext;
import org.jboss.invocation.InvocationKey;
import org.jboss.invocation.InvocationType;
import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
public class StatelessSessionInterceptor
extends GenericEJBInterceptor
{
private static final long serialVersionUID = -8807189798153718350L;
public StatelessSessionInterceptor()
{}
public Object invoke(Invocation invocation)
throws Throwable
{
InvocationContext ctx = invocation.getInvocationContext();
Method m = invocation.getMethod();
if (m.equals(TO_STRING))
{
return toString(ctx);
}
else if (m.equals(EQUALS))
{
Object[] args = invocation.getArguments();
String argsString = args[0] != null ? args[0].toString() : "";
String thisString = toString(ctx);
return new Boolean(thisString.equals(argsString));
}
else if (m.equals(HASH_CODE))
{
return new Integer(this.hashCode());
}
else if (m.equals(GET_HANDLE))
{
return new StatelessHandleImpl(
(String)ctx.getValue(InvocationKey.JNDI_NAME));
}
else if (m.equals(GET_PRIMARY_KEY))
{
throw new RemoteException("Call to getPrimaryKey not allowed on session bean");
}
else if (m.equals(GET_EJB_HOME))
{
return getEJBHome(invocation);
}
else if (m.equals(IS_IDENTICAL))
{
Object[] args = invocation.getArguments();
String argsString = args[0].toString();
String thisString = toString(ctx);
return new Boolean(thisString.equals(argsString));
}
else
{
invocation.setType(InvocationType.REMOTE);
return getNext().invoke(invocation);
}
}
private String toString(InvocationContext ctx)
{
return ctx.getValue(InvocationKey.JNDI_NAME) + ":Stateless";
}
}