Java Code Examples for org.springframework.core.annotation.AnnotationAttributes#fromMap()

The following examples show how to use org.springframework.core.annotation.AnnotationAttributes#fromMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GRpcApiRegister.java    From faster-framework-project with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(GRpcServerScan.class.getCanonicalName()));
    if (annotationAttributes == null) {
        log.warn("GrpcScan was not found.Please check your configuration.");
        return;
    }
    ClassPathBeanDefinitionScanner classPathGrpcApiScanner = new ClassPathBeanDefinitionScanner(registry, false);
    classPathGrpcApiScanner.setResourceLoader(this.resourceLoader);
    classPathGrpcApiScanner.addIncludeFilter(new AnnotationTypeFilter(GRpcApi.class));
    List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
    for (String pkg : annotationAttributes.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    classPathGrpcApiScanner.scan(StringUtils.toStringArray(basePackages));
}
 
Example 2
Source File: GRpcClientRegister.java    From faster-framework-project with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(GRpcClientScan.class.getCanonicalName()));
    if (annotationAttributes == null) {
        log.warn("GrpcScan was not found.Please check your configuration.");
        return;
    }
    ClassPathGRpcServiceScanner classPathGrpcServiceScanner = new ClassPathGRpcServiceScanner(registry, beanFactory);
    classPathGrpcServiceScanner.setResourceLoader(this.resourceLoader);
    classPathGrpcServiceScanner.addIncludeFilter(new AnnotationTypeFilter(GRpcService.class));
    List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
    for (String pkg : annotationAttributes.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    classPathGrpcServiceScanner.doScan(StringUtils.toStringArray(basePackages));
}
 
Example 3
Source File: DubboConfigBindingsRegistrar.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

//        解析@EnableDubboConfigBindings注解
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                importingClassMetadata.getAnnotationAttributes(EnableDubboConfigBindings.class.getName()));

//        获取注解的value值
        AnnotationAttributes[] annotationAttributes = attributes.getAnnotationArray("value");

//        创建dubbo配置绑定注册器
        DubboConfigBindingRegistrar registrar = new DubboConfigBindingRegistrar();
        registrar.setEnvironment(environment);

        for (AnnotationAttributes element : annotationAttributes) {

//            解析bean定义
            registrar.registerBeanDefinitions(element, registry);

        }
    }
 
Example 4
Source File: FlowerComponentScanRegistrar.java    From flower with Apache License 2.0 6 votes vote down vote up
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
  AnnotationAttributes attributes =
      AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(FlowerComponentScan.class.getName()));
  String[] basePackages = attributes.getStringArray("basePackages");
  Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
  String[] value = attributes.getStringArray("value");
  // Appends value array attributes
  Set<String> packagesToScan = new LinkedHashSet<String>(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;
}
 
Example 5
Source File: AbstractCachingConfiguration.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableCaching = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
	if (this.enableCaching == null) {
		throw new IllegalArgumentException(
				"@EnableCaching is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 6
Source File: AbstractLimiterConfiguration.java    From Limiter with Apache License 2.0 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    this.enableLimiter = AnnotationAttributes.fromMap(
            importMetadata.getAnnotationAttributes(EnableLimiter.class.getName(), false));
    if (this.enableLimiter == null) {
        throw new IllegalArgumentException(
                "@EnableLimiter is not present on importing class " + importMetadata.getClassName());
    }
}
 
Example 7
Source File: MBeanExportConfiguration.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class.getName());
	this.enableMBeanExport = AnnotationAttributes.fromMap(map);
	if (this.enableMBeanExport == null) {
		throw new IllegalArgumentException(
				"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 8
Source File: SpringFactoryImportSelector.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	if (!isEnabled()) {
		return new String[0];
	}
	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
		this.log.warn("More than one implementation " + "of @" + getSimpleName()
				+ " (now relying on @Conditionals to pick one): " + factories);
	}

	return factories.toArray(new String[factories.size()]);
}
 
