Search in sources :

Example 1 with DecoratorImpl

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

the class Validator method validateDecorators.

private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> bean) {
    if (!(beanManager.isPassivatingScope(bean.getScope()) || bean instanceof AbstractDecorableBuiltInBean<?>)) {
        return;
    }
    List<Decorator<?>> decorators = bean.getDecorators();
    if (decorators.isEmpty()) {
        return;
    }
    for (Decorator<?> decorator : decorators) {
        if (!Decorators.isPassivationCapable(decorator)) {
            if (bean instanceof AbstractDecorableBuiltInBean<?>) {
                throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, bean);
            } else {
                throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator);
            }
        }
        if (decorator instanceof DecoratorImpl) {
            beanManager = ((DecoratorImpl<?>) decorator).getBeanManager();
        }
        for (InjectionPoint ij : decorator.getInjectionPoints()) {
            if (!ij.isDelegate()) {
                Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
                validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean);
            }
        }
    }
}
Also used : WeldDecorator(org.jboss.weld.bean.WeldDecorator) Decorator(javax.enterprise.inject.spi.Decorator) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) AbstractDecorableBuiltInBean(org.jboss.weld.bean.builtin.AbstractDecorableBuiltInBean)

Example 2 with DecoratorImpl

use of org.jboss.weld.bean.DecoratorImpl 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)

Example 3 with DecoratorImpl

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

the class WeldStartup method endInitialization.

public void endInitialization() {
    tracker.start(Tracker.OP_END_INIT);
    final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class);
    if (index != null) {
        // Build a special index of bean identifiers
        index.build(getBeansForBeanIdentifierIndex());
    }
    // Register the managers so external requests can handle them
    // clear the TypeSafeResolvers, so data that is only used at startup
    // is not kept around using up memory
    flushCaches();
    deploymentManager.getServices().cleanupAfterBoot();
    deploymentManager.cleanupAfterBoot();
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        BeanManagerImpl beanManager = beanDeployment.getBeanManager();
        beanManager.getInterceptorMetadataReader().cleanAfterBoot();
        beanManager.getServices().cleanupAfterBoot();
        beanManager.cleanupAfterBoot();
        // clean up beans
        for (Bean<?> bean : beanManager.getBeans()) {
            if (bean instanceof RIBean<?>) {
                RIBean<?> riBean = (RIBean<?>) bean;
                riBean.cleanupAfterBoot();
            }
        }
        // clean up decorators
        for (Decorator<?> decorator : beanManager.getDecorators()) {
            if (decorator instanceof DecoratorImpl<?>) {
                Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot();
            }
        }
        // clean up interceptors
        for (Interceptor<?> interceptor : beanManager.getInterceptors()) {
            if (interceptor instanceof InterceptorImpl<?>) {
                Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot();
            }
        }
    }
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        beanDeployment.getBeanDeployer().cleanup();
    }
    // feed BeanDeploymentModule registry
    final BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class);
    if (modules != null) {
        modules.processBeanDeployments(getBeanDeployments());
        BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
    }
    getContainer().setState(ContainerState.INITIALIZED);
    if (modules != null) {
        // web modules are handled by HttpContextLifecycle
        for (BeanDeploymentModule module : modules) {
            if (!module.isWebModule()) {
                module.fireEvent(Object.class, ContextEvent.APPLICATION_INITIALIZED, InitializedLiteral.APPLICATION);
            }
        }
    }
    tracker.close();
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) RIBean(org.jboss.weld.bean.RIBean) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Aggregations

DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)3 WeldDecorator (org.jboss.weld.bean.WeldDecorator)2 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 Decorator (javax.enterprise.inject.spi.Decorator)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Provider (javax.inject.Provider)1 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)1 InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)1 RIBean (org.jboss.weld.bean.RIBean)1 AbstractDecorableBuiltInBean (org.jboss.weld.bean.builtin.AbstractDecorableBuiltInBean)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)1