Object callingObject = ((CallerInvocation) invocation).getCallingObject();
if (callingObject == null) return invocation.invokeNext(); // called from static method
Advised advised = (Advised) callingObject;
InstanceAdvisor advisor = advised._getInstanceAdvisor();
Interceptor interceptor = (Interceptor) advisor.getPerInstanceAspect(aspectDefinition);
return interceptor.invoke(invocation);
}
else
{
Object targetObject = invocation.getTargetObject();
if (targetObject == null) return invocation.invokeNext(); // static method call or static field call
InstanceAdvisor instanceAdvisor = null;
if (targetObject instanceof Advised)
{
Advised advised = (Advised) targetObject;
instanceAdvisor = advised._getInstanceAdvisor();
}
else
{
Advisor advisor = invocation.getAdvisor();
if (advisor == null)
{
return invocation.invokeNext();
}
if (advisor instanceof InstanceAdvisor)
{
instanceAdvisor = (InstanceAdvisor) advisor;
}
else
{
if (advisor instanceof ClassProxyContainer && invocation instanceof ContainerProxyMethodInvocation)
{
ContainerProxyMethodInvocation pi = (ContainerProxyMethodInvocation)invocation;
instanceAdvisor = pi.getProxy().getInstanceAdvisor();
}
else
{
return invocation.invokeNext();
}
}
}
Interceptor interceptor = (Interceptor) instanceAdvisor.getPerInstanceAspect(aspectDefinition);
return interceptor.invoke(invocation);
}
}