@SuppressWarnings("unchecked") public Set<Annotation> getQualifiers( BeanManager beanManager, GenericIdentifier identifier, Iterable<Annotation> annotations) { return Beans.getQualifiers( beanManager, genericConfigurationPoints.get(identifier).getAnnotated().getAnnotations(), annotations); }
void createGenericBeans(@Observes AfterBeanDiscovery event, BeanManager beanManager) { beanDiscoveryOver = true; // For each generic configuration type, we iterate the generic configurations for (Entry<GenericIdentifier, GenericConfigurationHolder> genericConfigurationEntry : genericConfigurationPoints.entrySet()) { Class<? extends Annotation> producerScope = Dependent.class; for (Annotation annotation : genericConfigurationEntry.getValue().getAnnotated().getAnnotations()) { if (beanManager.isScope(annotation.annotationType())) { producerScope = annotation.annotationType(); } } GenericConfigurationHolder genericConfigurationHolder = genericConfigurationEntry.getValue(); GenericIdentifier identifier = genericConfigurationEntry.getKey(); Class<? extends Annotation> genericConfigurationType = identifier.getAnnotationType(); if (!genericBeans.containsKey(genericConfigurationType)) { throw new IllegalStateException( "No generic bean definition exists for " + genericConfigurationType + ", but a generic producer does: " + genericConfigurationHolder.getAnnotated()); } // Add a generic configuration bean for each generic configuration producer (allows us to // inject the generic configuration annotation back into the generic bean) event.addBean(createGenericConfigurationBean(beanManager, identifier)); // Register the GenericProduct bean event.addBean(createGenericProductAnnotatedMemberBean(beanManager, identifier)); boolean alternative = genericConfigurationHolder.getAnnotated().isAnnotationPresent(Alternative.class); Class<?> javaClass = genericConfigurationHolder.getJavaClass(); if (genericBeanProducerMethods.containsKey(genericConfigurationType)) { for (ProducerMethodHolder<?, ?> holder : genericBeanProducerMethods.get(genericConfigurationType)) { Class<? extends Annotation> scopeOverride = null; if (holder.getProducerMethod().isAnnotationPresent(ApplyScope.class)) { scopeOverride = producerScope; } event.addBean( createGenericProducerMethod( holder, identifier, beanManager, scopeOverride, alternative, javaClass)); } } if (genericBeanProducerFields.containsKey(genericConfigurationType)) { for (FieldHolder<?, ?> holder : genericBeanProducerFields.get(genericConfigurationType)) { Class<? extends Annotation> scopeOverride = null; if (holder.getField().isAnnotationPresent(ApplyScope.class)) { scopeOverride = producerScope; } event.addBean( createGenericProducerField( holder.getBean(), identifier, holder.getField(), beanManager, scopeOverride, alternative, javaClass)); } } if (genericBeanObserverMethods.containsKey(genericConfigurationType)) { for (ObserverMethodHolder<?, ?> holder : genericBeanObserverMethods.get(genericConfigurationType)) { event.addObserverMethod( createGenericObserverMethod( holder.getObserverMethod(), identifier, holder.getMethod(), null, beanManager)); } } if (unwrapsMethods.containsKey(genericConfigurationType)) { for (AnnotatedMethod<?> i : unwrapsMethods.get(genericConfigurationType)) { Annotated annotated = genericConfigurationHolder.getAnnotated(); Set<Annotation> unwrapsQualifiers = Beans.getQualifiers(beanManager, i.getAnnotations(), annotated.getAnnotations()); if (unwrapsQualifiers.isEmpty()) { unwrapsQualifiers.add(DefaultLiteral.INSTANCE); } Set<Annotation> beanQualifiers = Beans.getQualifiers( beanManager, i.getDeclaringType().getAnnotations(), annotated.getAnnotations()); beanQualifiers.remove(AnyLiteral.INSTANCE); if (beanQualifiers.isEmpty()) { beanQualifiers.add(DefaultLiteral.INSTANCE); } beanQualifiers.remove(genericBeanQualifier); event.addBean(new UnwrapsProducerBean(i, unwrapsQualifiers, beanQualifiers, beanManager)); } } // For each generic bean that uses this genericConfigurationType, register a generic bean for // this generic configuration for (BeanHolder<?> genericBeanHolder : genericBeans.get(genericConfigurationType)) { // Register the generic bean, this is the underlying definition, with the synthetic // qualifier Class<? extends Annotation> scopeOverride = null; if (genericBeanHolder.getType().isAnnotationPresent(ApplyScope.class)) { scopeOverride = producerScope; } Bean<?> genericBean = createGenericBean( genericBeanHolder, identifier, beanManager, scopeOverride, alternative, javaClass); event.addBean(genericBean); } } }