org.springframework.beans.factory.parsing.ComponentDefinition Java Examples

The following examples show how to use org.springframework.beans.factory.parsing.ComponentDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AopNamespaceHandlerEventTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPointcutEvents() {
	this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);

	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
	PointcutComponentDefinition pcd = null;
	for (ComponentDefinition componentDefinition : nestedComponentDefs) {
		if (componentDefinition instanceof PointcutComponentDefinition) {
			pcd = (PointcutComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("PointcutComponentDefinition not found", pcd);
	assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
}
 
Example #2
Source File: AopNamespaceHandlerEventTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPointcutEvents() {
	this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);

	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
	PointcutComponentDefinition pcd = null;
	for (ComponentDefinition componentDefinition : nestedComponentDefs) {
		if (componentDefinition instanceof PointcutComponentDefinition) {
			pcd = (PointcutComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("PointcutComponentDefinition not found", pcd);
	assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
}
 
Example #3
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public boolean containsComponentDefinition(String name) {
	for (ComponentDefinition cd : this.registeredComponents) {
		if (cd instanceof CompositeComponentDefinition) {
			ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd).getNestedComponents();
			for (ComponentDefinition innerCd : innerCds) {
				if (innerCd.getName().equals(name)) {
					return true;
				}
			}
		}
		else {
			if (cd.getName().equals(name)) {
				return true;
			}
		}
	}
	return false;
}
 
Example #4
Source File: AopNamespaceHandlerEventTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testPointcutEvents() throws Exception {
	this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);

	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
	PointcutComponentDefinition pcd = null;
	for (int i = 0; i < nestedComponentDefs.length; i++) {
		ComponentDefinition componentDefinition = nestedComponentDefs[i];
		if (componentDefinition instanceof PointcutComponentDefinition) {
			pcd = (PointcutComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("PointcutComponentDefinition not found", pcd);
	assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
}
 
Example #5
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
	ManagedList<Object> actions = new ManagedList<Object>(7);
	actions.add(createBeanDefinition(AddAction.class, parserContext));
	actions.add(createBeanDefinition(RefreshAction.class, parserContext));
	actions.add(createBeanDefinition(RemoveAction.class, parserContext));
	actions.add(createBeanDefinition(FindAction.class, parserContext));
	actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));
	
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
	bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	bdb.addPropertyValue("sourceList", actions);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_TABLE_ACTIONS);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #6
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public boolean containsComponentDefinition(String name) {
	for (ComponentDefinition cd : this.registeredComponents) {
		if (cd instanceof CompositeComponentDefinition) {
			ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd).getNestedComponents();
			for (ComponentDefinition innerCd : innerCds) {
				if (innerCd.getName().equals(name)) {
					return true;
				}
			}
		}
		else {
			if (cd.getName().equals(name)) {
				return true;
			}
		}
	}
	return false;
}
 
Example #7
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerAccessorFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ConfigurableControlAccessorFactory.class);
	
	Map<Class<?>, Class<?extends ControlAccessor>> accessors = 
			new ManagedMap<Class<?>,Class<?extends ControlAccessor>>();
	accessors.put(JTextComponent.class, TextComponentAccessor.class);
	accessors.put(JList.class, ListAccessor.class);
	accessors.put(Selector.class, SelectorAccessor.class);
	accessors.put(JToggleButton.class, ToggleButtonAccessor.class);
	accessors.put(JComboBox.class, ComboAccessor.class);
	accessors.put(View.class, ViewAccessor.class);
	accessors.put(JLabel.class, LabelAccessor.class);
	accessors.put(TablePanel.class, TablePanelAccessor.class);
	bdb.addPropertyValue("accessors", accessors);
	
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), ACCESSOR_FACTORY_BEAN_NAME);
	
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #8
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
public boolean containsComponentDefinition(String name) {
	for (ComponentDefinition cd : this.registeredComponents) {
		if (cd instanceof CompositeComponentDefinition) {
			ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd).getNestedComponents();
			for (ComponentDefinition innerCd : innerCds) {
				if (innerCd.getName().equals(name)) {
					return true;
				}
			}
		}
		else {
			if (cd.getName().equals(name)) {
				return true;
			}
		}
	}
	return false;
}
 
Example #9
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
	ManagedList<Object> actions = new ManagedList<Object>(7);
	actions.add(createBeanDefinition(AddAction.class, parserContext));
	actions.add(createBeanDefinition(SelectAllAction.class, parserContext));
	actions.add(createBeanDefinition(DeselectAllAction.class, parserContext));
	actions.add(createBeanDefinition(RemoveAllAction.class, parserContext));
	actions.add(createBeanDefinition(HideShowFilterAction.class, parserContext));
	actions.add(createBeanDefinition(ApplyFilterAction.class, parserContext));
	actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));
	
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
	bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	bdb.addPropertyValue("sourceList", actions);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_TABLE_ACTIONS);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #10
Source File: LoggingContextLoader.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@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());
	}
}
 
Example #11
Source File: UtilNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Register CollectionTableCellRenderer
 * @param element
 * @param parserContext
 * @return
 */
private ComponentDefinition registerCollectionTableCellRenderer(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(CollectionTableCellRenderer.class);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), COLLECTION_TABLE_CELL_RENDERER_BEAN_NAME);
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #13
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerPaginatorView(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(PaginatorView.class);
	bdb.addPropertyValue("pageSizes", "10,20,30,40,50,100,All");
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), PAGINATOR_VIEW_BEAN_NAME);
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #14
Source File: LoggingApplicationContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@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());
	}
}
 
