Asserts.nullCheckForClass(specializedClass);
Bean<?> superBean = null;
Bean<?> specialized = null;
Set<Bean<?>> resolvers = isConfiguredWebBeans(specializedClass, true);
AlternativesManager altManager = webBeansContext.getAlternativesManager();
if (resolvers != null)
{
if(resolvers.isEmpty())
{
throw new InconsistentSpecializationException("Specialized bean for class : " + specializedClass
+ " is not enabled in the deployment.");
}
specialized = resolvers.iterator().next();
if(resolvers.size() > 1)
{
if (!isDirectlySpecializedBeanSet(resolvers))
{
throw new InconsistentSpecializationException("More than one specialized bean for class : "
+ specializedClass + " is enabled in the deployment.");
}
// find the widest bean which satisfies the specializedClass
for( Bean<?> sp : resolvers)
{
if (sp == specialized)
{
continue;
}
if (((AbstractOwbBean<?>)sp).getReturnType().
isAssignableFrom(((AbstractOwbBean<?>)specialized).getReturnType()))
{
specialized = sp;
}
}
}
Class<?> superClass = specializedClass.getSuperclass();
resolvers = isConfiguredWebBeans(superClass,false);
for(Bean<?> candidates : resolvers)
{
AbstractOwbBean<?> candidate = (AbstractOwbBean<?>)candidates;
if(!(candidate instanceof NewBean))
{
if(candidate.getReturnType().equals(superClass))
{
superBean = candidates;
break;
}
}
}
if (superBean != null)
{
// Recursively configure super class first if super class is also a special bean.
// So the name and bean meta data could be populated to this beanclass.
if (beanClasses.contains(superClass) && ((AbstractOwbBean<?>)superBean).isEnabled())
{
configureSpecializations(superClass, beanClasses);
}
if (!AnnotationUtil.hasClassAnnotation(specializedClass, Alternative.class))
{
//disable superbean if the current bean is not an alternative
((AbstractOwbBean<?>)superBean).setEnabled(false);
}
else if(altManager.isClassAlternative(specializedClass))
{
//disable superbean if the current bean is an enabled alternative
((AbstractOwbBean<?>)superBean).setEnabled(false);
}