private void defineDefaultScope()

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


    private void defineDefaultScope(String exceptionMessage, boolean onlyScopedBeans)
    {
        if (scope == null)
        {
            Set<Class<? extends Annotation>> stereos = stereotypes;
            if (stereos != null && stereos.size() >  0)
            {
                Annotation defined = null;
                Set<Class<? extends Annotation>> anns = stereotypes;
                for (Class<? extends Annotation> stero : anns)
                {
                    boolean containsNormal = AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class);
                    
                    if (AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class) ||
                            AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), Scope.class))
                    {                        
                        Annotation next;
                        
                        if(containsNormal)
                        {
                            next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), NormalScope.class)[0];
                        }
                        else
                        {
                            next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), Scope.class)[0];
                        }

                        if (defined == null)
                        {
                            defined = next;
                        }
                        else
                        {
                            if (!defined.equals(next))
                            {
                                throw new WebBeansConfigurationException(exceptionMessage);
                            }
                        }
                    }
                }

                if (defined != null)
                {
                    scope = defined.annotationType();
                }
                else
                {
                    scope = Dependent.class;
                }
            }
            if (scope == null)
            {
                if (annotated instanceof AnnotatedType)
                {
                    Constructor<Object> defaultCt = webBeansContext.getWebBeansUtil().getNoArgConstructor(((AnnotatedType) annotated).getJavaClass());
                    if (defaultCt != null && Modifier.isPrivate(defaultCt.getModifiers()))
                    {
                        // basically ignore this class by not adding a scope
                        return;
                    }
                }
            }
            if (scope == null &&
                (!onlyScopedBeans ||
                 annotated.getAnnotation(Interceptor.class) != null ||
                 annotated.getAnnotation(Decorator.class) != null))
            {
                // only add a 'default' Dependent scope
                // * if it's not in a bean-discovery-mode='scoped' module, or
                // * if it's a Decorator or Interceptor
                scope = Dependent.class;
            }

        }
    }