Example 9
Source File: AbstractTransactionManagementConfiguration.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableTx = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableTransactionManagement.class.getName(), false));
	if (this.enableTx == null) {
		throw new IllegalArgumentException(
				"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 10
Source File: AbstractCachingConfiguration.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableCaching = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
	if (this.enableCaching == null) {
		throw new IllegalArgumentException(
				"@EnableCaching is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 11
Source File: RecursiveAnnotationAttributesVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void registerDefaultValues(Class<?> annotationClass) {
	// Only do further scanning for public annotations; we'd run into
	// IllegalAccessExceptions otherwise, and we don't want to mess with
	// accessibility in a SecurityManager environment.
	if (Modifier.isPublic(annotationClass.getModifiers())) {
		// Check declared default values of attributes in the annotation type.
		Method[] annotationAttributes = annotationClass.getMethods();
		for (Method annotationAttribute : annotationAttributes) {
			String attributeName = annotationAttribute.getName();
			Object defaultValue = annotationAttribute.getDefaultValue();
			if (defaultValue != null && !this.attributes.containsKey(attributeName)) {
				if (defaultValue instanceof Annotation) {
					defaultValue = AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes(
							(Annotation) defaultValue, false, true));
				}
				else if (defaultValue instanceof Annotation[]) {
					Annotation[] realAnnotations = (Annotation[]) defaultValue;
					AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
					for (int i = 0; i < realAnnotations.length; i++) {
						mappedAnnotations[i] = AnnotationAttributes.fromMap(
								AnnotationUtils.getAnnotationAttributes(realAnnotations[i], false, true));
					}
					defaultValue = mappedAnnotations;
				}
				this.attributes.put(attributeName, defaultValue);
			}
		}
	}
}
 
Example 12
Source File: DubboConfigConfigurationSelector.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {

//        查询@EnableDubboConfig注解的属性值
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                importingClassMetadata.getAnnotationAttributes(EnableDubboConfig.class.getName()));

        boolean multiple = attributes.getBoolean("multiple");

        if (multiple) { //属性是否是多个配置
            return of(DubboConfigConfiguration.Multiple.class.getName());
        } else {
            return of(DubboConfigConfiguration.Single.class.getName());
        }
    }
 
Example 13
Source File: TestAutoConfigurationPackageRegistrar.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@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")));
}
 
Example 14
Source File: WxMvcConfiguration.java    From FastBootWeixin with Apache License 2.0 4 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(
            importMetadata.getAnnotationAttributes(EnableWxMvc.class.getName(), false));
    this.menuAutoCreate = annotationAttributes.getBoolean("menuAutoCreate");
}
 
Example 15
Source File: AnnotationConfigUtils.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationClassName) {
	return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName, false));
}
 
Example 16
Source File: AnnotationConfigUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Nullable
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationClassName) {
	return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName, false));
}
 
Example 17
Source File: EnodeBootstrapRegistrar.java    From enode with MIT License 4 votes vote down vote up
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationClassName) {
    return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName, false));
}
 
Example 18
Source File: HttpdocFilterRegistrar.java    From httpdoc with Apache License 2.0 4 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableHttpdoc.class.getName()));
    BeanDefinition httpdoc = new RootBeanDefinition(FilterRegistrationBean.class);

    String name = attributes.getString("name");
    httpdoc.getPropertyValues().add("name", name);

    boolean asyncSupported = attributes.getBoolean("asyncSupported");
    httpdoc.getPropertyValues().add("asyncSupported", asyncSupported);

    DispatcherType[] dispatcherTypes = (DispatcherType[]) attributes.get("dispatcherTypes");
    httpdoc.getPropertyValues().add("dispatcherTypes", EnumSet.of(dispatcherTypes[0], dispatcherTypes));

    boolean matchAfter = attributes.getBoolean("matchAfter");
    httpdoc.getPropertyValues().add("matchAfter", matchAfter);

    boolean enabled = attributes.getBoolean("enabled");
    httpdoc.getPropertyValues().add("enabled", enabled);

    int order = attributes.getNumber("order");
    httpdoc.getPropertyValues().add("order", order);

    String[] patterns = attributes.getStringArray("value");
    httpdoc.getPropertyValues().add("urlPatterns", Arrays.asList(patterns));

    Class<?> filter = attributes.getClass("filter");
    httpdoc.getPropertyValues().add("filter", newInstance(filter));

    Map<String, String> parameters = new LinkedHashMap<>();
    AnnotationAttributes[] params = attributes.getAnnotationArray("params");
    for (AnnotationAttributes param : params) parameters.put(param.getString("name"), param.getString("value"));

    parameters.put("packages", concat(attributes.getStringArray("packages")));
    parameters.put("httpdoc", attributes.getString("httpdoc"));
    parameters.put("protocol", attributes.getString("protocol"));
    parameters.put("hostname", attributes.getString("hostname"));
    parameters.put("port", attributes.getNumber("port").toString());
    parameters.put("context", attributes.getString("context"));
    parameters.put("version", attributes.getString("version"));
    parameters.put("dateFormat", attributes.getString("dateFormat"));
    parameters.put("description", attributes.getString("description"));
    parameters.put("charset", attributes.getString("charset"));
    parameters.put("contentType", attributes.getString("contentType"));
    parameters.put("translator", attributes.getClass("translator").getName());
    parameters.put("supplier", attributes.getClass("supplier").getName());
    parameters.put("interpreter", attributes.getClass("interpreter").getName());
    parameters.put("converter", attributes.getClass("converter").getName());
    parameters.put("serializer", attributes.getClass("serializer").getName());
    parameters.put("conversionProvider", attributes.getClass("conversionProvider").getName());

    httpdoc.getPropertyValues().add("initParameters", parameters);

    String beanName = attributes.getString("bean");
    registry.registerBeanDefinition(beanName, httpdoc);
}
 
Example 19
Source File: ConfigurationClassWithConditionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(MetaConditional.class.getName()));
	assertThat(attributes.getString("value"), equalTo("test"));
	return true;
}
 
Example 20
Source File: AbstractRetrofitClientsRegistrar.java    From spring-cloud-square with Apache License 2.0 4 votes vote down vote up
private void validate(Map<String, Object> attributes) {
	AnnotationAttributes annotation = AnnotationAttributes.fromMap(attributes);
	// This blows up if an aliased property is overspecified
	//TODO: is this needed anymore //annotation.getAliasedString("name", RetrofitClient.class, null);
}