@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2015 the original author or authors .
* Copyright 2002 - 2016 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -109,6 +109,9 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
private static final boolean jackson2Present = ClassUtils . isPresent (
private static final boolean jackson2Present = ClassUtils . isPresent (
"com.fasterxml.jackson.databind.ObjectMapper" , MessageBrokerBeanDefinitionParser . class . getClassLoader ( ) ) ;
"com.fasterxml.jackson.databind.ObjectMapper" , MessageBrokerBeanDefinitionParser . class . getClassLoader ( ) ) ;
private static final boolean javaxValidationPresent =
ClassUtils . isPresent ( "javax.validation.Validator" , MessageBrokerBeanDefinitionParser . class . getClassLoader ( ) ) ;
@Override
@Override
public BeanDefinition parse ( Element element , ParserContext context ) {
public BeanDefinition parse ( Element element , ParserContext context ) {
@ -516,6 +519,11 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
beanDef . getPropertyValues ( ) . add ( "pathMatcher" , new RuntimeBeanReference ( pathMatcherRef ) ) ;
beanDef . getPropertyValues ( ) . add ( "pathMatcher" , new RuntimeBeanReference ( pathMatcherRef ) ) ;
}
}
RuntimeBeanReference validatorRef = getValidator ( messageBrokerElement , source , context ) ;
if ( validatorRef ! = null ) {
beanDef . getPropertyValues ( ) . add ( "validator" , validatorRef ) ;
}
Element resolversElement = DomUtils . getChildElementByTagName ( messageBrokerElement , "argument-resolvers" ) ;
Element resolversElement = DomUtils . getChildElementByTagName ( messageBrokerElement , "argument-resolvers" ) ;
if ( resolversElement ! = null ) {
if ( resolversElement ! = null ) {
values . add ( "customArgumentResolvers" , extractBeanSubElements ( resolversElement , context ) ) ;
values . add ( "customArgumentResolvers" , extractBeanSubElements ( resolversElement , context ) ) ;
@ -529,6 +537,24 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
registerBeanDef ( beanDef , context , source ) ;
registerBeanDef ( beanDef , context , source ) ;
}
}
private RuntimeBeanReference getValidator ( Element messageBrokerElement , Object source , ParserContext parserContext ) {
if ( messageBrokerElement . hasAttribute ( "validator" ) ) {
return new RuntimeBeanReference ( messageBrokerElement . getAttribute ( "validator" ) ) ;
}
else if ( javaxValidationPresent ) {
RootBeanDefinition validatorDef = new RootBeanDefinition (
"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean" ) ;
validatorDef . setSource ( source ) ;
validatorDef . setRole ( BeanDefinition . ROLE_INFRASTRUCTURE ) ;
String validatorName = parserContext . getReaderContext ( ) . registerWithGeneratedName ( validatorDef ) ;
parserContext . registerComponent ( new BeanComponentDefinition ( validatorDef , validatorName ) ) ;
return new RuntimeBeanReference ( validatorName ) ;
}
else {
return null ;
}
}
private ManagedList < Object > extractBeanSubElements ( Element parentElement , ParserContext parserContext ) {
private ManagedList < Object > extractBeanSubElements ( Element parentElement , ParserContext parserContext ) {
ManagedList < Object > list = new ManagedList < Object > ( ) ;
ManagedList < Object > list = new ManagedList < Object > ( ) ;
list . setSource ( parserContext . extractSource ( parentElement ) ) ;
list . setSource ( parserContext . extractSource ( parentElement ) ) ;