MethodCalledByConstructorInvocation inv = (MethodCalledByConstructorInvocation) invocation;
Constructor<?> callingCon = inv.getCalling();
Class<?> callingClass = callingCon.getDeclaringClass();
if (isAdvised(callingClass))
{
ClassAdvisor advisor = AspectManager.instance().getAdvisor(callingClass);
if (advisor != null)
{
int index = advisor.getConstructorIndex(callingCon);
if (index >= 0)
{
HashMap<String, TLongObjectHashMap> calledClassesMap = advisor.getConCalledByConInterceptors()[index];
if (calledClassesMap != null)
{
TLongObjectHashMap calledCons = calledClassesMap.get(constructor.getDeclaringClass().getName());
if (calledCons != null)
{
long calledHash = MethodHashing.constructorHash(constructor);
ConByConInfo info = (ConByConInfo) calledCons.get(calledHash);
if (info != null && info.hasAdvices())
{
return advisor.invokeConCalledByCon(info, inv.getCallingObject(), args);
}
}
}
}
}
}
}
else if (invocation instanceof MethodCalledByMethodInvocation)
{
MethodCalledByMethodInvocation inv = (MethodCalledByMethodInvocation) invocation;
Method callingMethod = inv.getCallingMethod();
if (isAdvised(callingMethod.getDeclaringClass()))
{
ClassAdvisor advisor = AspectManager.instance().getAdvisor(callingMethod.getDeclaringClass());
if (advisor != null)
{
long callingMethodHash = MethodHashing.calculateHash(callingMethod);
long calledHash = MethodHashing.constructorHash(constructor);
@SuppressWarnings("unchecked")
HashMap calledClassesMap = (HashMap) advisor.getConCalledByMethodInterceptors().get(callingMethodHash);
if (calledClassesMap != null)
{
TLongObjectHashMap calledCons = (TLongObjectHashMap) calledClassesMap.get(constructor.getDeclaringClass().getName());
if (calledCons != null)
{
//CallerConstructorInfo info = (CallerConstructorInfo) calledCons.get(calledHash);
ConByMethodInfo info = (ConByMethodInfo) calledCons.get(calledHash);
if (info != null && info.hasAdvices())
{
//return advisor.invokeConCalledByMethod(callingMethodHash, args, info, inv.getCallingObject());
return advisor.invokeConCalledByMethod(info, inv.getCallingObject(), args);
}
}
}
}
}
}
//Try to attach to chain on target object
Class<?> calledClass = constructor.getDeclaringClass();
if (isAdvised(calledClass))
{
ClassAdvisor advisor = AspectManager.instance().getAdvisor(constructor.getDeclaringClass());
if (advisor != null && advisor.hasAspects())
{
int index = advisor.getConstructorIndex(constructor);
if (index >= 0)
{
ConstructorInfo jp = advisor.getConstructorInfos()[index];
return jp.getWrapper().invoke(null, args);
}
}
}
return invocation.invokeNext();