java annotation评价_Java Annotation.equals方法代码示例

import java.lang.annotation.Annotation; //导入方法依赖的package包/类

/**

* Match the given qualifier annotation against the candidate bean definition.

*/

protected boolean checkQualifier(

BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter) {

Class extends Annotation> type = annotation.annotationType();

RootBeanDefinition bd = (RootBeanDefinition) bdHolder.getBeanDefinition();

AutowireCandidateQualifier qualifier = bd.getQualifier(type.getName());

if (qualifier == null) {

qualifier = bd.getQualifier(ClassUtils.getShortName(type));

}

if (qualifier == null) {

// First, check annotation on factory method, if applicable

Annotation targetAnnotation = getFactoryMethodAnnotation(bd, type);

if (targetAnnotation == null) {

RootBeanDefinition dbd = getResolvedDecoratedDefinition(bd);

if (dbd != null) {

targetAnnotation = getFactoryMethodAnnotation(dbd, type);

}

}

if (targetAnnotation == null) {

// Look for matching annotation on the target class

if (getBeanFactory() != null) {

Class> beanType = getBeanFactory().getType(bdHolder.getBeanName());

if (beanType != null) {

targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);

}

}

if (targetAnnotation == null && bd.hasBeanClass()) {

targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(bd.getBeanClass()), type);

}

}

if (targetAnnotation != null && targetAnnotation.equals(annotation)) {

return true;

}

}

Map attributes = AnnotationUtils.getAnnotationAttributes(annotation);

if (attributes.isEmpty() && qualifier == null) {

// If no attributes, the qualifier must be present

return false;

}

for (Map.Entry entry : attributes.entrySet()) {

String attributeName = entry.getKey();

Object expectedValue = entry.getValue();

Object actualValue = null;

// Check qualifier first

if (qualifier != null) {

actualValue = qualifier.getAttribute(attributeName);

}

if (actualValue == null) {

// Fall back on bean definition attribute

actualValue = bd.getAttribute(attributeName);

}

if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) &&

expectedValue instanceof String && bdHolder.matchesName((String) expectedValue)) {

// Fall back on bean name (or alias) match

continue;

}

if (actualValue == null && qualifier != null) {

// Fall back on default, but only if the qualifier is present

actualValue = AnnotationUtils.getDefaultValue(annotation, attributeName);

}

if (actualValue != null) {

actualValue = typeConverter.convertIfNecessary(actualValue, expectedValue.getClass());

}

if (!expectedValue.equals(actualValue)) {

return false;

}

}

return true;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值