Java Code Examples for org.springframework.beans.factory.parsing.CompositeComponentDefinition

The following examples show how to use org.springframework.beans.factory.parsing.CompositeComponentDefinition. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 2
@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
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example 4
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example 5
Source Project: spring-analysis-note   Source File: JmsNamespaceHandlerTests.java    License: 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 6
Source Project: java-technology-stack   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 7
@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 8
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example 9
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example 10
Source Project: java-technology-stack   Source File: JmsNamespaceHandlerTests.java    License: 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 11
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example 12
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example 13
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 14
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 15
@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 16
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example 17
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example 18
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 19
Source Project: redisson   Source File: RedissonDefinitionParser.java    License: Apache License 2.0 6 votes vote down vote up
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    if (element.hasChildNodes()) {
        CompositeComponentDefinition compositeDef
                = new CompositeComponentDefinition(parentId,
                        parserContext.extractSource(element));
        parserContext.pushContainingComponent(compositeDef);
        List<Element> childElts = DomUtils.getChildElements(element);
        for (Element elt : childElts) {
            if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
                continue; //parsed elsewhere
            }
            String localName = parserContext.getDelegate().getLocalName(elt);
            localName = Conventions.attributeNameToPropertyName(localName);
            if (ConfigType.contains(localName)) {
                parseConfigTypes(elt, localName, redissonDef, parserContext);
            } else if (AddressType.contains(localName)) {
                parseAddressTypes(elt, localName, redissonDef, parserContext);
            } else if (helper.isRedissonNS(elt)) {
                elt.setAttribute(REDISSON_REF, redissonRef);
                parserContext.getDelegate().parseCustomElement(elt);
            }
        }
        parserContext.popContainingComponent();
    }
}
 
Example 20
@Override
public BeanDefinition parse( Element element, ParserContext parserContext ) {
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary( parserContext, element );
    if( !parserContext.getRegistry().containsBeanDefinition( BEAN_NAME ) ) {
        Object eleSource = parserContext.extractSource( element );

        RootBeanDefinition stageCreator = new RootBeanDefinition( SpringStageCreator.class );
        stageCreator.setSource( eleSource );
        stageCreator.setRole( BeanDefinition.ROLE_INFRASTRUCTURE );
        String executorName = parserContext.getReaderContext().registerWithGeneratedName( stageCreator );
        logger.debug( "Registered SpringStageCreator with name " + executorName );

        RootBeanDefinition beanFactoryPostProcessor = new RootBeanDefinition( JGivenBeanFactoryPostProcessor.class );
        beanFactoryPostProcessor.setRole( BeanDefinition.ROLE_INFRASTRUCTURE );
        parserContext.getRegistry().registerBeanDefinition( BEAN_NAME, beanFactoryPostProcessor );

        CompositeComponentDefinition componentDefinition = new CompositeComponentDefinition( element.getTagName(), eleSource );
        componentDefinition.addNestedComponent( new BeanComponentDefinition( stageCreator, executorName ) );
        componentDefinition.addNestedComponent( new BeanComponentDefinition( beanFactoryPostProcessor, BEAN_NAME ) );
        parserContext.registerComponent( componentDefinition );
    }
    return null;
}
 
Example 21
Source Project: jdal   Source File: DefaultsBeanDefinitionParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
	public BeanDefinition parse(Element element, ParserContext parserContext) {
	
		Object source = parserContext.extractSource(element);
		CompositeComponentDefinition ccd = new CompositeComponentDefinition("jdal-swing", source);
		
		ccd.addNestedComponent(registerPropertyEditors(element, parserContext));
		ccd.addNestedComponent(registerAccessorFactory(element, parserContext));
		ccd.addNestedComponent(registerBinderFactory(element, parserContext));
		ccd.addNestedComponent(registerPaginatorView(element, parserContext));
		ccd.addNestedComponent(registerDefaultTableActions(element, parserContext));
		ccd.addNestedComponent(registerDefaultGuiFactory(element, parserContext));
		ccd.addNestedComponent(registerCollectionTableCellRenderer(element, parserContext));
//		ccd.addNestedComponent(registerControlInitializer(element, parserContext));
		
		parserContext.getReaderContext().fireComponentRegistered(ccd);
		
		return null;
	}
 
Example 22
@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());
}
 
Example 23
@Test
public void testAdvisorEventsWithDirectPointcut() {
	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
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheResolution(element, interceptorDef, false);
		parseErrorHandler(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example 25
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME)) {
		Object source = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, source);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef =
				new RootBeanDefinition("org.springframework.cache.jcache.interceptor.JCacheInterceptor");
		interceptorDef.setSource(source);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		interceptorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		parseErrorHandler(element, interceptorDef);
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(
				"org.springframework.cache.jcache.interceptor.BeanFactoryJCacheOperationSourceAdvisor");
		advisorDef.setSource(source);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example 26
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	MutablePropertyValues commonProperties = parseCommonContainerProperties(element, parserContext);
	MutablePropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext);

	String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE);
	if (StringUtils.hasText(factoryId)) {
		RootBeanDefinition beanDefinition = createContainerFactory(
				factoryId, element, parserContext, commonProperties, specificProperties);
		if (beanDefinition != null) {
			beanDefinition.setSource(parserContext.extractSource(element));
			parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId));
		}
	}

	NodeList childNodes = element.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node child = childNodes.item(i);
		if (child.getNodeType() == Node.ELEMENT_NODE) {
			String localName = parserContext.getDelegate().getLocalName(child);
			if (LISTENER_ELEMENT.equals(localName)) {
				parseListener(element, (Element) child, parserContext, commonProperties, specificProperties);
			}
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 27
Source Project: spring-analysis-note   Source File: ParserContext.java    License: 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 28
@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());
}
 
Example 29
@Test
public void testAdvisorEventsWithDirectPointcut() {
	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 30
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheResolution(element, interceptorDef, false);
		parseErrorHandler(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}