public boolean defineInterceptorMethods()

in webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java [130:278]


    public boolean defineInterceptorMethods()
    {
        List<Class> classHierarchy = webBeansContext.getInterceptorUtil().getReverseClassHierarchy(annotatedType.getJavaClass());

        Collection<Method> aroundInvokeMethod = null;
        List<AnnotatedMethod> postConstructMethods = new ArrayList<>();
        List<AnnotatedMethod> preDestroyMethods = new ArrayList<>();
        List<AnnotatedMethod> aroundTimeoutMethods = new ArrayList<>();
        List<AnnotatedMethod> aroundConstructMethods = new ArrayList<>();

        // EJB related interceptors
        List<AnnotatedMethod> prePassivateMethods = new ArrayList<>();
        List<AnnotatedMethod> postActivateMethods = new ArrayList<>();

        boolean interceptorFound = false;

        Set<AnnotatedMethod<? super T>> methods = webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType);

        for (Class clazz : classHierarchy)
        {

            for (AnnotatedMethod m : methods)
            {
                int arouncConstructCount = 0;
                if (clazz == m.getJavaMember().getDeclaringClass())
                {
                    if (m.getAnnotation(AroundConstruct.class) != null)
                    {
                        if (arouncConstructCount > 0)
                        {
                            throw new WebBeansConfigurationException("only one AroundConstruct allowed per Interceptor");
                        }
                        arouncConstructCount++;
                        aroundConstructMethods.add(m);
                    }

                    // we only take methods from this very class and not sub- or superclasses
                    if (m.getAnnotation(AroundInvoke.class) != null)
                    {
                        if (aroundInvokeMethod != null)
                        {
                            for (Method ai : aroundInvokeMethod)
                            {
                                if (ai.getDeclaringClass() == m.getJavaMember().getDeclaringClass())
                                {
                                    throw new WebBeansConfigurationException("only one AroundInvoke allowed per Interceptor");
                                }
                            }
                        }
                        checkAroundInvokeConditions(m);
                        if (aroundInvokeMethod == null)
                        {
                            aroundInvokeMethod = new ArrayList<>();
                        }
                        aroundInvokeMethod.add(m.getJavaMember());
                    }

                    // PostConstruct
                    if (m.getAnnotation(PostConstruct.class) != null)
                    {
                        checkSameClassInterceptors(postConstructMethods, m);
                        postConstructMethods.add(m); // add at last position
                    }

                    // PreDestroy
                    if (m.getAnnotation(PreDestroy.class) != null)
                    {
                        checkSameClassInterceptors(preDestroyMethods, m);
                        preDestroyMethods.add(m); // add at last position
                    }

                    // AroundTimeout
                    if (m.getAnnotation(AroundTimeout.class) != null)
                    {
                        checkSameClassInterceptors(aroundTimeoutMethods, m);
                        aroundTimeoutMethods.add(m); // add at last position
                    }

                    // and now the EJB related interceptors
                    if (ejbPlugin != null)
                    {
                        if (m.getAnnotation(prePassivateClass) != null)
                        {
                            checkSameClassInterceptors(prePassivateMethods, m);
                            prePassivateMethods.add(m); // add at last position
                        }

                        // AroundTimeout
                        if (m.getAnnotation(AroundTimeout.class) != null)
                        {
                            checkSameClassInterceptors(aroundTimeoutMethods, m);
                            postActivateMethods.add(m); // add at last position
                        }

                        // AroundTimeout
                        if (m.getAnnotation(postActivateClass) != null)
                        {
                            checkSameClassInterceptors(postActivateMethods, m);
                            postActivateMethods.add(m); // add at last position
                        }
                    }
                }
            }
        }

        // and now for setting the bean info

        interceptionMethods = new HashMap<>();

        if (aroundInvokeMethod != null)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.AROUND_INVOKE, aroundInvokeMethod.toArray(new Method[aroundInvokeMethod.size()]));
        }

        if (postConstructMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.POST_CONSTRUCT, getMethodArray(postConstructMethods));
        }
        if (preDestroyMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.PRE_DESTROY, getMethodArray(preDestroyMethods));
        }
        if (aroundTimeoutMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.AROUND_TIMEOUT, getMethodArray(aroundTimeoutMethods));
        }

        if (prePassivateMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.PRE_PASSIVATE, getMethodArray(prePassivateMethods));
        }
        if (postActivateMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.POST_ACTIVATE, getMethodArray(postActivateMethods));
        }
        if (aroundConstructMethods.size() > 0)
        {
            interceptorFound = true;
            interceptionMethods.put(InterceptionType.AROUND_CONSTRUCT, getMethodArray(aroundConstructMethods));
        }

        return interceptorFound;
    }