Java Code Examples for org.springframework.beans.factory.xml.ParserContext#registerBeanComponent()

The following examples show how to use org.springframework.beans.factory.xml.ParserContext#registerBeanComponent() . 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: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
		builder.setFactoryMethod("aspectOf");
		String executor = element.getAttribute("executor");
		if (StringUtils.hasText(executor)) {
			builder.addPropertyReference("executor", executor);
		}
		String exceptionHandler = element.getAttribute("exception-handler");
		if (StringUtils.hasText(exceptionHandler)) {
			builder.addPropertyReference("exceptionHandler", exceptionHandler);
		}
		parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
				TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
	}
}
 
Example 2
Source File: LoadTimeWeaverBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

	if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) {
		if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME);
			parserContext.registerBeanComponent(
					new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME));
		}

		if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) {
			new SpringConfiguredBeanDefinitionParser().parse(element, parserContext);
		}
	}
}
 
Example 3
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void registerTransactionAspect(Element element, ParserContext parserContext) {
	String txAspectBeanName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME;
	String txAspectClassName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_CLASS_NAME;
	if (!parserContext.getRegistry().containsBeanDefinition(txAspectBeanName)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(txAspectClassName);
		def.setFactoryMethodName("aspectOf");
		registerTransactionManager(element, def);
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, txAspectBeanName));
	}
}
 
Example 4
Source File: AnnotationDrivenCacheBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void registerCacheAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
		def.setFactoryMethodName("aspectOf");
		BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource);
		String sourceName =
				parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
		def.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));

		parserContext.registerBeanComponent(new BeanComponentDefinition(sourceDef, sourceName));
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
	}
}
 
Example 5
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void registerJtaTransactionAspect(Element element, ParserContext parserContext) {
	String txAspectBeanName = TransactionManagementConfigUtils.JTA_TRANSACTION_ASPECT_BEAN_NAME;
	String txAspectClassName = TransactionManagementConfigUtils.JTA_TRANSACTION_ASPECT_CLASS_NAME;
	if (!parserContext.getRegistry().containsBeanDefinition(txAspectBeanName)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(txAspectClassName);
		def.setFactoryMethodName("aspectOf");
		registerTransactionManager(element, def);
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, txAspectBeanName));
	}
}
 
Example 6
Source File: AnnotationDrivenCacheBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers a
 * <pre class="code">
 * <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
 *   <property name="cacheManager" ref="cacheManager"/>
 *   <property name="keyGenerator" ref="keyGenerator"/>
 * </bean>
 * </pre>
 */
private static void registerCacheAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
		def.setFactoryMethodName("aspectOf");
		parseCacheResolution(element, def, false);
		CacheNamespaceHandler.parseKeyGenerator(element, def);
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME));
	}
}
 
Example 7
Source File: DeclareMixinConfigurerBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(
			DeclareMixinAutoProxyCreatorConfigurer.class);
	
	parserContext.registerBeanComponent(new BeanComponentDefinition(bdb.getBeanDefinition(),
			DECLARE_MIXIN_CONFIGURER));
	
	return null;
}
 
Example 8
Source File: SpringConfiguredBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
		def.setFactoryMethodName("aspectOf");
		def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		def.setSource(parserContext.extractSource(element));
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME));
	}
	return null;
}
 
Example 9
Source File: AuditingBeanDefinitionParser.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
private void registerInfrastructureBeanWithId(AbstractBeanDefinition def, String id,
		ParserContext context, Element element) {

	def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	def.setSource(context.extractSource(element));
	context.registerBeanComponent(new BeanComponentDefinition(def, id));
}
 
Example 10
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void registerTransactionAspect(Element element, ParserContext parserContext) {
	String txAspectBeanName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME;
	String txAspectClassName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_CLASS_NAME;
	if (!parserContext.getRegistry().containsBeanDefinition(txAspectBeanName)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(txAspectClassName);
		def.setFactoryMethodName("aspectOf");
		registerTransactionManager(element, def);
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, txAspectBeanName));
	}
}
 
Example 11
Source File: TableBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Register BeanDefinition and apply default bean attributes.
 * @param element
 * @param parserContext
 * @param beanName
 * @param bdb
 */
private void registerBeanDefinition(Element element, ParserContext parserContext, String beanName,
		BeanDefinitionBuilder bdb) {
	AbstractBeanDefinition bd = bdb.getBeanDefinition();
	parserContext.getDelegate().parseBeanDefinitionAttributes(element, beanName, null, bd);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), beanName);
	parserContext.registerBeanComponent(bcd);
}
 
