1 16 17 package org.springframework.beans.factory.parsing; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.springframework.beans.PropertyValue; 23 import org.springframework.beans.PropertyValues; 24 import org.springframework.beans.factory.config.BeanDefinition; 25 import org.springframework.beans.factory.config.BeanDefinitionHolder; 26 import org.springframework.beans.factory.config.BeanReference; 27 28 36 public class BeanComponentDefinition extends BeanDefinitionHolder implements ComponentDefinition { 37 38 private BeanDefinition[] innerBeanDefinitions; 39 40 private BeanReference[] beanReferences; 41 42 43 48 public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName) { 49 super(beanDefinition, beanName); 50 findInnerBeanDefinitionsAndBeanReferences(beanDefinition); 51 } 52 53 58 public BeanComponentDefinition(BeanDefinitionHolder holder) { 59 super(holder); 60 findInnerBeanDefinitionsAndBeanReferences(holder.getBeanDefinition()); 61 } 62 63 64 private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) { 65 List innerBeans = new ArrayList (); 66 List references = new ArrayList (); 67 PropertyValues propertyValues = beanDefinition.getPropertyValues(); 68 for (int i = 0; i < propertyValues.getPropertyValues().length; i++) { 69 PropertyValue propertyValue = propertyValues.getPropertyValues()[i]; 70 Object value = propertyValue.getValue(); 71 if (value instanceof BeanDefinitionHolder) { 72 innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition()); 73 } 74 else if (value instanceof BeanDefinition) { 75 innerBeans.add(value); 76 } 77 else if (value instanceof BeanReference) { 78 references.add(value); 79 } 80 } 81 this.innerBeanDefinitions = (BeanDefinition[]) innerBeans.toArray(new BeanDefinition[innerBeans.size()]); 82 this.beanReferences = (BeanReference[]) references.toArray(new BeanReference[references.size()]); 83 } 84 85 86 public String getName() { 87 return getBeanName(); 88 } 89 90 public String getDescription() { 91 return getShortDescription(); 92 } 93 94 public BeanDefinition[] getBeanDefinitions() { 95 return new BeanDefinition[] {getBeanDefinition()}; 96 } 97 98 public BeanDefinition[] getInnerBeanDefinitions() { 99 return this.innerBeanDefinitions; 100 } 101 102 public BeanReference[] getBeanReferences() { 103 return this.beanReferences; 104 } 105 106 107 111 public String toString() { 112 return getDescription(); 113 } 114 115 119 public boolean equals(Object other) { 120 return (this == other || (other instanceof BeanComponentDefinition && super.equals(other))); 121 } 122 123 } 124 | Popular Tags |