org.springframework.beans.factory.parsing.ComponentDefinition#getBeanDefinitions ( )源码实例Demo

下面列出了org.springframework.beans.factory.parsing.ComponentDefinition#getBeanDefinitions ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void beanEventReceived() throws Exception {
	ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
	assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Rob Harrop"),
			beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertEquals(1, componentDefinition1.getBeanReferences().length);
	assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
	assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
	BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("ACME"),
			innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertTrue(componentDefinition1.getSource() instanceof Element);

	ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
	assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Juergen Hoeller"),
			beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
	assertEquals(0, componentDefinition2.getBeanReferences().length);
	assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
	BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Eva Schallmeiner"),
			innerBd2.getPropertyValues().getPropertyValue("name").getValue());
	assertTrue(componentDefinition2.getSource() instanceof Element);
}
 
@Test
public void testEvents() {
	ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties");
	assertNotNull("Event for 'myProperties' not sent", propertiesComponent);
	AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass());

	ComponentDefinition constantComponent = this.listener.getComponentDefinition("min");
	assertNotNull("Event for 'min' not sent", propertiesComponent);
	AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass());
}
 
@Test
public void beanEventReceived() throws Exception {
	ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
	assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Rob Harrop"),
			beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertEquals(1, componentDefinition1.getBeanReferences().length);
	assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
	assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
	BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("ACME"),
			innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertTrue(componentDefinition1.getSource() instanceof Element);

	ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
	assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Juergen Hoeller"),
			beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
	assertEquals(0, componentDefinition2.getBeanReferences().length);
	assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
	BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Eva Schallmeiner"),
			innerBd2.getPropertyValues().getPropertyValue("name").getValue());
	assertTrue(componentDefinition2.getSource() instanceof Element);
}
 
@Test
public void testEvents() {
	ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties");
	assertNotNull("Event for 'myProperties' not sent", propertiesComponent);
	AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass());

	ComponentDefinition constantComponent = this.listener.getComponentDefinition("min");
	assertNotNull("Event for 'min' not sent", propertiesComponent);
	AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass());
}
 
public void componentRegistered(
      ComponentDefinition paramComponentDefinition) {
   String name = paramComponentDefinition.getName();
   
   for(BeanDefinition bd : paramComponentDefinition.getBeanDefinitions()) {
      processBeanDefinition(name, bd);
   }
}
 
@Test
public void beanEventReceived() throws Exception {
	ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
	assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Rob Harrop"),
			beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertEquals(1, componentDefinition1.getBeanReferences().length);
	assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
	assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
	BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("ACME"),
			innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertTrue(componentDefinition1.getSource() instanceof Element);

	ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
	assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Juergen Hoeller"),
			beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
	assertEquals(0, componentDefinition2.getBeanReferences().length);
	assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
	BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Eva Schallmeiner"),
			innerBd2.getPropertyValues().getPropertyValue("name").getValue());
	assertTrue(componentDefinition2.getSource() instanceof Element);
}
 
@Test
public void testEvents() {
	ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties");
	assertNotNull("Event for 'myProperties' not sent", propertiesComponent);
	AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass());

	ComponentDefinition constantComponent = this.listener.getComponentDefinition("min");
	assertNotNull("Event for 'min' not sent", propertiesComponent);
	AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass());
}
 
@Override
public void componentRegistered(ComponentDefinition componentDefinition) {
	log.info("Registered component [" + componentDefinition.getName() + "]");
	for (BeanDefinition bd : componentDefinition.getBeanDefinitions()) {
		String name = bd.getBeanClassName();
		if (bd instanceof BeanComponentDefinition) {
			name = ((BeanComponentDefinition) bd).getBeanName();
		}
		log.info("Registered bean definition: [" + name + "]" + " from " + bd.getResourceDescription());
	}
}
 
@Override
public void componentRegistered(ComponentDefinition componentDefinition) {
	log.info("Registered component [" + componentDefinition.getName() + "]");
	for (BeanDefinition bd : componentDefinition.getBeanDefinitions()) {
		String name = bd.getBeanClassName();
		if (bd instanceof BeanComponentDefinition) {
			name = ((BeanComponentDefinition) bd).getBeanName();
		}
		log.info("Registered bean definition: [" + name + "]" + " from " + bd.getResourceDescription());
	}
}
 
private void validateComponentDefinition(ComponentDefinition compDef) {
	BeanDefinition[] beanDefs = compDef.getBeanDefinitions();
	for (BeanDefinition beanDef : beanDefs) {
		assertNotNull("BeanDefinition has no source attachment", beanDef.getSource());
	}
}
 
private void validateComponentDefinition(ComponentDefinition compDef) {
	BeanDefinition[] beanDefs = compDef.getBeanDefinitions();
	for (BeanDefinition beanDef : beanDefs) {
		assertNotNull("BeanDefinition has no source attachment", beanDef.getSource());
	}
}
 
private void validateComponentDefinition(ComponentDefinition compDef) {
	BeanDefinition[] beanDefs = compDef.getBeanDefinitions();
	for (BeanDefinition beanDef : beanDefs) {
		assertNotNull("BeanDefinition has no source attachment", beanDef.getSource());
	}
}