public class BeanDefinitionHolder implements BeanMetadataElement {
// bean定义
private final BeanDefinition beanDefinition;
// bean名称
private final String beanName;
// 别名数组
@Nullable
private final String[] aliases;
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName) {
this(beanDefinition, beanName, null);
}
// 含有bean定义、bean名称、别名数组三个参数的构造方法
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, @Nullable
String[] aliases) {
Assert.notNull(beanDefinition, "BeanDefinition must not be null");
Assert.notNull(beanName, "Bean name must not be null");
this.beanDefinition = beanDefinition;
this.beanName = beanName;
this.aliases = aliases;
}
// 复制构造函数:使用与给定的BeanDefinitionHolder实例相同的内容。
public BeanDefinitionHolder(BeanDefinitionHolder beanDefinitionHolder) {
Assert.notNull(beanDefinitionHolder, "BeanDefinitionHolder must not be null");
this.beanDefinition = beanDefinitionHolder.getBeanDefinition();
this.beanName = beanDefinitionHolder.getBeanName();
this.aliases = beanDefinitionHolder.getAliases();
}
// 获取bean定义
public BeanDefinition getBeanDefinition() {
return this.beanDefinition;
}
// 获取bean定义的主名称
public String getBeanName() {
return this.beanName;
}
// 获取别名数组
@Nullable
public String[] getAliases() {
return this.aliases;
}
// 获取bean定义的源对象
@Override
@Nullable
public Object getSource() {
return this.beanDefinition.getSource();
}
// 确定给定的候选名称是否与bean名称匹配或存储在此bean定义中的别名
public boolean matchesName(@Nullable String candidateName) {
return (candidateName != null && (candidateName.equals(this.beanName) ||
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
ObjectUtils.containsElement(this.aliases, candidateName)));
}
// 返回bean的友好简短描述,说明名称和别名
public String getShortDescription() {
if (this.aliases == null) {
return "Bean definition with name '" + this.beanName + "'";
}
return "Bean definition with name '" + this.beanName + "' and aliases [" +
StringUtils.arrayToCommaDelimitedString(this.aliases) + ']';
}
// 返回bean的详细描述,包括名称和别名以及所包含的bean定义信息
public String getLongDescription() {
return getShortDescription() + ": " + this.beanDefinition;
}
@Override
public String toString() {
return getLongDescription();
}
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof BeanDefinitionHolder)) {
return false;
}
BeanDefinitionHolder otherHolder = (BeanDefinitionHolder) other;
return this.beanDefinition.equals(otherHolder.beanDefinition) &&
this.beanName.equals(otherHolder.beanName) &&
ObjectUtils.nullSafeEquals(this.aliases, otherHolder.aliases);
}
@Override
public int hashCode() {
int hashCode = this.beanDefinition.hashCode();
hashCode = 29 * hashCode + this.beanName.hashCode();
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.aliases);
return hashCode;
}
}
BeanDefinitionHolder解析
于 2022-11-28 15:09:28 首次发布
关键词由CSDN通过智能技术生成