List of usage examples for org.springframework.core.annotation AnnotationAttributes fromMap
@Nullable public static AnnotationAttributes fromMap(@Nullable Map<String, Object> map)
From source file:com.github.eddumelendez.autoconfigure.TestAutoConfigurationPackageRegistrar.java
@Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true)); AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value"))); }
From source file:lodsve.core.condition.OnJndiCondition.java
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { AnnotationAttributes annotationAttributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName())); String[] locations = annotationAttributes.getStringArray("value"); try {/* w ww . j av a 2s . c om*/ return getMatchOutcome(locations); } catch (NoClassDefFoundError ex) { return ConditionOutcome.noMatch("JNDI class not found"); } }
From source file:com.developmentsprint.spring.breaker.annotations.AbstractCircuitBreakerConfiguration.java
@Override public void setImportMetadata(AnnotationMetadata importMetadata) { this.enableCircuitBreakers = AnnotationAttributes .fromMap(importMetadata.getAnnotationAttributes(EnableCircuitBreakers.class.getName(), false)); Assert.notNull(this.enableCircuitBreakers, "@EnableCircuitBreakers is not present on importing class " + importMetadata.getClassName()); }
From source file:org.zalando.baigan.proxy.ConfigurationBeanDefinitionRegistrar.java
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { final AnnotationAttributes annotationAttributes = AnnotationAttributes .fromMap(importingClassMetadata.getAnnotationAttributes(ConfigurationServiceScan.class.getName())); if (annotationAttributes == null || annotationAttributes.isEmpty()) { throw new IllegalArgumentException("ConfigurationServiceScan requires at least 1 scan package."); }/*from w w w . j a v a 2s . com*/ final List<String> basePackages = Lists.newArrayList(); basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("value"))); basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("basePackages"))); final Set<String> saneSet = basePackages.stream().filter(str -> !StringUtils.isEmpty(str)) .collect(Collectors.toSet()); createAndRegisterBeanDefinitions(saneSet, registry); }
From source file:ductive.console.config.SshServerBeanRegistrar.java
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { AnnotationAttributes attr = AnnotationAttributes .fromMap(importingClassMetadata.getAnnotationAttributes(EnableConsole.class.getName())); {/*from w w w.j a v a 2 s .com*/ RootBeanDefinition beanDefinition = new RootBeanDefinition(SshServerFactoryBean.class); beanDefinition.setSource(null); beanDefinition.getPropertyValues().add("host", attr.getString("host")); beanDefinition.getPropertyValues().add("port", attr.getString("port")); beanDefinition.getPropertyValues().add("hostKeyFile", attr.getString("hostKeyFile")); beanDefinition.getPropertyValues().add("hostKeyPermissions", attr.getString("hostKeyPermissions")); String userAuthFactoryBeanName = attr.getString("userAuthFactoryProvider"); if (!StringUtils.isBlank(userAuthFactoryBeanName)) beanDefinition.getPropertyValues().add("userAuthFactoryProvider", new RuntimeBeanReference(userAuthFactoryBeanName)); String passwordAuthenticatorBeanName = attr.getString("passwordAuthenticator"); if (!StringUtils.isBlank(passwordAuthenticatorBeanName)) beanDefinition.getPropertyValues().add("passwordAuthenticator", new RuntimeBeanReference(passwordAuthenticatorBeanName)); String publicKeyAuthenticatorBeanName = attr.getString("publicKeyAuthenticator"); if (!StringUtils.isBlank(publicKeyAuthenticatorBeanName)) beanDefinition.getPropertyValues().add("publicKeyAuthenticator", new RuntimeBeanReference(publicKeyAuthenticatorBeanName)); registry.registerBeanDefinition(SSH_SERVER_FACTORY_BEAN_NAME, beanDefinition); } { RootBeanDefinition beanDefinition = new RootBeanDefinition(DefaultStandardPromptProvider.class); beanDefinition.setSource(null); beanDefinition.getPropertyValues().add("prompt", attr.getString("standardPrompt")); beanDefinition.getPropertyValues().add("color", attr.getString("standardPromptColor")); registry.registerBeanDefinition(STANDARD_PROMPT_PROVIDER_BEAN_NAME, beanDefinition); } }
From source file:com.ryantenney.metrics.spring.config.annotation.MetricsConfigurationSupport.java
@Override public void setImportMetadata(AnnotationMetadata importMetadata) { final AnnotationAttributes enableMetrics = AnnotationAttributes .fromMap(importMetadata.getAnnotationAttributes(EnableMetrics.class.getName(), false)); Assert.notNull(enableMetrics, "@" + EnableMetrics.class.getSimpleName() + " is not present on importing class " + importMetadata.getClassName()); this.proxyConfig = new ProxyConfig(); this.proxyConfig.setExposeProxy(enableMetrics.getBoolean("exposeProxy")); this.proxyConfig.setProxyTargetClass(enableMetrics.getBoolean("proxyTargetClass")); }
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 * // ww w. j av a 2s . c o 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.mybatis.spring.annotation.MapperScannerRegistrar.java
/** * {@inheritDoc}//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: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"); }/* ww w.ja v a 2 s . com*/ 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"); }// w w w . java 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; }