org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter Java Examples

The following examples show how to use org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter. 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 ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Assert.notNull(className, "No resolver class");
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #2
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Assert.notNull(className, "No resolver class");
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #3
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<Object>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #4
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<Object>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #5
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testArgumentResolvers() {
	loadBeanDefinitions("mvc-config-argument-resolvers.xml");
	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	Object value = new DirectFieldAccessor(adapter).getPropertyValue("customArgumentResolvers");
	assertNotNull(value);
	assertTrue(value instanceof List);
	List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
	assertEquals(3, resolvers.size());
	assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
	assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
	assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
	assertNotSame(resolvers.get(1), resolvers.get(2));
}
 
Example #6
Source File: BootMvcConfigurerAdapter.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	argumentResolvers.add(new WebAttributeArgumentResolver());
	argumentResolvers.add(new ListParameterArgumentResolver());
	if(this.argumentResolverList!=null){
		argumentResolverList.forEach(arg->{
			if(arg.getClass().getAnnotation(BootMvcArgumentResolver.class)!=null){
				argumentResolvers.add(arg);
			}
		});
	}
	if(this.webArgumentResolverList!=null){
		webArgumentResolverList.forEach(arg->{
			if(arg.getClass().getAnnotation(BootMvcArgumentResolver.class)!=null){
				argumentResolvers.add(new ServletWebArgumentResolverAdapter(arg));
			}
		});
	}
}
 
Example #7
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testArgumentResolvers(Object bean) {
	assertNotNull(bean);
	Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
	assertNotNull(value);
	assertTrue(value instanceof List);
	@SuppressWarnings("unchecked")
	List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
	assertEquals(3, resolvers.size());
	assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
	assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
	assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
	assertNotSame(resolvers.get(1), resolvers.get(2));
}
 
Example #8
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testArgumentResolvers(Object bean) {
	assertNotNull(bean);
	Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
	assertNotNull(value);
	assertTrue(value instanceof List);
	@SuppressWarnings("unchecked")
	List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
	assertEquals(3, resolvers.size());
	assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
	assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
	assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
	assertNotSame(resolvers.get(1), resolvers.get(2));
}