* Used to get all beans matching a ResolvableType from the
* {@link com.foreach.across.core.context.registry.AcrossContextBeanRegistry}.
*/
@Override
protected boolean checkGenericTypeMatch( BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor ) {
ResolvableType dependencyType = descriptor.getResolvableType();
ResolvableType targetType = null;
RootBeanDefinition rbd = null;
if ( bdHolder.getBeanDefinition() instanceof RootBeanDefinition ) {
rbd = (RootBeanDefinition) bdHolder.getBeanDefinition();
}
if ( rbd != null ) {
// First, check factory method return type, if applicable
targetType = getReturnTypeForFactoryMethod( rbd, descriptor );
if ( targetType == null ) {
RootBeanDefinition dbd = getResolvedDecoratedDefinition( rbd );
if ( dbd != null ) {
targetType = getReturnTypeForFactoryMethod( dbd, descriptor );
}
}
}
if ( targetType == null ) {
// Regular case: straight bean instance, with BeanFactory available.
if ( getBeanFactory() != null ) {
Class<?> beanType = getBeanFactory().getType( bdHolder.getBeanName() );
if ( beanType != null ) {
targetType = ResolvableType.forClass( ClassUtils.getUserClass( beanType ) );
}
}
// Fallback: no BeanFactory set, or no type resolvable through it
// -> best-effort match against the target class if applicable.
if ( targetType == null && rbd != null && rbd.hasBeanClass() && rbd.getFactoryMethodName() == null ) {
Class<?> beanClass = rbd.getBeanClass();
if ( !FactoryBean.class.isAssignableFrom( beanClass ) ) {
targetType = ResolvableType.forClass( ClassUtils.getUserClass( beanClass ) );
}
}
}
if ( targetType == null || ( descriptor.fallbackMatchAllowed() && targetType.hasUnresolvableGenerics() ) ) {
return true;
}
// Full check for complex generic type match...
return dependencyType.isAssignableFrom( targetType );
}