1 16 17 package org.springframework.beans.factory.config; 18 19 import org.springframework.beans.BeanMetadataElement; 20 import org.springframework.util.Assert; 21 import org.springframework.util.ObjectUtils; 22 import org.springframework.util.StringUtils; 23 24 38 public class BeanDefinitionHolder implements BeanMetadataElement { 39 40 private final BeanDefinition beanDefinition; 41 42 private final String beanName; 43 44 private final String [] aliases; 45 46 47 52 public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName) { 53 this(beanDefinition, beanName, null); 54 } 55 56 62 public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String [] aliases) { 63 Assert.notNull(beanDefinition, "BeanDefinition must not be null"); 64 Assert.notNull(beanName, "Bean name must not be null"); 65 this.beanDefinition = beanDefinition; 66 this.beanName = beanName; 67 this.aliases = aliases; 68 } 69 70 77 public BeanDefinitionHolder(BeanDefinitionHolder beanDefinitionHolder) { 78 Assert.notNull(beanDefinitionHolder, "BeanDefinitionHolder must not be null"); 79 this.beanDefinition = beanDefinitionHolder.getBeanDefinition(); 80 this.beanName = beanDefinitionHolder.getBeanName(); 81 this.aliases = beanDefinitionHolder.getAliases(); 82 } 83 84 85 88 public BeanDefinition getBeanDefinition() { 89 return this.beanDefinition; 90 } 91 92 95 public String getBeanName() { 96 return this.beanName; 97 } 98 99 103 public String [] getAliases() { 104 return this.aliases; 105 } 106 107 111 public Object getSource() { 112 return this.beanDefinition.getSource(); 113 } 114 115 116 121 public String getShortDescription() { 122 StringBuffer sb = new StringBuffer (); 123 sb.append("Bean definition with name '").append(this.beanName).append("'"); 124 if (this.aliases != null) { 125 sb.append(" and aliases [").append(StringUtils.arrayToCommaDelimitedString(this.aliases)).append("]"); 126 } 127 return sb.toString(); 128 } 129 130 136 public String getLongDescription() { 137 StringBuffer sb = new StringBuffer (getShortDescription()); 138 sb.append(": ").append(this.beanDefinition); 139 return sb.toString(); 140 } 141 142 148 public String toString() { 149 return getLongDescription(); 150 } 151 152 153 public boolean equals(Object other) { 154 if (this == other) { 155 return true; 156 } 157 if (!(other instanceof BeanDefinitionHolder)) { 158 return false; 159 } 160 BeanDefinitionHolder otherHolder = (BeanDefinitionHolder) other; 161 return this.beanDefinition.equals(otherHolder.beanDefinition) && 162 this.beanName.equals(otherHolder.beanName) && 163 ObjectUtils.nullSafeEquals(this.aliases, otherHolder.aliases); 164 } 165 166 public int hashCode() { 167 int hashCode = this.beanDefinition.hashCode(); 168 hashCode = 29 * hashCode + this.beanName.hashCode(); 169 hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.aliases); 170 return hashCode; 171 } 172 173 } 174 | Popular Tags |