this.managedReferenceFactory = managedReferenceFactory;
}
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
final ManagedReference managedReference = targetReference.get();
if (managedReference instanceof WeldManagedReference) {
final WeldManagedReference reference = (WeldManagedReference) managedReference;
reference.getInjectionTarget().inject(targetReference.get().getInstance(), reference.getContext());
//now inject the interceptors
for (final Map.Entry<Class<?>, AtomicReference<ManagedReference>> entry : interceptors.entrySet()) {
final ManagedReference instance = entry.getValue().get();
if (instance != null) {
reference.injectInterceptor(entry.getKey(), instance.getInstance());
}
}
} else if(managedReferenceFactory != null){
//this component was not created by the managed reference factory, this can happen in the case of JSF managed beans
final ManagedReference newReference = managedReferenceFactory.injectExistingReference(managedReference);
targetReference.set(newReference);
}
return context.proceed();
}