in webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java [77:165]
public void removeDisabledBeanAttributes(Map<BeanArchiveService.BeanArchiveInformation, Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>>> beanAttributesPerBda,
BeanAttributesProvider attributeProvider,
boolean notSpecializationOnly)
{
Set<AnnotatedType<?>> allAnnotatedTypes = getAllAnnotatedTypes(beanAttributesPerBda);
if (allAnnotatedTypes != null && !allAnnotatedTypes.isEmpty())
{
// superClassList is used to handle the case: Car, CarToyota, Bus, SchoolBus, CarFord
// for which case OWB should throw exception that both CarToyota and CarFord are
// specialize Car.
// see spec section 5.1.3
Set<Class<?>> superClassList = new HashSet<>();
// first let's find all superclasses of Specialized types
Set<Class<?>> disabledClasses = new HashSet<>();
for(AnnotatedType<?> annotatedType : allAnnotatedTypes)
{
if(annotatedType.getAnnotation(Specializes.class) != null && isEnabled(annotatedType))
{
Class<?> specialClass = annotatedType.getJavaClass();
Class<?> superClass = specialClass.getSuperclass();
if (ejbPlugin != null && ejbPlugin.isSessionBean(superClass) && !ejbPlugin.isSessionBean(specialClass))
{
throw new WebBeansConfigurationException(specialClass + " specializes and EJB " + superClass + ". That's forbidden.");
}
if (attributeProvider != null)
{
BeanAttributes<?> ba = attributeProvider.get(annotatedType);
if (ba == null || !ba.getTypes().contains(superClass))
{
throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specializes class " + specialClass.getName()
+ " does not extend a bean with a valid bean constructor - removed with ProcessBeanAttribute"));
}
}
if(superClass.equals(Object.class))
{
throw new WebBeansDeploymentException(new WebBeansConfigurationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0003)
+ specialClass.getName() + WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0004)));
}
if (superClassList.contains(superClass))
{
// since CDI 1.1 we have to wrap this in a DeploymentException
throw new WebBeansDeploymentException(new InconsistentSpecializationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0005) +
superClass.getName()));
}
if (!containsAllSuperclassTypes(annotatedType, superClass, allAnnotatedTypes))
{
throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specialized Class : " + specialClass.getName()
+ " must have all bean types of its super class"));
}
AnnotatedType<?> superType = getAnnotatedTypeForClass(allAnnotatedTypes, superClass);
if (notSpecializationOnly)
{
if ((superType == null && !webBeansContext.findMissingAnnotatedType(superClass)) || (superType != null && !webBeansUtil.isConstructorOk(superType)))
{
throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specializes class " + specialClass.getName()
+ " does not extend a bean with a valid bean constructor"));
}
try
{
webBeansUtil.checkManagedBean(specialClass);
}
catch (WebBeansConfigurationException illegalBeanTypeException)
{
// this Exception gets thrown if the given class is not a valid bean type
throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specializes class " + specialClass.getName()
+ " does not extend a valid bean type", illegalBeanTypeException));
}
}
superClassList.add(superClass);
while (!superClass.equals(Object.class))
{
disabledClasses.add(superClass);
superClass = superClass.getSuperclass();
}
}
}
// and now remove all AnnotatedTypes of those collected disabledClasses
removeAllDisabledClasses(beanAttributesPerBda, disabledClasses);
}
}