public Object invoke(final Object self, final Method thisMethod, final Method proceed, final Object[] args)
throws Throwable
{
if (Thread.currentThread().isInterrupted())
{
throw new ContainerException("Thread.interrupt() requested.");
}
Callable<Object> task = new Callable<Object>()
{
@Override
public Object call() throws Exception
{
try
{
if (thisMethod.getDeclaringClass().getName().equals(ForgeProxy.class.getName()))
{
if (thisMethod.getName().equals("getDelegate"))
return ClassLoaderInterceptor.this.getDelegate();
if (thisMethod.getName().equals("getHandler"))
return ClassLoaderInterceptor.this.getHandler();
}
}
catch (Exception e)
{
}
ClassLoader previousLoader = null;
Object result;
try
{
previousLoader = setCurrentLoader(loader);
if (thisMethod.equals(EQUALS_METHOD))
{
Object object = args[0];
Object unwrapped = Proxies.unwrap(object);
args[0] = unwrapped;
}
result = thisMethod.invoke(delegate, args);
}
catch (InvocationTargetException e)
{
if (e.getCause() instanceof Exception)
throw (Exception) e.getCause();
throw e;
}
finally
{
setCurrentLoader(previousLoader);
}
return result;
}
};
Object result = ClassLoaders.executeIn(loader, task);
if (Thread.currentThread().isInterrupted())
{
throw new ContainerException("Thread.interrupt() requested.");
}
return result;
}