package org.jboss.ejb.plugins;
import javax.ejb.EJBException;
import org.jboss.ejb.Interceptor;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.InvocationKey;
import org.jboss.naming.ENCThreadLocalKey;
public class ProxyFactoryFinderInterceptor
extends AbstractInterceptor
{
public void create() throws Exception
{
}
protected void setProxyFactory(String invokerBinding, Invocation mi) throws Exception
{
if (invokerBinding == null)
{
log.trace("invokerBInding is null in ProxyFactoryFinder");
return;
}
Object proxyFactory = container.lookupProxyFactory(invokerBinding);
if (proxyFactory == null)
{
String methodName;
if(mi.getMethod() != null) {
methodName = mi.getMethod().getName();
} else
{
methodName ="<no method>";
}
log.error("***************** proxyFactory is null ********");
log.error("Method name: " + methodName);
log.error("jmx name: " + container.getJmxName().toString());
log.error("invokerBinding: " + invokerBinding);
log.error("Stack trace", new Throwable());
log.error("*************************");
throw new EJBException("Couldn't find proxy factory");
}
container.setProxyFactory(proxyFactory);
}
public Object invokeHome(Invocation mi)
throws Exception
{
String invokerBinding =
(String)mi.getAsIsValue(InvocationKey.INVOKER_PROXY_BINDING);
setProxyFactory(invokerBinding, mi);
String oldInvokerBinding = ENCThreadLocalKey.getKey();
if (invokerBinding != null || oldInvokerBinding == null)
{
ENCThreadLocalKey.setKey(invokerBinding);
}
Interceptor next = getNext();
Object value = null;
try
{
value = next.invokeHome(mi);
}
finally
{
ENCThreadLocalKey.setKey(oldInvokerBinding);
}
return value;
}
public Object invoke(Invocation mi)
throws Exception
{
String invokerBinding =
(String)mi.getAsIsValue(InvocationKey.INVOKER_PROXY_BINDING);
setProxyFactory(invokerBinding, mi);
String oldInvokerBinding = ENCThreadLocalKey.getKey();
if (invokerBinding != null || oldInvokerBinding == null)
{
ENCThreadLocalKey.setKey(invokerBinding);
}
Interceptor next = getNext();
Object value = null;
try
{
value = next.invoke(mi);
}
finally
{
ENCThreadLocalKey.setKey(oldInvokerBinding);
}
return value;
}
}