final MethodIdentifier postConstructMethodIdentifier = classDescription.getPostConstructMethod();
if (postConstructMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, interceptorClassIndex, postConstructMethodIdentifier);
if (isNotOverriden(interceptorClassConfiguration, method, interceptorIndex, deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, true);
List<InterceptorFactory> userPostConstruct = userPostConstructByInterceptorClass.get(interceptorClassName);
if (userPostConstruct == null) {
userPostConstructByInterceptorClass.put(interceptorClassName, userPostConstruct = new ArrayList<InterceptorFactory>());
}
userPostConstruct.add(interceptorFactory);
}
}
final MethodIdentifier preDestroyMethodIdentifier = classDescription.getPreDestroyMethod();
if (preDestroyMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, interceptorClassIndex, preDestroyMethodIdentifier);
if (isNotOverriden(interceptorClassConfiguration, method, interceptorIndex, deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(contextKey, method, true);
List<InterceptorFactory> userPreDestroy = userPreDestroyByInterceptorClass.get(interceptorClassName);
if (userPreDestroy == null) {
userPreDestroyByInterceptorClass.put(interceptorClassName, userPreDestroy = new ArrayList<InterceptorFactory>());
}
userPreDestroy.add(interceptorFactory);
}
}
}
final MethodIdentifier aroundInvokeMethodIdentifier = classDescription.getAroundInvokeMethod();
if (aroundInvokeMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, interceptorClassIndex, aroundInvokeMethodIdentifier);
if (isNotOverriden(interceptorClassConfiguration, method, interceptorIndex, 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 = classDescription.getAroundTimeoutMethod();
if (aroundTimeoutMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, interceptorClassIndex, aroundTimeoutMethodIdentifier);
if (isNotOverriden(interceptorClassConfiguration, method, interceptorIndex, 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(componentClassConfiguration, applicationDescription) {
@Override
public void handle(EEModuleClassConfiguration configuration, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
final ClassReflectionIndex classReflectionIndex = deploymentReflectionIndex.getClassIndex(configuration.getModuleClass());
final MethodIdentifier componentPostConstructMethodIdentifier = classDescription.getPostConstructMethod();
if (componentPostConstructMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, classReflectionIndex, componentPostConstructMethodIdentifier);
if (isNotOverriden(configuration, method, componentClassIndex, deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, true);
userPostConstruct.addLast(interceptorFactory);
}
}
final MethodIdentifier componentPreDestroyMethodIdentifier = classDescription.getPreDestroyMethod();
if (componentPreDestroyMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, classReflectionIndex, componentPreDestroyMethodIdentifier);
if (isNotOverriden(configuration, method, componentClassIndex, deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, true);
userPreDestroy.addLast(interceptorFactory);
}
}
final MethodIdentifier componentAroundInvokeMethodIdentifier = classDescription.getAroundInvokeMethod();
if (componentAroundInvokeMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, classReflectionIndex, componentAroundInvokeMethodIdentifier);
if (isNotOverriden(configuration, method, componentClassIndex, deploymentReflectionIndex)) {
componentUserAroundInvoke.add(new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, false));
}
}
if (description.isTimerServiceApplicable()) {
final MethodIdentifier componentAroundTimeoutMethodIdentifier = classDescription.getAroundTimeoutMethod();
if (componentAroundTimeoutMethodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, classReflectionIndex, componentAroundTimeoutMethodIdentifier);
if (isNotOverriden(configuration, method, componentClassIndex, deploymentReflectionIndex)) {
componentUserAroundTimeout.add(new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, false));
}
}
}
}
}.run();
final InterceptorFactory tcclInterceptor = new ImmediateInterceptorFactory(new TCCLInterceptor(module.getClassLoader()));
// Apply post-construct
if (!injectors.isEmpty()) {
configuration.addPostConstructInterceptor(weaved(injectors), InterceptorOrder.ComponentPostConstruct.RESOURCE_INJECTION_INTERCEPTORS);
}