public void validate()

in webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java [1421:1543]


    public void validate(Set<InjectionPoint> injectionPoints, Bean<?> bean)
    {

        boolean isDecorator = false;
        boolean isInterceptor = false;

        if (bean != null)
        {
            isInterceptor = bean instanceof Interceptor;
            isDecorator = !isInterceptor && bean instanceof jakarta.enterprise.inject.spi.Decorator;
        }

        boolean delegateFound = false;
        for (InjectionPoint injectionPoint : injectionPoints)
        {
            if (injectionPoint.getAnnotated().isAnnotationPresent(Decorated.class))
            {
                validateDecorated(bean, isDecorator, injectionPoint);
            }
            else if (injectionPoint.getAnnotated().isAnnotationPresent(Intercepted.class))
            {
                validateIntercepted(bean, isInterceptor, injectionPoint);
            }
            else
            {
                Class<?> rawType = ClassUtil.getRawTypeForInjectionPoint(injectionPoint);
                if (rawType.equals(jakarta.enterprise.inject.spi.Decorator.class) ||
                    (isDecorator && rawType.equals(Bean.class)) ||
                    rawType.equals(Interceptor.class))
                {
                    Type[] types = ClassUtil.getActualTypeArguments(injectionPoint.getType());
                    if (types.length != 1 || !GenericsUtil.isAssignableFrom(
                            false, AbstractProducerBean.class.isInstance(bean), bean.getBeanClass(), types[0], new HashMap<>()))
                    {
                        throw new WebBeansConfigurationException("injected bean parameter must be " + rawType);
                    }
                }
                else if (InterceptionFactory.class == rawType)
                {
                    if (!ParameterizedType.class.isInstance(injectionPoint.getType()))
                    {
                        throw new WebBeansConfigurationException(
                                "No type specified for the interception factory, ensure to paramterize it");
                    }
                    ParameterizedType pt = ParameterizedType.class.cast(injectionPoint.getType());
                    if (pt.getActualTypeArguments() == null || pt.getActualTypeArguments().length != 1)
                    {
                        throw new WebBeansConfigurationException("No explicit type specified for the interception factory");
                    }
                    Type type = pt.getActualTypeArguments()[0];
                    if (!Class.class.isInstance(type))
                    {
                        throw new WebBeansConfigurationException("InterceptionFactory only works with Class, no generics");
                    }
                }

                if (isDecorator)
                {
                    List<Method> abstractMethods = ClassUtil.getAbstractMethods(bean.getBeanClass());
                    if (!abstractMethods.isEmpty())
                    {
                        Set<Type> types = ((jakarta.enterprise.inject.spi.Decorator) bean).getDecoratedTypes();
                        for (Method abstractMethod : abstractMethods)
                        {
                            boolean methodDeclared = false;
                            for (Type type : types)
                            {
                                if (ClassUtil.isMethodDeclared(ClassUtil.getClass(type), abstractMethod.getName(), abstractMethod.getParameterTypes()))
                                {
                                    methodDeclared = true;
                                    break;
                                }
                            }

                            if (!methodDeclared)
                            {
                                throw new WebBeansConfigurationException("Decorator must not declare abstract methods which is not declared in any Decorated type.");
                            }
                        }
                    }
                }
            }

            if (!injectionPoint.isDelegate())
            {
                webBeansContext.getBeanManagerImpl().validate(injectionPoint);
            }
            else
            {
                if (!isDecorator)
                {
                    throw new WebBeansConfigurationException(
                            "Delegate injection points can not defined by beans that are not decorator. Injection point : "
                                    + injectionPoint);
                }
                else if (delegateFound)
                {
                    throw new WebBeansConfigurationException(
                            "Only one Delegate injection point can be defined by decorator. Decorator : "
                                    + injectionPoint.getBean());
                }
                else
                {
                    delegateFound = true;
                }
            }

            if (injectionPoint.getQualifiers().contains(DefaultLiteral.INSTANCE)
                    && ParameterizedType.class.isInstance(injectionPoint.getType())
                    && jakarta.enterprise.inject.spi.Decorator.class == ParameterizedType.class.cast(injectionPoint.getType()).getRawType()
                    && !isDecorator)
            {
                throw new WebBeansConfigurationException("@Inject Decorator<X> only supported in decorators");
            }
            if (injectionPoint.getQualifiers().contains(DefaultLiteral.INSTANCE)
                    && ParameterizedType.class.isInstance(injectionPoint.getType())
                    && Interceptor.class == ParameterizedType.class.cast(injectionPoint.getType()).getRawType()
                    && !isInterceptor)
            {
                throw new WebBeansConfigurationException("@Inject Interceptor<X> only supported in interceptors");
            }
        }
    }