public Object invoke(Invocation invocation) throws Throwable {
InvocationContext ctx = invocation.getInvocationContext();
Method m = invocation.getMethod();
// Implement local methods
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(ctx.getCacheId().hashCode());
}
// Implement local EJB calls
else if (m.equals(GET_HANDLE))
{
String jndiName = (String) ctx.getValue(InvocationKey.JNDI_NAME);
Object id = ctx.getCacheId();
return new EntityHandleImpl(jndiName, id);
}
else if (m.equals(GET_PRIMARY_KEY))
{
return ctx.getCacheId();
}
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));
}
// If not taken care of, go on and call the container
else
{
// We are a Remote invocation
invocation.setType(InvocationType.REMOTE);
// We pertain to this ID (represented by cache ID)
invocation.setId(ctx.getCacheId());
return getNext().invoke(invocation);
}
}
InvocationHandler implementation. |