* Configure direct/indirect specialized producer method beans.
*/
public static void configureProducerMethodSpecializations()
{
Method method;
ProducerMethodBean pbean;
ProducerMethodBean pLeft;
ProducerMethodBean pRight;
logger.debug("configure Specialized producer beans has started.");
// collect all producer method beans
Set<Bean<?>> beans = BeanManagerImpl.getManager().getBeans();
List<ProducerMethodBean> producerBeans = new ArrayList<ProducerMethodBean>();
for(Bean b : beans)
{
if (b instanceof ProducerMethodBean)
{
producerBeans.add((ProducerMethodBean)b);
}
}
// create sorted bean helper.
SortedListHelper<ProducerMethodBean> producerBeanListHelper = new
SortedListHelper<ProducerMethodBean>(new ArrayList<ProducerMethodBean>(),
new Comparator<ProducerMethodBean> ()
{
public int compare(ProducerMethodBean e1, ProducerMethodBean e2)
{
if (e1.getBeanClass().isAssignableFrom(e2.getBeanClass()))
{
return -1;
}
else if (e1.equals(e2))
{
return 0;
}
return 1;
}
});
while(true)
{
pbean = null;
method = null;
producerBeanListHelper.clear();
//locate a specialized bean
for(ProducerMethodBean pb : producerBeans)
{
if (pb.isSpecializedBean())
{
pbean = pb;
method = pb.getCreatorMethod();
producerBeanListHelper.add(pb);
break;
}
}
if (pbean == null)
{
break;
}
pRight = pbean;
pLeft = pRight;
boolean pLeftContinue = true;
boolean pRightContinue = true;
// find all pbean's super beans and sub sub beans
while(pLeftContinue || pRightContinue)
{
pRightContinue = false;
pLeftContinue = false;
for(ProducerMethodBean pb : producerBeans)
{
//left
if (pLeft!= null &&
pLeft.getBeanClass().getSuperclass().equals(pb.getBeanClass()))
{
Method superMethod = ClassUtil.getClassMethodWithTypes(pb.getBeanClass(), method.getName(),
Arrays.asList(method.getParameterTypes()));
//Added by GE, method check is necessary otherwise getting wrong method qualifier annotations
if (superMethod != null && superMethod.equals(pb.getCreatorMethod()))
{
producerBeanListHelper.add(pb);
pLeft = (pb.isSpecializedBean()) ? pb : null;
}
else
{
pLeft = null;
}
if (pLeft != null)
{
pLeftContinue = true;
}
}
//right
if (pRight != null &&
pb.getBeanClass().getSuperclass().equals(pRight.getBeanClass()))
{
if (!pb.isSpecializedBean())
{
pRight = null;
}