List of usage examples for org.springframework.core MethodParameter getMethodAnnotation
@Nullable public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
From source file:com.github.zhanhb.download.spring.PathDownloaderHandler.java
@Override public boolean supportsReturnType(MethodParameter returnType) { return returnType.getMethodAnnotation(ToDownload.class) != null && Path.class.isAssignableFrom(returnType.getMethod().getReturnType()); }
From source file:be.wolkmaan.klimtoren.shared.ViewInjectingReturnValueHandler.java
/** * Returns the view class declared on the method, if it exists. * Otherwise, returns null./* w w w. j ava 2 s.c o m*/ * @param returnType * @return */ private Class<? extends BaseView> getDeclaredViewClass(MethodParameter returnType) { ResponseView annotation = returnType.getMethodAnnotation(ResponseView.class); if (annotation != null) { return annotation.value(); } else { return null; } }
From source file:com.epam.ta.reportportal.ws.resolver.JacksonViewReturnValueHandler.java
/** * Returns assigned view or null/* w w w . ja v a 2 s .com*/ * * @param returnType * @return */ private Class<?> getDeclaredViewClass(MethodParameter returnType) { ResponseView annotation = returnType.getMethodAnnotation(ResponseView.class); if (annotation != null) { return annotation.value(); } else { return null; } }
From source file:com.github.jonpeterson.spring.mvc.versioning.VersionedModelResponseBodyAdvice.java
@Override public boolean supports(MethodParameter returnType, Class converterType) { return returnType.getMethodAnnotation(VersionedResponseBody.class) != null; }
From source file:com.ufukuzun.myth.dialect.handler.AjaxRequestResponseBodyReturnValueHandler.java
@Override public boolean supportsReturnType(MethodParameter returnType) { return returnType.getMethodAnnotation(AjaxResponseBody.class) != null; }
From source file:org.ngrinder.infra.spring.RemainedPathResolverTest.java
@Test public void testResolveArgument() throws Exception { MethodParameter mock2 = mock(MethodParameter.class); RequestMapping requestMapping = mock(RequestMapping.class); when(mock2.getMethodAnnotation(RequestMapping.class)).thenReturn(requestMapping); when(requestMapping.value()).thenReturn(new String[] { "/list/**" }); final RequestMapping requestMappingOnType = mock(RequestMapping.class); when(requestMappingOnType.value()).thenReturn(new String[] { "/script" }); RemainedPathMethodArgumentResolver resolver = new RemainedPathMethodArgumentResolver() { @Override/*w ww . j a va 2 s.co m*/ protected RequestMapping getDeclaringClassRequestMapping(MethodParameter parameter) { return requestMappingOnType; } }; NativeWebRequest nativeWebRequestMock = mock(NativeWebRequest.class); when(nativeWebRequestMock.getAttribute(anyString(), anyInt())).thenReturn("/list/script/hello/world"); assertThat((String) resolver.resolveArgument(mock2, null, nativeWebRequestMock, null), is("hello/world")); }
From source file:br.com.d4n.ui4entity.mvc.ControllerReturnValueHandler.java
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnType.getMethodAnnotation(UI4Entity.class) != null || returnValue.getClass().getAnnotation(UI4Entity.class) != null) { returnValue = engine.parse(returnValue); returnType = new UI4EntityMethodParameter(returnType, returnValue.getClass()); }//from w w w .j a v a2 s. c o m delegate.handleReturnValue(returnValue, returnType, mavContainer, webRequest); }
From source file:org.makersoft.mvc.method.annotation.FormatHandlerMethodReturnValueHandler.java
@Override public boolean supportsReturnType(MethodParameter returnType) { return returnType.getMethodAnnotation(Format.class) != null; }
From source file:br.com.d4n.ui4entity.mvc.ValueOptionReturnValueHandler.java
@SuppressWarnings("rawtypes") @Override/* www. j a va 2 s. co m*/ public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnType.getMethodAnnotation(ValueOptions.class) != null) { Map<String, Object> map = new HashMap<String, Object>(); if (returnValue instanceof List) { map.put("type", "list"); } else if (returnValue instanceof Map) { returnValue = ((Map) returnValue).entrySet(); map.put("type", "map"); } else throw new ClassCastException("@ValueOptions method must be return Map or List"); map.put(ValueOptionsProviderResolver.OPTIONS_ATTR_NAME, returnValue); returnValue = map; returnType = new UI4EntityMethodParameter(returnType, returnValue.getClass()); } delegate.handleReturnValue(returnValue, returnType, mavContainer, webRequest); }
From source file:org.ngrinder.infra.spring.RemainedPathMethodArgumentResolver.java
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { AntPathMatcher pathMatcher = new AntPathMatcher(); RequestMapping requestMappingOnMethod = parameter.getMethodAnnotation(RequestMapping.class); RequestMapping requestMappingOnClass = getDeclaringClassRequestMapping(parameter); String combine = pathMatcher.combine(requestMappingOnClass.value()[0], requestMappingOnMethod.value()[0]); return PathUtils.removePrependedSlash(pathMatcher.extractPathWithinPattern(combine, (String) webRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST))); }