Example #15
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerBinderFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ConfigurableBinderFactory.class);
	bdb.addPropertyReference(ACCESSOR_FACTORY_BEAN_NAME, ACCESSOR_FACTORY_BEAN_NAME);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), BINDER_FACTORY_BEAN_NAME);
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #16
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerPropertyEditors(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			CustomEditorConfigurer.class);
	Map<String, String> map = new HashMap<String, String>();
	map.put("java.awt.Image", "org.jdal.beans.ImagePropertyEditor");
	map.put("javax.swing.Icon", "org.jdal.beans.IconPropertyEditor");
	bdb.addPropertyValue("customEditors", map);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			CUSTOM_EDITOR_CONFIGURER_BEAN_NAME);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #17
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @param element
 * @param parserContext
 * @return
 */
private ComponentDefinition registerDefaultGuiFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ApplicationContextGuiFactory.class);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_GUI_FACTORY);		
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #18
Source File: ParserContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void registerComponent(ComponentDefinition component) {
	CompositeComponentDefinition containingComponent = getContainingComponent();
	if (containingComponent != null) {
		containingComponent.addNestedComponent(component);
	}
	else {
		this.readerContext.fireComponentRegistered(component);
	}
}
 
Example #19
Source File: EventPublicationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @param element
 * @param parserContext
 * @return
 */
@SuppressWarnings("unused")
private ComponentDefinition registerControlInitializer(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			AnnotationControlInitializer.class);
	
	bdb.addPropertyReference(PERSISTENT_SERVICE, PERSISTENT_SERVICE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			CONTROL_INITIALIZER);
	
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #21
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @param element
 * @param parserContext
 * @return
 */
private ComponentDefinition registerDefaultGuiFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ApplicationContextGuiFactory.class);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_GUI_FACTORY);		
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #22
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSourceExtraction() {
	Iterator<ComponentDefinition> iterator = context.getRegisteredComponents();
	while (iterator.hasNext()) {
		ComponentDefinition compDef = iterator.next();
		assertNotNull("CompositeComponentDefinition '" + compDef.getName() + "' has no source attachment", compDef.getSource());
		validateComponentDefinition(compDef);
	}
}
 
Example #23
Source File: AopNamespaceHandlerEventTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvisorEventsWithDirectPointcut() throws Exception {
	this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);

	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
	AdvisorComponentDefinition acd = null;
	for (int i = 0; i < nestedComponentDefs.length; i++) {
		ComponentDefinition componentDefinition = nestedComponentDefs[i];
		if (componentDefinition instanceof AdvisorComponentDefinition) {
			acd = (AdvisorComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("AdvisorComponentDefinition not found", acd);
	assertEquals(2, acd.getBeanDefinitions().length);
	assertEquals(1, acd.getBeanReferences().length);

	assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
	BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
	assertEquals("countingAdvice", adviceDef.getBeanName());
}
 
Example #24
Source File: AopNamespaceHandlerEventTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvisorEventsWithPointcutRef() throws Exception {
	this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);

	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length);
	AdvisorComponentDefinition acd = null;
	for (int i = 0; i < nestedComponentDefs.length; i++) {
		ComponentDefinition componentDefinition = nestedComponentDefs[i];
		if (componentDefinition instanceof AdvisorComponentDefinition) {
			acd = (AdvisorComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("AdvisorComponentDefinition not found", acd);
	assertEquals(1, acd.getBeanDefinitions().length);
	assertEquals(2, acd.getBeanReferences().length);

	assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
	BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
	assertEquals("countingAdvice", adviceDef.getBeanName());
}
 
Example #25
Source File: ParserContext.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
public void registerComponent(ComponentDefinition component) {
	CompositeComponentDefinition containingComponent = getContainingComponent();
	if (containingComponent != null) {
		containingComponent.addNestedComponent(component);
	}
	else {
		this.readerContext.fireComponentRegistered(component);
	}
}
 
Example #26
Source File: ParserContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void registerComponent(ComponentDefinition component) {
	CompositeComponentDefinition containingComponent = getContainingComponent();
	if (containingComponent != null) {
		containingComponent.addNestedComponent(component);
	}
	else {
		this.readerContext.fireComponentRegistered(component);
	}
}
 
Example #27
Source File: ContextDependencyLister.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void componentRegistered(
      ComponentDefinition paramComponentDefinition) {
   String name = paramComponentDefinition.getName();
   
   for(BeanDefinition bd : paramComponentDefinition.getBeanDefinitions()) {
      processBeanDefinition(name, bd);
   }
}
 
Example #28
Source File: UtilNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #29
Source File: EventPublicationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #30
Source File: AopNamespaceHandlerEventTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testAdvisorEventsWithPointcutRef() {
	this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT);
	ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
	assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);

	assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
	CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
	assertEquals("aop:config", compositeDef.getName());

	ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
	assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length);
	AdvisorComponentDefinition acd = null;
	for (int i = 0; i < nestedComponentDefs.length; i++) {
		ComponentDefinition componentDefinition = nestedComponentDefs[i];
		if (componentDefinition instanceof AdvisorComponentDefinition) {
			acd = (AdvisorComponentDefinition) componentDefinition;
			break;
		}
	}
	assertNotNull("AdvisorComponentDefinition not found", acd);
	assertEquals(1, acd.getBeanDefinitions().length);
	assertEquals(2, acd.getBeanReferences().length);

	assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
	BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
	assertEquals("countingAdvice", adviceDef.getBeanName());
}