package org.jboss.ejb.plugins.local;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.RemoveException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class LocalHomeProxy
extends LocalProxy
implements InvocationHandler
{
static final long serialVersionUID = 1762319499924478521L;
protected static final Method REMOVE_BY_PRIMARY_KEY;
protected static final Method REMOVE_OBJECT;
static
{
try
{
final Class empty[] = {};
final Class type = EJBLocalHome.class;
REMOVE_BY_PRIMARY_KEY = type.getMethod("remove", new Class[] {Object.class});
REMOVE_OBJECT = EJBLocalObject.class.getMethod("remove", empty);
}
catch (Exception e)
{
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
public LocalHomeProxy(String jndiName, BaseLocalProxyFactory factory)
{
super(jndiName, factory);
}
protected Object getId()
{
return jndiName;
}
public 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 + "Home";
}
else if (m.equals(EQUALS))
{
Object temp = invoke(proxy, TO_STRING, args);
retValue = new Boolean(temp.equals(jndiName + "Home"));
}
else if (m.equals(HASH_CODE))
{
retValue = new Integer(this.hashCode());
}
else if (m.equals(REMOVE_BY_PRIMARY_KEY))
{
try
{
Object id = args[0];
retValue = factory.invoke(id, REMOVE_OBJECT, EMPTY_ARGS);
}
catch (Exception e)
{
RemoveException re = new RemoveException(e.getMessage());
re.initCause(e);
throw re;
}
}
else
{
retValue = factory.invokeHome(m, args);
}
return retValue;
}
}