Search in sources :

Example 1 with WeldDecorator

use of org.jboss.weld.bean.WeldDecorator in project core by weld.

the class Validator method validateDecorator.

protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) {
    if (decorator.getDecoratedTypes().isEmpty()) {
        throw ValidatorLogger.LOG.noDecoratedTypes(decorator);
    }
    if (!decorator.getScope().equals(Dependent.class)) {
        throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator);
    }
    Decorators.checkDelegateType(decorator);
    /*
         * Validate decorators of facade built-in beans
         */
    Type delegateType = decorator.getDelegateType();
    if (delegateType instanceof ParameterizedType) {
        ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType;
        if (!Decorators.isPassivationCapable(decorator)) {
            if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) {
                throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName());
            }
            if (Event.class.equals(parameterizedDelegateType.getRawType())) {
                throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Event.class.getName());
            }
        }
    }
    if (decorator instanceof WeldDecorator<?>) {
        EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated();
        if (decorator instanceof DecoratorImpl<?>) {
            // Discovered decorator bean - abstract methods and delegate injection point are validated during bean initialization
            validateRIBean((CommonBean<?>) decorator, manager, specializedBeans);
            // Following checks are not legal for custom decorator beans as we cannot rely on decorator bean class methods
            if (!BeanMethods.getObserverMethods(annotated).isEmpty() || !BeanMethods.getAsyncObserverMethods(annotated).isEmpty()) {
                throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator);
            }
            while (annotated != null && annotated.getJavaClass() != Object.class) {
                if (!annotated.getDeclaredEnhancedMethods(Produces.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveProducerMethods(decorator);
                }
                if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator);
                }
                if (!annotated.getDeclaredEnhancedMethodsWithAnnotatedParameters(Disposes.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveDisposerMethods(decorator);
                }
                annotated = annotated.getEnhancedSuperclass();
            }
        } else {
            // Custom decorator bean
            validateGeneralBean(decorator, manager);
            Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) WeldDecorator(org.jboss.weld.bean.WeldDecorator) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) Instance(javax.enterprise.inject.Instance) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) Event(javax.enterprise.event.Event) Dependent(javax.enterprise.context.Dependent) Provider(javax.inject.Provider)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 WildcardType (java.lang.reflect.WildcardType)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Instance (javax.enterprise.inject.Instance)1 Provider (javax.inject.Provider)1 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1 WeldDecorator (org.jboss.weld.bean.WeldDecorator)1