// Add referenced beans from bean element
Bean bean = (Bean) element;
// For a child bean add the parent bean
if (bean.isChildBean()) {
IBean parentBean = getBean(bean.getParentName(), context);
if (addBeanReference(BeanType.PARENT, bean, parentBean, context, references, referencedBeans)
&& recursive) {
// Now add all parent beans and all beans which are
// referenced by the parent beans
// The HashSet is used to detect a cycle
Set<String> beanNames = new HashSet<String>();
beanNames.add(bean.getElementName());
beanNames.add(parentBean.getElementName());
while (parentBean != null && parentBean.isChildBean()) {
String parentName = parentBean.getParentName();
if (beanNames.contains(parentName)) {
// break from cycle
break;
}
beanNames.add(parentName);
parentBean = getBean(parentName, context);
if (addBeanReference(BeanType.PARENT, bean, parentBean, context, references, referencedBeans)
&& recursive) {
addBeanReferencesForBean(parentBean, context, recursive, references, referencedBeans);
}
}
}
}
// Get bean's merged or standard bean definition
AbstractBeanDefinition bd;
if (recursive) {
bd = (AbstractBeanDefinition) getMergedBeanDefinition(bean, context);
}
else {
bd = (AbstractBeanDefinition) (bean).getBeanDefinition();
}
// Add bean's factoy bean
if (bd.getFactoryBeanName() != null) {
IBean factoryBean = getBean(bd.getFactoryBeanName(), context);
if (addBeanReference(BeanType.FACTORY, bean, factoryBean, context, references, referencedBeans)
&& recursive) {
addBeanReferencesForBean(factoryBean, context, recursive, references, referencedBeans);
}
}
// Add bean's depends-on beans
if (bd.getDependsOn() != null) {
for (String dependsOnBeanId : bd.getDependsOn()) {
IBean dependsOnBean = getBean(dependsOnBeanId, context);
if (addBeanReference(BeanType.DEPENDS_ON, bean, dependsOnBean, context, references, referencedBeans)
&& recursive) {
addBeanReferencesForBean(dependsOnBean, context, recursive, references, referencedBeans);
}
}
}
// Add beans from bean's MethodOverrides
if (!bd.getMethodOverrides().isEmpty()) {
for (Object methodOverride : bd.getMethodOverrides().getOverrides()) {
if (methodOverride instanceof LookupOverride) {
String beanName = ((LookupOverride) methodOverride).getBeanName();
IBean overrideBean = getBean(beanName, context);
if (addBeanReference(BeanType.METHOD_OVERRIDE, bean, overrideBean, context, references,
referencedBeans) && recursive) {
addBeanReferencesForBean(overrideBean, context, recursive, references, referencedBeans);
}
}
else if (methodOverride instanceof ReplaceOverride) {
String beanName = ((ReplaceOverride) methodOverride).getMethodReplacerBeanName();
IBean overrideBean = getBean(beanName, context);
if (addBeanReference(BeanType.METHOD_OVERRIDE, bean, overrideBean, context, references,
referencedBeans) && recursive) {
addBeanReferencesForBean(overrideBean, context, recursive, references, referencedBeans);
}
}