当前位置: 首页>>代码示例>>Java>>正文


Java ResolvableType.isInstance方法代码示例

本文整理汇总了Java中org.springframework.core.ResolvableType.isInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ResolvableType.isInstance方法的具体用法?Java ResolvableType.isInstance怎么用?Java ResolvableType.isInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.ResolvableType的用法示例。


在下文中一共展示了ResolvableType.isInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBeanNamesForType

import org.springframework.core.ResolvableType; //导入方法依赖的package包/类
@Override
public String[] getBeanNamesForType(ResolvableType type) {
	boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type.getRawClass()));
	List<String> matches = new ArrayList<String>();
	for (Map.Entry<String, Object> entry : this.beans.entrySet()) {
		String name = entry.getKey();
		Object beanInstance = entry.getValue();
		if (beanInstance instanceof FactoryBean && !isFactoryType) {
			Class<?> objectType = ((FactoryBean<?>) beanInstance).getObjectType();
			if (objectType != null && (type == null || type.isAssignableFrom(objectType))) {
				matches.add(name);
			}
		}
		else {
			if (type == null || type.isInstance(beanInstance)) {
				matches.add(name);
			}
		}
	}
	return StringUtils.toStringArray(matches);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:StaticListableBeanFactory.java

示例2: isTypeMatch

import org.springframework.core.ResolvableType; //导入方法依赖的package包/类
@Override
public boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	// Check manually registered singletons.
	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			if (!BeanFactoryUtils.isFactoryDereference(name)) {
				Class<?> type = getTypeForFactoryBean((FactoryBean<?>) beanInstance);
				return (type != null && typeToMatch.isAssignableFrom(type));
			}
			else {
				return typeToMatch.isInstance(beanInstance);
			}
		}
		else {
			return (!BeanFactoryUtils.isFactoryDereference(name) && typeToMatch.isInstance(beanInstance));
		}
	}
	else if (containsSingleton(beanName) && !containsBeanDefinition(beanName)) {
		// null instance registered
		return false;
	}

	else {
		// No singleton instance found -> check bean definition.
		BeanFactory parentBeanFactory = getParentBeanFactory();
		if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
			// No bean definition found in this factory -> delegate to parent.
			return parentBeanFactory.isTypeMatch(originalBeanName(name), typeToMatch);
		}

		// Retrieve corresponding bean definition.
		RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

		Class<?> classToMatch = typeToMatch.getRawClass();
		Class<?>[] typesToMatch = (FactoryBean.class == classToMatch ?
				new Class<?>[] {classToMatch} : new Class<?>[] {FactoryBean.class, classToMatch});

		// Check decorated bean definition, if any: We assume it'll be easier
		// to determine the decorated bean's type than the proxy's type.
		BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
		if (dbd != null && !BeanFactoryUtils.isFactoryDereference(name)) {
			RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd);
			Class<?> targetClass = predictBeanType(dbd.getBeanName(), tbd, typesToMatch);
			if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) {
				return typeToMatch.isAssignableFrom(targetClass);
			}
		}

		Class<?> beanType = predictBeanType(beanName, mbd, typesToMatch);
		if (beanType == null) {
			return false;
		}

		// Check bean class whether we're dealing with a FactoryBean.
		if (FactoryBean.class.isAssignableFrom(beanType)) {
			if (!BeanFactoryUtils.isFactoryDereference(name)) {
				// If it's a FactoryBean, we want to look at what it creates, not the factory class.
				beanType = getTypeForFactoryBean(beanName, mbd);
				if (beanType == null) {
					return false;
				}
			}
		}
		else if (BeanFactoryUtils.isFactoryDereference(name)) {
			// Special case: A SmartInstantiationAwareBeanPostProcessor returned a non-FactoryBean
			// type but we nevertheless are being asked to dereference a FactoryBean...
			// Let's check the original bean class and proceed with it if it is a FactoryBean.
			beanType = predictBeanType(beanName, mbd, FactoryBean.class);
			if (beanType == null || !FactoryBean.class.isAssignableFrom(beanType)) {
				return false;
			}
		}

		return typeToMatch.isAssignableFrom(beanType);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:80,代码来源:AbstractBeanFactory.java


注:本文中的org.springframework.core.ResolvableType.isInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。