List of usage examples for org.springframework.core.type AnnotationMetadata getClassName
String getClassName();
From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java
protected Set<String> getBasePackages(final AnnotationMetadata importingClassMetadata) { Map<String, Object> attributes = importingClassMetadata .getAnnotationAttributes(EnableOAuth2FeignClients.class.getCanonicalName()); Set<String> basePackages = new HashSet<>(); for (String pkg : (String[]) attributes.get("value")) { if (StringUtils.hasText(pkg)) { basePackages.add(pkg);/*from www . ja v a2 s . co m*/ } } for (String pkg : (String[]) attributes.get("basePackages")) { if (StringUtils.hasText(pkg)) { basePackages.add(pkg); } } for (Class<?> clazz : (Class[]) attributes.get("basePackageClasses")) { basePackages.add(ClassUtils.getPackageName(clazz)); } if (basePackages.isEmpty()) { basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName())); } return basePackages; }
From source file:org.wallride.autoconfigure.WebAdminComponentScanRegistrar.java
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(WebAdminComponentScan.class.getName())); String[] value = attributes.getStringArray("value"); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); if (!ObjectUtils.isEmpty(value)) { Assert.state(ObjectUtils.isEmpty(basePackages), "@WebAdminComponentScan basePackages and value attributes are mutually exclusive"); }// www. j a va 2 s.c o m Set<String> packagesToScan = new LinkedHashSet<String>(); packagesToScan.addAll(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
From source file:org.wallride.autoconfigure.WebGuestComponentScanRegistrar.java
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(WebGuestComponentScan.class.getName())); String[] value = attributes.getStringArray("value"); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); if (!ObjectUtils.isEmpty(value)) { Assert.state(ObjectUtils.isEmpty(basePackages), "@WebGuestComponentScan basePackages and value attributes are mutually exclusive"); }//from w ww . ja v a 2 s. co m Set<String> packagesToScan = new LinkedHashSet<String>(); packagesToScan.addAll(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
From source file:org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.java
public RabbitListenerTestHarness(AnnotationMetadata importMetadata) { Map<String, Object> map = importMetadata.getAnnotationAttributes(RabbitListenerTest.class.getName()); this.attributes = AnnotationAttributes.fromMap(map); Assert.notNull(this.attributes, "@RabbitListenerTest is not present on importing class " + importMetadata.getClassName()); }
From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java
/** * Return the appropriate {@link AnnotationAttributes} from the * {@link AnnotationMetadata}. By default this method will return attributes for * {@link #getAnnotationClass()}.// w ww . j a v a 2 s . c om * @param metadata the annotation metadata * @return annotation attributes */ protected AnnotationAttributes getAttributes(AnnotationMetadata metadata) { String name = getAnnotationClass().getName(); AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(name, true)); Assert.notNull(attributes, () -> "No auto-configuration attributes found. Is " + metadata.getClassName() + " annotated with " + ClassUtils.getShortName(name) + "?"); return attributes; }
From source file:org.springframework.boot.autoconfigure.ComponentScanDetector.java
private List<String> getBasePackages(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes.fromMap( (metadata == null ? null : metadata.getAnnotationAttributes(ComponentScan.class.getName(), true))); if (attributes != null) { List<String> basePackages = new ArrayList<String>(); addAllHavingText(basePackages, attributes.getStringArray("value")); addAllHavingText(basePackages, attributes.getStringArray("basePackages")); for (String packageClass : attributes.getStringArray("basePackageClasses")) { basePackages.add(ClassUtils.getPackageName(packageClass)); }//from w ww. j av a 2 s .c o m if (basePackages.isEmpty()) { basePackages.add(ClassUtils.getPackageName(metadata.getClassName())); } return basePackages; } return Collections.emptyList(); }
From source file:org.springframework.cloud.commons.util.SpringFactoryImportSelector.java
@Override public String[] selectImports(AnnotationMetadata metadata) { if (!isEnabled()) { return new String[0]; }//w w w. ja va2 s .c o m AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(this.annotationClass.getName(), true)); Assert.notNull(attributes, "No " + getSimpleName() + " attributes found. Is " + metadata.getClassName() + " annotated with @" + getSimpleName() + "?"); // Find all possible auto configuration classes, filtering duplicates List<String> factories = new ArrayList<>(new LinkedHashSet<>( SpringFactoriesLoader.loadFactoryNames(this.annotationClass, this.beanClassLoader))); if (factories.isEmpty() && !hasDefaultFactory()) { throw new IllegalStateException("Annotation @" + getSimpleName() + " found, but there are no implementations. Did you forget to include a starter?"); } if (factories.size() > 1) { // there should only ever be one DiscoveryClient, but there might be more than // one factory log.warn("More than one implementation " + "of @" + getSimpleName() + " (now relying on @Conditionals to pick one): " + factories); } return factories.toArray(new String[factories.size()]); }
From source file:org.springframework.cloud.netflix.hystrix.HystrixConfiguration.java
@Override public void setImportMetadata(AnnotationMetadata importMetadata) { this.enableHystrix = AnnotationAttributes .fromMap(importMetadata.getAnnotationAttributes(EnableHystrix.class.getName(), false)); Assert.notNull(this.enableHystrix, "@EnableHystrix is not present on importing class " + importMetadata.getClassName()); }
From source file:org.springframework.context.annotation.ConfigurationClassParser.java
/** * Retrieve the metadata for all <code>@Bean</code> methods. *///from www . ja v a2 s . c om private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass) { AnnotationMetadata original = sourceClass.getMetadata(); Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.class.getName()); if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) { // Try reading the class file via ASM for deterministic declaration order... // Unfortunately, the JVM's standard reflection returns methods in arbitrary // order, even between different runs of the same application on the same JVM. try { AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClassName()) .getAnnotationMetadata(); Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.class.getName()); if (asmMethods.size() >= beanMethods.size()) { Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size()); for (MethodMetadata asmMethod : asmMethods) { for (MethodMetadata beanMethod : beanMethods) { if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) { selectedMethods.add(beanMethod); break; } } } if (selectedMethods.size() == beanMethods.size()) { // All reflection-detected methods found in ASM method set -> proceed beanMethods = selectedMethods; } } } catch (IOException ex) { logger.debug("Failed to read class file via ASM for determining @Bean method order", ex); // No worries, let's continue with the reflection metadata we started with... } } return beanMethods; }
From source file:org.springframework.context.annotation.ConfigurationClassParser.java
private boolean isChainedImportOnStack(ConfigurationClass configClass) { if (this.importStack.contains(configClass)) { String configClassName = configClass.getMetadata().getClassName(); AnnotationMetadata importingClass = this.importStack.getImportingClassFor(configClassName); while (importingClass != null) { if (configClassName.equals(importingClass.getClassName())) { return true; }//ww w. j av a 2 s . c om importingClass = this.importStack.getImportingClassFor(importingClass.getClassName()); } } return false; }