Browse Source

Remove code duplication in AnnotationDrivenBeanDefinitionParser

This commit merges the implementations of getCallableInterceptors()
and getDeferredResultInterceptors() in order to remove code duplication.

Closes gh-24305
pull/24314/head
GungnirLaevatain 5 years ago committed by Sam Brannen
parent
commit
4692f20aac
  1. 31
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java

31
spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java

@ -234,8 +234,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { @@ -234,8 +234,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
ManagedList<?> returnValueHandlers = getReturnValueHandlers(element, context);
String asyncTimeout = getAsyncTimeout(element);
RuntimeBeanReference asyncExecutor = getAsyncExecutor(element);
ManagedList<?> callableInterceptors = getCallableInterceptors(element, source, context);
ManagedList<?> deferredResultInterceptors = getDeferredResultInterceptors(element, source, context);
ManagedList<?> callableInterceptors = getInterceptors(element, source, context, "callable-interceptors");
ManagedList<?> deferredResultInterceptors = getInterceptors(element, source, context, "deferred-result-interceptors");
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
handlerAdapterDef.setSource(source);
@ -480,34 +480,13 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { @@ -480,34 +480,13 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
return null;
}
private ManagedList<?> getCallableInterceptors(
Element element, @Nullable Object source, ParserContext context) {
ManagedList<Object> interceptors = new ManagedList<>();
Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
if (asyncElement != null) {
Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
if (interceptorsElement != null) {
interceptors.setSource(source);
for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
BeanDefinitionHolder beanDef = context.getDelegate().parseBeanDefinitionElement(converter);
if (beanDef != null) {
beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
interceptors.add(beanDef);
}
}
}
}
return interceptors;
}
private ManagedList<?> getDeferredResultInterceptors(
Element element, @Nullable Object source, ParserContext context) {
private ManagedList<?> getInterceptors(
Element element, @Nullable Object source, ParserContext context, String interceptorElementName) {
ManagedList<Object> interceptors = new ManagedList<>();
Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
if (asyncElement != null) {
Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors");
Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, interceptorElementName);
if (interceptorsElement != null) {
interceptors.setSource(source);
for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {

Loading…
Cancel
Save