List of usage examples for org.springframework.core.annotation AnnotationAttributes getClass
@SuppressWarnings("unchecked") public <T> Class<? extends T> getClass(String attributeName)
From source file:com.alibaba.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar.java
protected void registerBeanDefinitions(AnnotationAttributes attributes, BeanDefinitionRegistry registry) { String prefix = environment.resolvePlaceholders(attributes.getString("prefix")); Class<? extends AbstractConfig> configClass = attributes.getClass("type"); boolean multiple = attributes.getBoolean("multiple"); registerDubboConfigBeans(prefix, configClass, multiple, registry); }
From source file:org.mybatis.spring.annotation.MapperScannerRegistrar.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s . c o m*/ */ @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { AnnotationAttributes annoAttrs = AnnotationAttributes .fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName())); ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); // this check is needed in Spring 3.1 if (resourceLoader != null) { scanner.setResourceLoader(resourceLoader); } Class<? extends Annotation> annotationClass = annoAttrs.getClass("annotationClass"); if (!Annotation.class.equals(annotationClass)) { scanner.setAnnotationClass(annotationClass); } Class<?> markerInterface = annoAttrs.getClass("markerInterface"); if (!Class.class.equals(markerInterface)) { scanner.setMarkerInterface(markerInterface); } Class<? extends BeanNameGenerator> generatorClass = annoAttrs.getClass("nameGenerator"); if (!BeanNameGenerator.class.equals(generatorClass)) { scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass)); } Class<? extends MapperFactoryBean> mapperFactoryBeanClass = annoAttrs.getClass("factoryBean"); if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) { scanner.setMapperFactoryBean(BeanUtils.instantiateClass(mapperFactoryBeanClass)); } scanner.setSqlSessionTemplateBeanName(annoAttrs.getString("sqlSessionTemplateRef")); scanner.setSqlSessionFactoryBeanName(annoAttrs.getString("sqlSessionFactoryRef")); List<String> basePackages = new ArrayList<String>(); for (String pkg : annoAttrs.getStringArray("value")) { if (StringUtils.hasText(pkg)) { basePackages.add(pkg); } } for (String pkg : annoAttrs.getStringArray("basePackages")) { if (StringUtils.hasText(pkg)) { basePackages.add(pkg); } } for (Class<?> clazz : annoAttrs.getClassArray("basePackageClasses")) { basePackages.add(ClassUtils.getPackageName(clazz)); } scanner.registerFilters(); scanner.doScan(StringUtils.toStringArray(basePackages)); }
From source file:us.swcraft.springframework.cache.aerospike.config.annotation.AerospikeCacheConfiguration.java
public void setImportMetadata(AnnotationMetadata importMetadata) { Map<String, Object> enableAttrMap = importMetadata .getAnnotationAttributes(EnableAerospikeCacheManager.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()) {// ww w. java2 s .c o m EnableAerospikeCacheManager enableWebSecurityAnnotation = AnnotationUtils .findAnnotation(classToInspect, EnableAerospikeCacheManager.class); if (enableWebSecurityAnnotation == null) { continue; } enableAttrMap = AnnotationUtils.getAnnotationAttributes(enableWebSecurityAnnotation); enableAttrs = AnnotationAttributes.fromMap(enableAttrMap); } } defaultTimeToLiveInSeconds = enableAttrs.getNumber("defaultTimeToLiveInSeconds"); defaultNamespace = enableAttrs.getString("defaultNamespace"); defaultCacheName = enableAttrs.getString("defaultCacheName"); compression = enableAttrs.getEnum("compression"); serializerClass = enableAttrs.getClass("serializerClass"); cachesConfiguration = enableAttrs.getAnnotationArray("caches"); }
From source file:org.springframework.boot.actuate.endpoint.annotation.AnnotationEndpointDiscoverer.java
private Class<?> getEndpointType(Class<?> extensionType) { AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(extensionType, EndpointExtension.class); Class<?> endpointType = attributes.getClass("endpoint"); Assert.state(!endpointType.equals(Void.class), () -> "Extension " + endpointType.getName() + " does not specify an endpoint"); return endpointType; }
From source file:org.springframework.boot.actuate.endpoint.annotation.AnnotationEndpointDiscoverer.java
private boolean isEndpointExposed(Class<?> endpointType, EndpointInfo<T> endpointInfo) { if (isEndpointFiltered(endpointInfo)) { return false; }//w w w . j a v a2 s . co m AnnotationAttributes annotationAttributes = AnnotatedElementUtils .getMergedAnnotationAttributes(endpointType, FilteredEndpoint.class); if (annotationAttributes == null) { return true; } Class<?> filterClass = annotationAttributes.getClass("value"); return isFilterMatch(filterClass, endpointInfo); }
From source file:org.springframework.boot.actuate.endpoint.annotation.AnnotationEndpointDiscoverer.java
/** * Determines if an extension is exposed. * @param endpointType the endpoint type * @param extensionType the extension type * @param endpointInfo the endpoint info * @return if the extension is exposed/*from www.ja va 2 s . c o m*/ */ protected boolean isExtensionExposed(Class<?> endpointType, Class<?> extensionType, EndpointInfo<T> endpointInfo) { AnnotationAttributes annotationAttributes = AnnotatedElementUtils .getMergedAnnotationAttributes(extensionType, EndpointExtension.class); Class<?> filterClass = annotationAttributes.getClass("filter"); return isFilterMatch(filterClass, endpointInfo); }
From source file:org.springframework.context.annotation.ConfigurationClassParser.java
/** * Apply processing and build a complete {@link ConfigurationClass} by reading the * annotations, members and methods from the source class. This method can be called * multiple times as relevant sources are discovered. * @param configClass the configuration class being build * @param sourceClass a source class//from w ww .java 2 s .c o m * @return the superclass, or {@code null} if none found or previously processed */ @Nullable protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { // Recursively process any member (nested) classes first processMemberClasses(configClass, sourceClass); // Process any @PropertySource annotations for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable( sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) { if (this.environment instanceof ConfigurableEnvironment) { processPropertySource(propertySource); } else { logger.warn("Ignoring @PropertySource annotation on [" + sourceClass.getMetadata().getClassName() + "]. Reason: Environment must implement ConfigurableEnvironment"); } } // Process any @ComponentScan annotations Set<AnnotationAttributes> componentScans = AnnotationConfigUtils .attributesForRepeatable(sourceClass.getMetadata(), ComponentScans.class, ComponentScan.class); if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) { for (AnnotationAttributes componentScan : componentScans) { // The config class is annotated with @ComponentScan -> perform the scan immediately Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName()); // Check the set of scanned definitions for any further config classes and parse recursively if needed for (BeanDefinitionHolder holder : scannedBeanDefinitions) { if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) { parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName()); } } } } // Process any @Import annotations processImports(configClass, sourceClass, getImports(sourceClass), true); // Process any @ImportResource annotations AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class); if (importResource != null) { String[] resources = importResource.getStringArray("locations"); Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader"); for (String resource : resources) { String resolvedResource = this.environment.resolveRequiredPlaceholders(resource); configClass.addImportedResource(resolvedResource, readerClass); } } // Process individual @Bean methods Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(sourceClass); for (MethodMetadata methodMetadata : beanMethods) { configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass)); } // Process default methods on interfaces processInterfaces(configClass, sourceClass); // Process superclass, if any if (sourceClass.getMetadata().hasSuperClass()) { String superclass = sourceClass.getMetadata().getSuperClassName(); if (superclass != null && !superclass.startsWith("java") && !this.knownSuperclasses.containsKey(superclass)) { this.knownSuperclasses.put(superclass, configClass); // Superclass found, return its annotation metadata and recurse return sourceClass.getSuperClass(); } } // No superclass -> processing is complete return null; }
From source file:org.springframework.context.annotation.ConfigurationClassParser.java
/** * Process the given <code>@PropertySource</code> annotation metadata. * @param propertySource metadata for the <code>@PropertySource</code> annotation found * @throws IOException if loading a property source failed *//*w w w. j a v a2 s. co m*/ private void processPropertySource(AnnotationAttributes propertySource) throws IOException { String name = propertySource.getString("name"); if (!StringUtils.hasLength(name)) { name = null; } String encoding = propertySource.getString("encoding"); if (!StringUtils.hasLength(encoding)) { encoding = null; } String[] locations = propertySource.getStringArray("value"); Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required"); boolean ignoreResourceNotFound = propertySource.getBoolean("ignoreResourceNotFound"); Class<? extends PropertySourceFactory> factoryClass = propertySource.getClass("factory"); PropertySourceFactory factory = (factoryClass == PropertySourceFactory.class ? DEFAULT_PROPERTY_SOURCE_FACTORY : BeanUtils.instantiateClass(factoryClass)); for (String location : locations) { try { String resolvedLocation = this.environment.resolveRequiredPlaceholders(location); Resource resource = this.resourceLoader.getResource(resolvedLocation); addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding))); } catch (IllegalArgumentException | FileNotFoundException | UnknownHostException ex) { // Placeholders not resolvable or resource not found when trying to open it if (ignoreResourceNotFound) { if (logger.isInfoEnabled()) { logger.info("Properties location [" + location + "] not resolvable: " + ex.getMessage()); } } else { throw ex; } } } }
From source file:org.springframework.test.context.ContextConfigurationAttributes.java
/** * Construct a new {@link ContextConfigurationAttributes} instance for the * supplied {@link AnnotationAttributes} (parsed from a * {@link ContextConfiguration @ContextConfiguration} annotation) and * the {@linkplain Class test class} that declared them. * @param declaringClass the test class that declared {@code @ContextConfiguration} * @param annAttrs the annotation attributes from which to retrieve the attributes *//*from w w w .j ava 2s .c o m*/ @SuppressWarnings("unchecked") public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) { this(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getClassArray("classes"), annAttrs.getBoolean("inheritLocations"), (Class<? extends ApplicationContextInitializer<?>>[]) annAttrs.getClassArray("initializers"), annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), annAttrs.getClass("loader")); }