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 (sp.getTypes().size() > specialized.getTypes().size() && sp.getTypes().containsAll(specialized.getTypes()))
{
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)
{
for (Class<?> beanClass: beanClasses)
{
if (beanClass.equals(specializedClass))
{
continue;
}
if (beanClass.getSuperclass().equals(superClass))
{
InconsistentSpecializationException exception = new InconsistentSpecializationException(superClass.getName()
+ " is @Specialized by two classes: " + beanClass.getName() + " and " + specializedClass.getName());
throw new WebBeansDeploymentException(exception);
}
}
if (!specialized.getTypes().containsAll(superBean.getTypes()))
{
throw new DefinitionException("@Specialized Class : " + specializedClass.getName()
+ " must have all bean types of its super class");
}
webBeansContext.getBeanManagerImpl().getNotificationManager().disableOverriddenObservers(specializedClass);
// 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);
}
AbstractOwbBean<?> comp = (AbstractOwbBean<?>)specialized;
if (comp.isSpecializedBean())
{
// This comp is already configured in previous invocation
// return directly, else Exception might be fired when set
// bean name again.
return;
}
//Check types of the beans
if(comp.getClass() != superBean.getClass())
{
throw new InconsistentSpecializationException("@Specialized Class : " + specializedClass.getName()
+ " and its super class may be the same type of bean,i.e, ManagedBean, SessionBean etc.");
}
if(superBean.getName() != null)
{
if (!superBean.getName().equals(comp.getName()))
{
throw new InconsistentSpecializationException("@Specialized Class : " + specializedClass.getName()
+ " may not explicitly declare a bean name");
}
}
comp.setSpecializedBean(true);