Java Code Examples for org.springframework.beans.factory.support.GenericBeanDefinition#setSource()

The following examples show how to use org.springframework.beans.factory.support.GenericBeanDefinition#setSource() . 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 5 votes vote down vote up
private GenericBeanDefinition createObjectMapperFactoryDefinition(@Nullable Object source) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
	beanDefinition.setSource(source);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	return beanDefinition;
}
 
Example 2
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private RuntimeBeanReference registerMessageConverter(
		Element element, ParserContext context, @Nullable Object source) {

	Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
	ManagedList<Object> converters = new ManagedList<>();
	if (convertersElement != null) {
		converters.setSource(source);
		for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
			Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
			converters.add(object);
		}
	}
	if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
		converters.setSource(source);
		converters.add(new RootBeanDefinition(StringMessageConverter.class));
		converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
		if (jackson2Present) {
			RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
			RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
			resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
			jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
			// Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
			GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
			jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
			jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			jacksonFactoryDef.setSource(source);
			jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
			converters.add(jacksonConverterDef);
		}
	}
	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, converters);
	RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cargs, null);
	String name = MESSAGE_CONVERTER_BEAN_NAME;
	registerBeanDefByName(name, messageConverterDef, context, source);
	return new RuntimeBeanReference(name);
}
 
Example 3
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private GenericBeanDefinition createObjectMapperFactoryDefinition(@Nullable Object source) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
	beanDefinition.setSource(source);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	return beanDefinition;
}
 
Example 4
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private RuntimeBeanReference registerMessageConverter(
		Element element, ParserContext context, @Nullable Object source) {

	Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
	ManagedList<Object> converters = new ManagedList<>();
	if (convertersElement != null) {
		converters.setSource(source);
		for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
			Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
			converters.add(object);
		}
	}
	if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
		converters.setSource(source);
		converters.add(new RootBeanDefinition(StringMessageConverter.class));
		converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
		if (jackson2Present) {
			RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
			RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
			resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
			jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
			// Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
			GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
			jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
			jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			jacksonFactoryDef.setSource(source);
			jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
			converters.add(jacksonConverterDef);
		}
	}
	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, converters);
	RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cargs, null);
	String name = MESSAGE_CONVERTER_BEAN_NAME;
	registerBeanDefByName(name, messageConverterDef, context, source);
	return new RuntimeBeanReference(name);
}
 
Example 5
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private GenericBeanDefinition createObjectMapperFactoryDefinition(Object source) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
	beanDefinition.setSource(source);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	return beanDefinition;
}
 
Example 6
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private GenericBeanDefinition createObjectMapperFactoryDefinition(Object source) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
	beanDefinition.setSource(source);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	return beanDefinition;
}
 
Example 7
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private RuntimeBeanReference registerMessageConverter(Element element, ParserContext context, Object source) {
	Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
	ManagedList<? super Object> converters = new ManagedList<Object>();
	if (convertersElement != null) {
		converters.setSource(source);
		for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
			Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
			converters.add(object);
		}
	}
	if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
		converters.setSource(source);
		converters.add(new RootBeanDefinition(StringMessageConverter.class));
		converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
		if (jackson2Present) {
			RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
			RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
			resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
			jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
			// Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
			GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
			jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
			jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			jacksonFactoryDef.setSource(source);
			jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
			converters.add(jacksonConverterDef);
		}
	}
	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, converters);
	RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
	return new RuntimeBeanReference(registerBeanDef(messageConverterDef, context, source));
}