List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation
@Nullable public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType)
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.OsgiAnnotationHandlerMapping.java
protected String[] determineUrlsForOsgiService(Object osgiController) { Class<?> handlerType = osgiController.getClass(); RequestMapping mapping = osgiController.getClass().getAnnotation(RequestMapping.class); if (mapping != null) { // @RequestMapping found at type level this.cachedMappings.put(handlerType, mapping); Set<String> urls = new LinkedHashSet<String>(); String[] typeLevelPatterns = mapping.value(); if (typeLevelPatterns.length > 0) { // @RequestMapping specifies paths at type level String[] methodLevelPatterns = determineUrlsForHandlerMethods(handlerType, true); for (String typeLevelPattern : typeLevelPatterns) { if (!typeLevelPattern.startsWith("/")) { typeLevelPattern = "/" + typeLevelPattern; }/* ww w . j a v a2s . c o m*/ boolean hasEmptyMethodLevelMappings = false; for (String methodLevelPattern : methodLevelPatterns) { if (methodLevelPattern == null) { hasEmptyMethodLevelMappings = true; } else { String combinedPattern = getPathMatcher().combine(typeLevelPattern, methodLevelPattern); addUrlsForPath(urls, combinedPattern); } } if (hasEmptyMethodLevelMappings || org.springframework.web.servlet.mvc.Controller.class.isAssignableFrom(handlerType)) { addUrlsForPath(urls, typeLevelPattern); } } return StringUtils.toStringArray(urls); } else { // actual paths specified by @RequestMapping at method level return determineUrlsForHandlerMethods(handlerType, false); } } else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) { // @RequestMapping to be introspected at method level return determineUrlsForHandlerMethods(handlerType, false); } else { return null; } }
From source file:org.springframework.data.web.ProjectingJackson2HttpMessageConverter.java
@Override public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) { if (!canRead(mediaType)) { return false; }//w w w . j a v a2 s. c o m ResolvableType owner = contextClass == null ? null : ResolvableType.forClass(contextClass); Class<?> rawType = ResolvableType.forType(type, owner).resolve(Object.class); Boolean result = supportedTypesCache.get(rawType); if (result != null) { return result; } result = rawType.isInterface() && AnnotationUtils.findAnnotation(rawType, ProjectedPayload.class) != null; supportedTypesCache.put(rawType, result); return result; }
From source file:flex.contrib.utils.FlexUtils.java
/** * Gets the remoting destination annotation from the bean. * * @param bean the bean for which to return the remoting destination annotation * @return remoting destination annotation of the bean *///from w w w . j a v a 2 s. c o m public static flex.contrib.stereotypes.RemotingDestination getRemotingDestinationAnnotation(Object bean) { flex.contrib.stereotypes.RemotingDestination annotation; if (!AopUtils.isAopProxy(bean)) { annotation = AnnotationUtils.findAnnotation(bean.getClass(), flex.contrib.stereotypes.RemotingDestination.class); } else { annotation = AnnotationUtils.findAnnotation(AopUtils.getTargetClass(bean), flex.contrib.stereotypes.RemotingDestination.class); } return annotation; }
From source file:com.github.kongchen.swagger.docgen.mavenplugin.ApiSource.java
private void setInfoFromAnnotation() { Info resultInfo = new Info(); for (Class<?> aClass : getValidClasses(SwaggerDefinition.class)) { SwaggerDefinition swaggerDefinition = AnnotationUtils.findAnnotation(aClass, SwaggerDefinition.class); io.swagger.annotations.Info infoAnnotation = swaggerDefinition.info(); Info info = new Info().title(infoAnnotation.title()).description(infoAnnotation.description()) .version(infoAnnotation.version()).termsOfService(infoAnnotation.termsOfService()) .license(from(infoAnnotation.license())).contact(from(infoAnnotation.contact())); resultInfo.mergeWith(info);/* w ww .ja va 2 s .c o m*/ } info = resultInfo; }
From source file:org.springjutsu.validation.util.RequestUtils.java
/** * Given a handler object, return the base controller * class-level requestMapping paths. In case the controller * specifies one or more base path(s).//from w w w .j a v a2s .c o m * @param handler the handler object * @return the controller request paths. */ public static String[] getControllerRequestPaths(HandlerMethod handler) { RequestMapping requestMapping = AnnotationUtils.findAnnotation(AopUtils.getTargetClass(handler.getBean()), RequestMapping.class); return requestMapping == null ? null : requestMapping.value(); }
From source file:org.makersoft.mvc.method.annotation.RESTfulMappingHandlerMapping.java
/** * Uses method and type-level @{@link RequestMapping} annotations to create * the RequestMappingInfo./*from w w w .ja v a 2 s . co m*/ * * @return the created RequestMappingInfo, or {@code null} if the method * does not have a {@code @RequestMapping} annotation. * * @see #getCustomMethodCondition(Method) * @see #getCustomTypeCondition(Class) */ @Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = null; RESTfull clazzAnnotation = AnnotationUtils.findAnnotation(handlerType, RESTfull.class); if (clazzAnnotation != null) { info = createRequestMappingInfo(method, clazzAnnotation, handlerType); // RequestMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class); // if (typeAnnotation != null) { // RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType); // info = createRequestMappingInfo(typeAnnotation, typeCondition).combine(info); // } } return info; }
From source file:org.flywaydb.test.junit.FlywayTestExecutionListener.java
/** * Invoke this method before test class will be created.</p> * * <b>Attention:</b> This will be only invoked if spring version >= 3.x * are used./*from w w w . j av a 2 s . c om*/ * * @param testContext * default test context filled from spring * * @throws Exception * if any error occurred */ public void beforeTestClass(final TestContext testContext) throws Exception { // no we check for the DBResetForClass final Class<?> testClass = testContext.getTestClass(); final Annotation annotation = AnnotationUtils.findAnnotation(testClass, FlywayTest.class); dbResetWithAnotation(testContext, (FlywayTest) annotation); }
From source file:us.swcraft.springframework.session.aerospike.config.annotation.web.http.AerospikeHttpSessionConfiguration.java
public void setImportMetadata(AnnotationMetadata importMetadata) { Map<String, Object> enableAttrMap = importMetadata .getAnnotationAttributes(EnableAerospikeHttpSession.class.getName()); AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap); if (enableAttrs == null) { // search parent classes Class<?> currentClass = ClassUtils.resolveClassName(importMetadata.getClassName(), beanClassLoader); for (Class<?> classToInspect = currentClass; classToInspect != null; classToInspect = classToInspect .getSuperclass()) {/*from w ww . ja v a 2 s. c o m*/ EnableAerospikeHttpSession enableWebSecurityAnnotation = AnnotationUtils .findAnnotation(classToInspect, EnableAerospikeHttpSession.class); if (enableWebSecurityAnnotation == null) { continue; } enableAttrMap = AnnotationUtils.getAnnotationAttributes(enableWebSecurityAnnotation); enableAttrs = AnnotationAttributes.fromMap(enableAttrMap); } } maxInactiveIntervalInSeconds = enableAttrs.getNumber("maxInactiveIntervalInSeconds"); namespace = enableAttrs.getString("namespace"); setname = enableAttrs.getString("setname"); }
From source file:springfox.documentation.spring.data.rest.EntityRequestHandler.java
@Override public <T extends Annotation> Optional<T> findAnnotation(Class<T> annotation) { return Optional.fromNullable(AnnotationUtils.findAnnotation(handlerMethod.getMethod(), annotation)); }
From source file:nl.jeslee.jersey.server.spring.SpringComponentProvider.java
@Override public boolean bind(Class<?> component, Set<Class<?>> providerContracts) { if (ctx == null) { return false; }// w w w . j a v a 2 s . c o m if (AnnotationUtils.findAnnotation(component, Component.class) != null) { DynamicConfiguration c = Injections.getConfiguration(locator); String[] beanNames = ctx.getBeanNamesForType(component); if (beanNames == null || beanNames.length != 1) { LOGGER.severe(LocalizationMessages.NONE_OR_MULTIPLE_BEANS_AVAILABLE(component)); return false; } String beanName = beanNames[0]; ServiceBindingBuilder bb = Injections .newFactoryBinder(new SpringComponentProvider.SpringManagedBeanFactory(ctx, locator, beanName)); bb.to(component); Injections.addBinding(bb, c); c.commit(); LOGGER.config(LocalizationMessages.BEAN_REGISTERED(beanName)); return true; } return false; }