new ClassDescriptionTraversal(interceptorClass.getModuleClass(), applicationClasses) {
@Override
public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
mergeInjectionsForClass(clazz, classDescription, moduleDescription, description, configuration, context, injectors, contextKey, uninjectors, metadataComplete);
final InterceptorClassDescription interceptorConfig;
if (classDescription != null && !metadataComplete) {
interceptorConfig = InterceptorClassDescription.merge(classDescription.getInterceptorClassDescription(), moduleDescription.getInterceptorClassOverride(clazz.getName()));
} else {
interceptorConfig = InterceptorClassDescription.merge(null, moduleDescription.getInterceptorClassOverride(clazz.getName()));
}
// Only class level interceptors are processed for postconstruct/predestroy methods.
// Method level interceptors aren't supposed to be processed for postconstruct/predestroy lifecycle
// methods, as per interceptors spec
if (interceptorHasLifecycleCallbacks) {
final MethodIdentifier postConstructMethodIdentifier = interceptorConfig.getPostConstruct();
if (postConstructMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, postConstructMethodIdentifier);
if (isNotOverriden(clazz, method, interceptorClass.getModuleClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, true, true);
List<InterceptorFactory> userPostConstruct = userPostConstructByInterceptorClass.get(interceptorClassName);
if (userPostConstruct == null) {
userPostConstructByInterceptorClass.put(interceptorClassName, userPostConstruct = new ArrayList<InterceptorFactory>());
}
userPostConstruct.add(interceptorFactory);
}
}
final MethodIdentifier preDestroyMethodIdentifier = interceptorConfig.getPreDestroy();
if (preDestroyMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, preDestroyMethodIdentifier);
if (isNotOverriden(clazz, method, interceptorClass.getModuleClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, true, true);
List<InterceptorFactory> userPreDestroy = userPreDestroyByInterceptorClass.get(interceptorClassName);
if (userPreDestroy == null) {
userPreDestroyByInterceptorClass.put(interceptorClassName, userPreDestroy = new ArrayList<InterceptorFactory>());
}
userPreDestroy.add(interceptorFactory);
}
}
}
final MethodIdentifier aroundInvokeMethodIdentifier = interceptorConfig.getAroundInvoke();
if (aroundInvokeMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, aroundInvokeMethodIdentifier);
if (isNotOverriden(clazz, method, interceptorClass.getModuleClass(), deploymentReflectionIndex)) {
List<InterceptorFactory> interceptors;
if ((interceptors = userAroundInvokesByInterceptorClass.get(interceptorClassName)) == null) {
userAroundInvokesByInterceptorClass.put(interceptorClassName, interceptors = new ArrayList<InterceptorFactory>());
}
interceptors.add(new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, false));
}
}
if (description.isTimerServiceApplicable()) {
final MethodIdentifier aroundTimeoutMethodIdentifier = interceptorConfig.getAroundTimeout();
if (aroundTimeoutMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, aroundTimeoutMethodIdentifier);
if (isNotOverriden(clazz, method, interceptorClass.getModuleClass(), deploymentReflectionIndex)) {
List<InterceptorFactory> interceptors;
if ((interceptors = userAroundTimeoutsByInterceptorClass.get(interceptorClassName)) == null) {
userAroundTimeoutsByInterceptorClass.put(interceptorClassName, interceptors = new ArrayList<InterceptorFactory>());
}
interceptors.add(new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, false));
}
}
}
}
}.run();
}
final Deque<InterceptorFactory> userPostConstruct = new ArrayDeque<InterceptorFactory>();
final Deque<InterceptorFactory> userPreDestroy = new ArrayDeque<InterceptorFactory>();
//now add the lifecycle interceptors in the correct order
for (final InterceptorDescription interceptorClass : interceptorWithLifecycleCallbacks) {
if (userPostConstructByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPostConstruct.addAll(userPostConstructByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
if (userPreDestroyByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPreDestroy.addAll(userPreDestroyByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
}
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
final InterceptorClassDescription interceptorConfig = mergeInterceptorConfig(clazz, classDescription, description, metadataComplete);
final MethodIdentifier componentPostConstructMethodIdentifier = interceptorConfig.getPostConstruct();
if (componentPostConstructMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, componentPostConstructMethodIdentifier);
if (isNotOverriden(clazz, method, componentClassIndex.getIndexedClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, true, true);
userPostConstruct.addLast(interceptorFactory);
}
}
final MethodIdentifier componentPreDestroyMethodIdentifier = interceptorConfig.getPreDestroy();
if (componentPreDestroyMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, componentPreDestroyMethodIdentifier);
if (isNotOverriden(clazz, method, componentClassIndex.getIndexedClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, true, true);
userPreDestroy.addLast(interceptorFactory);
}
}
final MethodIdentifier componentAroundInvokeMethodIdentifier = interceptorConfig.getAroundInvoke();
if (componentAroundInvokeMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, componentAroundInvokeMethodIdentifier);
if (isNotOverriden(clazz, method, componentClassIndex.getIndexedClass(), deploymentReflectionIndex)) {
componentUserAroundInvoke.add(new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, false));
}
}
if (description.isTimerServiceApplicable()) {
final MethodIdentifier componentAroundTimeoutMethodIdentifier = interceptorConfig.getAroundTimeout();
if (componentAroundTimeoutMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, componentAroundTimeoutMethodIdentifier);
if (isNotOverriden(clazz, method, componentClassIndex.getIndexedClass(), deploymentReflectionIndex)) {
componentUserAroundTimeout.add(new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, false));
}