private void defineQualifiers()

in webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java [207:273]


    private void defineQualifiers(Annotated annotated, Set<Class<? extends Annotation>> qualifiedTypes)
    {
        Annotation[] annotations = AnnotationUtil.asArray(annotated.getAnnotations());
        AnnotationManager annotationManager = webBeansContext.getAnnotationManager();

        for (Annotation annotation : annotations)
        {
            Class<? extends Annotation> type = annotation.annotationType();

            if (annotationManager.isQualifierAnnotation(type))
            {
                annotationManager.checkQualifierConditions(annotation);

                if (qualifiedTypes.contains(annotation.annotationType()) && !isRepetable(annotated, annotation))
                {
                    continue;
                }
                else
                {
                    qualifiedTypes.add(annotation.annotationType());
                }
                if (annotation.annotationType().equals(Named.class) && name != null)
                {
                    qualifiers.add(new NamedLiteral(name));
                }
                else
                {
                    qualifiers.add(annotation);
                }
            }
        }
        
        // No-binding annotation
        if (qualifiers.isEmpty())
        {
            qualifiers.add(DefaultLiteral.INSTANCE);
        }
        else if (qualifiers.size() == 1)
        {
            // section 2.3.1
            // If a bean does not explicitly declare a qualifier other than @Named or @Any,
            // the bean has exactly one additional qualifier, of type @Default.
            Annotation annot = qualifiers.iterator().next();
            if(annot.annotationType().equals(Named.class) || annot.annotationType().equals(Any.class))
            {
                qualifiers.add(DefaultLiteral.INSTANCE);
            }
        }
        else if (qualifiers.size() == 2)
        {
            Iterator<Annotation> qualiIt = qualifiers.iterator();
            Class<? extends Annotation> q1 = qualiIt.next().annotationType();
            Class<? extends Annotation> q2 = qualiIt.next().annotationType();
            if (q1.equals(Named.class) && q2.equals(Any.class) ||
                q2.equals(Named.class) && q1.equals(Any.class) )
            {
                qualifiers.add(DefaultLiteral.INSTANCE);
            }
        }

        //Add @Any support
        if(!hasAnyQualifier())
        {
            qualifiers.add(AnyLiteral.INSTANCE);
        }
        
    }