Example 12
Source File: SqsParserUtils.java    From spring-integration-aws with MIT License 5 votes vote down vote up
public static void registerExecutorProxy(Element element,
		String sqsExecutorBeanName, ParserContext parserContext) {

	if (element.hasAttribute("sqs-executor-proxy")) {
		String sqsProxyBeanName = element
				.getAttribute("sqs-executor-proxy");
		BeanDefinitionBuilder sqsExecutorProxyBuilder = BeanDefinitionBuilder
				.genericBeanDefinition(SqsExecutorProxy.class);
		sqsExecutorProxyBuilder
				.addConstructorArgReference(sqsExecutorBeanName);
		parserContext.registerBeanComponent(new BeanComponentDefinition(
				sqsExecutorProxyBuilder.getBeanDefinition(),
				sqsProxyBeanName));
	}
}
 
Example 13
Source File: ScheduledTasksBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private RuntimeBeanReference beanReference(Element taskElement,
		ParserContext parserContext, BeanDefinitionBuilder builder) {
	// Extract the source of the current task
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(taskElement));
	String generatedName = parserContext.getReaderContext().generateBeanName(builder.getRawBeanDefinition());
	parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(), generatedName));
	return new RuntimeBeanReference(generatedName);
}
 
Example 14
Source File: AbstractListenerContainerParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext,
		PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

	RootBeanDefinition listenerDef = new RootBeanDefinition();
	listenerDef.setSource(parserContext.extractSource(listenerEle));
	listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");

	String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
	if (!StringUtils.hasText(ref)) {
		parserContext.getReaderContext().error(
				"Listener 'ref' attribute contains empty value.", listenerEle);
	}
	else {
		listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
	}

	String method = null;
	if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
		method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
		if (!StringUtils.hasText(method)) {
			parserContext.getReaderContext().error(
					"Listener 'method' attribute contains empty value.", listenerEle);
		}
	}
	listenerDef.getPropertyValues().add("defaultListenerMethod", method);

	PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
	if (messageConverterPv != null) {
		listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
	}

	BeanDefinition containerDef = createContainer(
			containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
	containerDef.getPropertyValues().add("messageListener", listenerDef);

	if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
		String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
		Boolean pubSubDomain = (Boolean) commonContainerProperties.getPropertyValue("replyPubSubDomain").getValue();
		listenerDef.getPropertyValues().add(
				pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
		if (containerDef.getPropertyValues().contains("destinationResolver")) {
			listenerDef.getPropertyValues().add("destinationResolver",
					containerDef.getPropertyValues().getPropertyValue("destinationResolver").getValue());
		}
	}


	String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
	// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
	if (!StringUtils.hasText(containerBeanName)) {
		containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
	}

	// Register the listener and fire event
	parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
 
Example 15
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void registerTransactionalEventListenerFactory(ParserContext parserContext) {
	RootBeanDefinition def = new RootBeanDefinition();
	def.setBeanClass(TransactionalEventListenerFactory.class);
	parserContext.registerBeanComponent(new BeanComponentDefinition(def,
			TransactionManagementConfigUtils.TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME));
}
 
Example 16
Source File: SnsPublishSubscribeChannelParser.java    From spring-integration-aws with MIT License 4 votes vote down vote up
@Override
protected BeanDefinitionBuilder buildBeanDefinition(Element element,
		ParserContext parserContext) {

	BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
			.genericBeanDefinition(PublishSubscribeSnsChannel.class);

	// create and set snsExecutor
	final BeanDefinitionBuilder snsExecutorBuilder = SnsParserUtils
			.getSnsExecutorBuilder(element, parserContext);

	final BeanDefinition snsExecutorBuilderBeanDefinition = snsExecutorBuilder
			.getBeanDefinition();
	final String channelAdapterId = this.resolveId(element,
			beanDefinitionBuilder.getRawBeanDefinition(), parserContext);
	final String snsExecutorBeanName = channelAdapterId + ".snsExecutor";

	SnsParserUtils.registerSubscriptions(element, parserContext,
			snsExecutorBuilder, channelAdapterId);

	parserContext.registerBeanComponent(new BeanComponentDefinition(
			snsExecutorBuilderBeanDefinition, snsExecutorBeanName));

	beanDefinitionBuilder.addPropertyReference("snsExecutor",
			snsExecutorBeanName);

	SnsParserUtils.registerExecutorProxy(element, snsExecutorBeanName,
			parserContext);
	// ---

	IntegrationNamespaceUtils.setValueIfAttributeDefined(
			beanDefinitionBuilder, element, "phase");

	IntegrationNamespaceUtils.setValueIfAttributeDefined(
			beanDefinitionBuilder, element, "auto-startup");

	AwsParserUtils.registerPermissions(element, snsExecutorBuilder,
			parserContext);

	return beanDefinitionBuilder;
}
 
Example 17
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void registerTransactionalEventListenerFactory(ParserContext parserContext) {
	RootBeanDefinition def = new RootBeanDefinition();
	def.setBeanClass(TransactionalEventListenerFactory.class);
	parserContext.registerBeanComponent(new BeanComponentDefinition(def,
			TransactionManagementConfigUtils.TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME));
}
 
Example 18
Source File: AbstractListenerContainerParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext,
		MutablePropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

	RootBeanDefinition listenerDef = new RootBeanDefinition();
	listenerDef.setSource(parserContext.extractSource(listenerEle));
	listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");

	String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
	if (!StringUtils.hasText(ref)) {
		parserContext.getReaderContext().error(
				"Listener 'ref' attribute contains empty value.", listenerEle);
	}
	else {
		listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
	}

	if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
		String method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
		if (!StringUtils.hasText(method)) {
			parserContext.getReaderContext().error(
					"Listener 'method' attribute contains empty value.", listenerEle);
		}
		listenerDef.getPropertyValues().add("defaultListenerMethod", method);
	}

	PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
	if (messageConverterPv != null) {
		listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
	}

	BeanDefinition containerDef = createContainer(
			containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
	containerDef.getPropertyValues().add("messageListener", listenerDef);

	if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
		String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
		Boolean pubSubDomain = (Boolean) commonContainerProperties.get("replyPubSubDomain");
		if (pubSubDomain == null) {
			pubSubDomain = false;
		}
		listenerDef.getPropertyValues().add(
				pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
		PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver");
		if (destinationResolver != null) {
			listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
		}
	}


	String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
	// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
	if (!StringUtils.hasText(containerBeanName)) {
		containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
	}

	// Register the listener and fire event
	parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
 
Example 19
Source File: TransactionManagerParser.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {

    String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID);
    String dataSourceRef = element.getAttribute(ATT_DATA_SOURCE_REF);
    String sessionFactoryRef = element.getAttribute(ATT_SESSION_FACTORY_REF);

    if(StringUtils.hasText(dataSourceRef) && StringUtils.hasText(sessionFactoryRef)) {
        throw new IllegalArgumentException(
                String.format("Only one of %s and %s can be specified",
                        ATT_DATA_SOURCE_REF, ATT_SESSION_FACTORY_REF));
    }

    BeanDefinitionBuilder builder;
    if(StringUtils.hasText(dataSourceRef)) {
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndDataSourceTransactionManager.class);
        builder.addPropertyReference("dataSource", dataSourceRef);
    } else if(StringUtils.hasText(sessionFactoryRef)) {
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndHibernateTransactionManager.class);
        builder.addPropertyReference("sessionFactory", sessionFactoryRef);
    } else {
        // Standard transaction manager
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceTransactionManager.class);
    }

    builder.addPropertyReference("contextSource", contextSourceRef);

    Element defaultStrategyChild = DomUtils.getChildElementByTagName(element, Elements.DEFAULT_RENAMING_STRATEGY);
    Element differentSubtreeChild = DomUtils.getChildElementByTagName(element, Elements.DIFFERENT_SUBTREE_RENAMING_STRATEGY);

    if(defaultStrategyChild != null) {
        builder.addPropertyValue("renamingStrategy", parseDefaultRenamingStrategy(defaultStrategyChild));
    }

    if(differentSubtreeChild != null) {
        builder.addPropertyValue("renamingStrategy", parseDifferentSubtreeRenamingStrategy(differentSubtreeChild));
    }

    String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);

    BeanDefinition beanDefinition = builder.getBeanDefinition();
    parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));

    return beanDefinition;
}
 
Example 20
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void registerTransactionalEventListenerFactory(ParserContext parserContext) {
	RootBeanDefinition def = new RootBeanDefinition();
	def.setBeanClass(TransactionalEventListenerFactory.class);
	parserContext.registerBeanComponent(new BeanComponentDefinition(def,
			TransactionManagementConfigUtils.TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME));
}