Search in sources :

Example 1 with DecorableBean

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

the class Validator method validateRIBean.

/**
 * Validate an RIBean. This includes validating whether two beans specialize
 * the same bean
 *
 * @param bean             the bean to validate
 * @param beanManager      the current manager
 * @param specializedBeans the existing specialized beans
 */
protected void validateRIBean(CommonBean<?> bean, BeanManagerImpl beanManager, Collection<CommonBean<?>> specializedBeans) {
    validateGeneralBean(bean, beanManager);
    if (bean instanceof NewBean) {
        return;
    }
    if (bean instanceof DecorableBean) {
        validateDecorators(beanManager, (DecorableBean<?>) bean);
    }
    if ((bean instanceof AbstractClassBean<?>)) {
        AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
        // validate CDI-defined interceptors
        if (classBean.hasInterceptors()) {
            validateInterceptors(beanManager, classBean);
        }
    }
    // for each producer bean validate its disposer method
    if (bean instanceof AbstractProducerBean<?, ?, ?>) {
        AbstractProducerBean<?, ?, ?> producerBean = Reflections.<AbstractProducerBean<?, ?, ?>>cast(bean);
        if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) {
            AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>>cast(producerBean.getProducer());
            if (producer.getDisposalMethod() != null) {
                for (InjectionPoint ip : producer.getDisposalMethod().getInjectionPoints()) {
                    // pass the producer bean instead of the disposal method bean
                    validateInjectionPointForDefinitionErrors(ip, null, beanManager);
                    validateMetadataInjectionPoint(ip, null, ValidatorLogger.INJECTION_INTO_DISPOSER_METHOD);
                    validateEventMetadataInjectionPoint(ip);
                    validateInjectionPointForDeploymentProblems(ip, null, beanManager);
                }
            }
        }
    }
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) DecorableBean(org.jboss.weld.bean.DecorableBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) NewBean(org.jboss.weld.bean.NewBean) AbstractMemberProducer(org.jboss.weld.injection.producer.AbstractMemberProducer)

Example 2 with DecorableBean

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

the class Validator method reallyValidatePseudoScopedBean.

/**
 * checks if a bean has been seen before in the dependencyPath. If not, it
 * resolves the InjectionPoints and adds the resolved beans to the set of
 * beans to be validated
 */
private static void reallyValidatePseudoScopedBean(Bean<?> bean, BeanManagerImpl beanManager, Set<Object> dependencyPath, Set<Bean<?>> validatedBeans) {
    // see if we have already seen this bean in the dependency path
    if (dependencyPath.contains(bean)) {
        // create a list that shows the path to the bean
        List<Object> realDependencyPath = new ArrayList<Object>(dependencyPath);
        realDependencyPath.add(bean);
        throw ValidatorLogger.LOG.pseudoScopedBeanHasCircularReferences(WeldCollections.toMultiRowString(realDependencyPath));
    }
    if (validatedBeans.contains(bean)) {
        return;
    }
    dependencyPath.add(bean);
    for (InjectionPoint injectionPoint : bean.getInjectionPoints()) {
        if (!injectionPoint.isDelegate()) {
            dependencyPath.add(injectionPoint);
            validatePseudoScopedInjectionPoint(injectionPoint, beanManager, dependencyPath, validatedBeans);
            dependencyPath.remove(injectionPoint);
        }
    }
    if (bean instanceof DecorableBean<?>) {
        final List<Decorator<?>> decorators = Reflections.<DecorableBean<?>>cast(bean).getDecorators();
        if (!decorators.isEmpty()) {
            for (final Decorator<?> decorator : decorators) {
                reallyValidatePseudoScopedBean(decorator, beanManager, dependencyPath, validatedBeans);
            }
        }
    }
    if (bean instanceof AbstractProducerBean<?, ?, ?> && !(bean instanceof EEResourceProducerField<?, ?>)) {
        AbstractProducerBean<?, ?, ?> producer = (AbstractProducerBean<?, ?, ?>) bean;
        if (!beanManager.isNormalScope(producer.getDeclaringBean().getScope()) && !producer.getAnnotated().isStatic()) {
            reallyValidatePseudoScopedBean(producer.getDeclaringBean(), beanManager, dependencyPath, validatedBeans);
        }
    }
    validatedBeans.add(bean);
    dependencyPath.remove(bean);
}
Also used : WeldDecorator(org.jboss.weld.bean.WeldDecorator) Decorator(javax.enterprise.inject.spi.Decorator) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ArrayList(java.util.ArrayList) DecorableBean(org.jboss.weld.bean.DecorableBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean)

Aggregations

InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)2 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)2 DecorableBean (org.jboss.weld.bean.DecorableBean)2 ArrayList (java.util.ArrayList)1 Decorator (javax.enterprise.inject.spi.Decorator)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1 NewBean (org.jboss.weld.bean.NewBean)1 WeldDecorator (org.jboss.weld.bean.WeldDecorator)1 AbstractMemberProducer (org.jboss.weld.injection.producer.AbstractMemberProducer)1