List of usage examples for org.springframework.core.type AnnotationMetadata getAnnotationTypes
default Set<String> getAnnotationTypes()
From source file:org.talend.daikon.spring.BndToSpringBeanNameGenerator.java
/** * Derive a bean name from one of the annotations on the class. First delegate to the super class and if it is not a * spring annotation then check for the bnd annotation * //from ww w . jav a2 s .co m * @param annotatedDef the annotation-aware bean definition * @return the bean name, or {@code null} if none is found */ @Override protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { String beanName = super.determineBeanNameFromAnnotation(annotatedDef); if (beanName != null) { return beanName; } // else check for BND annotation AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); for (String type : types) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(amd.getAnnotationAttributes(type, false)); if (isStereotypeWithBndNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { Object value = attributes.get("name"); if (value instanceof String) { String strVal = (String) value; if (StringUtils.hasLength(strVal)) { if (beanName != null && !strVal.equals(beanName)) { throw new IllegalStateException("Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + strVal + "'"); } beanName = strVal; } } } } return beanName; }
From source file:org.cleverbus.core.common.route.RouteBeanNameGenerator.java
protected boolean isRouteAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); for (String type : types) { if (type.equals(CAMEL_CONF_CLASSNAME)) { return true; }//from www .j av a 2s.co m } return false; }
From source file:org.libreplan.web.common.entrypoints.RedirectorSynthetiser.java
private void addIfSuitable(List<Class<?>> accumulatedResult, CachingMetadataReaderFactory metadataReaderFactory, Resource resource) {/*from www.j av a 2 s. c om*/ try { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); ClassMetadata classMetadata = metadataReader.getClassMetadata(); if (classMetadata.isInterface() && annotationMetadata.getAnnotationTypes().contains(EntryPoints.class.getName())) { Class<?> klass = Class.forName(classMetadata.getClassName()); if (klass.isInterface()) { accumulatedResult.add(klass); } } } } catch (Exception e) { LOG.warn("exception processing " + resource, e); } }
From source file:org.springframework.context.annotation.AutoProxyRegistrar.java
/** * Register, escalate, and configure the standard auto proxy creator (APC) against the * given registry. Works by finding the nearest annotation declared on the importing * {@code @Configuration} class that has both {@code mode} and {@code proxyTargetClass} * attributes. If {@code mode} is set to {@code PROXY}, the APC is registered; if * {@code proxyTargetClass} is set to {@code true}, then the APC is forced to use * subclass (CGLIB) proxying.//from w w w. j a va2 s . c o m * <p>Several {@code @Enable*} annotations expose both {@code mode} and * {@code proxyTargetClass} attributes. It is important to note that most of these * capabilities end up sharing a {@linkplain AopConfigUtils#AUTO_PROXY_CREATOR_BEAN_NAME * single APC}. For this reason, this implementation doesn't "care" exactly which * annotation it finds -- as long as it exposes the right {@code mode} and * {@code proxyTargetClass} attributes, the APC can be registered and configured all * the same. */ @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { boolean candidateFound = false; Set<String> annoTypes = importingClassMetadata.getAnnotationTypes(); for (String annoType : annoTypes) { AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType); if (candidate == null) { continue; } Object mode = candidate.get("mode"); Object proxyTargetClass = candidate.get("proxyTargetClass"); if (mode != null && proxyTargetClass != null && AdviceMode.class == mode.getClass() && Boolean.class == proxyTargetClass.getClass()) { candidateFound = true; if (mode == AdviceMode.PROXY) { AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry); if ((Boolean) proxyTargetClass) { AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry); return; } } } } if (!candidateFound) { String name = getClass().getSimpleName(); logger.warn(String.format( "%s was imported but no annotations were found " + "having both 'mode' and 'proxyTargetClass' attributes of type " + "AdviceMode and boolean respectively. This means that auto proxy " + "creator registration and configuration may not have occurred as " + "intended, and components may not be proxied as expected. Check to " + "ensure that %s has been @Import'ed on the same class where these " + "annotations are declared; otherwise remove the import of %s " + "altogether.", name, name, name)); } }
From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java
/** * TODO until SPR-11710 will be resolved. * Captures the meta-annotation attribute values, in order. * @param importingClassMetadata The importing class metadata * @return The captured values.//from w w w . j ava 2 s.c o m */ private List<MultiValueMap<String, Object>> captureMetaAnnotationValues( AnnotationMetadata importingClassMetadata) { Set<String> directAnnotations = importingClassMetadata.getAnnotationTypes(); List<MultiValueMap<String, Object>> valuesHierarchy = new ArrayList<MultiValueMap<String, Object>>(); // Need to grab the values now; see SPR-11710 for (String ann : directAnnotations) { Set<String> chain = importingClassMetadata.getMetaAnnotationTypes(ann); if (chain.contains(MessagingGateway.class.getName())) { for (String meta : chain) { valuesHierarchy.add(importingClassMetadata.getAllAnnotationAttributes(meta)); } } } return valuesHierarchy; }