Search in sources :

Example 56 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project dubbo-faker by moyada.

the class MonitorRegistrar method getBasePackages.

private String[] getBasePackages(AnnotationMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableSharinganMonitor.class.getName()));
    if (null == attributes) {
        return null;
    }
    Set<String> packages = new HashSet<>();
    String[] values = attributes.getStringArray("value");
    for (String value : values) {
        add(packages, value);
    }
    String[] basePackages = attributes.getStringArray("basePackages");
    for (String basePackage : basePackages) {
        add(packages, basePackage);
    }
    Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
    for (Class<?> basePackageClass : basePackageClasses) {
        add(packages, ClassUtils.getPackageName(basePackageClass));
    }
    if (packages.isEmpty()) {
        add(packages, ClassUtils.getPackageName(metadata.getClassName()));
    }
    return packages.toArray(new String[0]);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) HashSet(java.util.HashSet)

Example 57 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project commons by terran4j.

the class DsqlRepositoryConfigRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableDsqlRepositories.class.getName()));
    Class<?>[] basePackageClasses = attributes.getClassArray("value");
    if (basePackageClasses == null || basePackageClasses.length == 0) {
        basePackageClasses = attributes.getClassArray("basePackageClasses");
    }
    if (registry instanceof DefaultListableBeanFactory) {
        DefaultListableBeanFactory factory = (DefaultListableBeanFactory) registry;
        if (beanFactory == null) {
            // 缓存 beanFactory 对象。
            beanFactory = factory;
        }
        registerBeanDefinitions(factory, basePackageClasses);
    } else {
        String msg = String.format("Current registry %s is NOT the class: %s, " + "maybe the Spring Version is incompatible.", registry.getClass(), DefaultListableBeanFactory.class);
        throw new UnsupportedOperationException(msg);
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 58 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project redisson by redisson.

the class RedissonWebSessionConfiguration method setImportMetadata.

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableRedissonWebSession.class.getName());
    AnnotationAttributes attrs = AnnotationAttributes.fromMap(map);
    keyPrefix = attrs.getString("keyPrefix");
    maxInactiveIntervalInSeconds = attrs.getNumber("maxInactiveIntervalInSeconds");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 59 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project redisson by redisson.

the class RedissonHttpSessionConfiguration method setImportMetadata.

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableRedissonHttpSession.class.getName());
    AnnotationAttributes attrs = AnnotationAttributes.fromMap(map);
    keyPrefix = attrs.getString("keyPrefix");
    maxInactiveIntervalInSeconds = attrs.getNumber("maxInactiveIntervalInSeconds");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 60 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-security by spring-projects.

the class GlobalMethodSecuritySelector method selectImports.

@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    Class<EnableGlobalMethodSecurity> annoType = EnableGlobalMethodSecurity.class;
    Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(annoType.getName(), false);
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(annotationAttributes);
    Assert.notNull(attributes, () -> String.format("@%s is not present on importing class '%s' as expected", annoType.getSimpleName(), importingClassMetadata.getClassName()));
    // TODO would be nice if could use BeanClassLoaderAware (does not work)
    Class<?> importingClass = ClassUtils.resolveClassName(importingClassMetadata.getClassName(), ClassUtils.getDefaultClassLoader());
    boolean skipMethodSecurityConfiguration = GlobalMethodSecurityConfiguration.class.isAssignableFrom(importingClass);
    AdviceMode mode = attributes.getEnum("mode");
    boolean isProxy = AdviceMode.PROXY == mode;
    String autoProxyClassName = isProxy ? AutoProxyRegistrar.class.getName() : GlobalMethodSecurityAspectJAutoProxyRegistrar.class.getName();
    boolean jsr250Enabled = attributes.getBoolean("jsr250Enabled");
    List<String> classNames = new ArrayList<>(4);
    if (isProxy) {
        classNames.add(MethodSecurityMetadataSourceAdvisorRegistrar.class.getName());
    }
    classNames.add(autoProxyClassName);
    if (!skipMethodSecurityConfiguration) {
        classNames.add(GlobalMethodSecurityConfiguration.class.getName());
    }
    if (jsr250Enabled) {
        classNames.add(Jsr250MetadataSourceConfiguration.class.getName());
    }
    return classNames.toArray(new String[0]);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) AdviceMode(org.springframework.context.annotation.AdviceMode) ArrayList(java.util.ArrayList) AutoProxyRegistrar(org.springframework.context.annotation.AutoProxyRegistrar)

Aggregations

AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)89 Test (org.junit.jupiter.api.Test)17 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)7 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)7 Annotation (java.lang.annotation.Annotation)6 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)3 StandardAnnotationMetadata (org.springframework.core.type.StandardAnnotationMetadata)3 DubboReference (org.apache.dubbo.config.annotation.DubboReference)2 ReferenceBean (org.apache.dubbo.config.spring.ReferenceBean)2 Test (org.junit.Test)2 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)2 BeanNameGenerator (org.springframework.beans.factory.support.BeanNameGenerator)2 DiscoveredOperationMethod (org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2