use of org.springframework.core.annotation.AnnotationAttributes in project spring-security by spring-projects.
the class WebSecurityConfiguration method setImportMetadata.
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
Map<String, Object> enableWebSecurityAttrMap = importMetadata.getAnnotationAttributes(EnableWebSecurity.class.getName());
AnnotationAttributes enableWebSecurityAttrs = AnnotationAttributes.fromMap(enableWebSecurityAttrMap);
this.debugEnabled = enableWebSecurityAttrs.getBoolean("debug");
if (this.webSecurity != null) {
this.webSecurity.debug(this.debugEnabled);
}
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class ImportAwareTests method directlyAnnotatedWithImport.
@Test
public void directlyAnnotatedWithImport() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingConfig.class);
ctx.refresh();
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat(importMetadata).isNotNull();
assertThat(importMetadata.getClassName()).isEqualTo(ImportingConfig.class.getName());
AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
Class<?>[] importedClasses = importAttribs.getClassArray("value");
assertThat(importedClasses[0].getName()).isEqualTo(ImportedConfig.class.getName());
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class ImportAwareTests method directlyAnnotatedWithImportLite.
@Test
public void directlyAnnotatedWithImportLite() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingConfigLite.class);
ctx.refresh();
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
ImportedConfigLite importAwareConfig = ctx.getBean(ImportedConfigLite.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat(importMetadata).isNotNull();
assertThat(importMetadata.getClassName()).isEqualTo(ImportingConfigLite.class.getName());
AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
Class<?>[] importedClasses = importAttribs.getClassArray("value");
assertThat(importedClasses[0].getName()).isEqualTo(ImportedConfigLite.class.getName());
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class AdviceModeImportSelector method selectImports.
/**
* This implementation resolves the type of annotation from generic metadata and
* validates that (a) the annotation is in fact present on the importing
* {@code @Configuration} class and (b) that the given annotation has an
* {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
* {@link AdviceMode}.
* <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
* concrete implementation to choose imports in a safe and convenient fashion.
* @throws IllegalArgumentException if expected annotation {@code A} is not present
* on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
* returns {@code null}
*/
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
Class<?> annType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
Assert.state(annType != null, "Unresolvable type argument for AdviceModeImportSelector");
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annType);
if (attributes == null) {
throw new IllegalArgumentException(String.format("@%s is not present on importing class '%s' as expected", annType.getSimpleName(), importingClassMetadata.getClassName()));
}
AdviceMode adviceMode = attributes.getEnum(getAdviceModeAttributeName());
String[] imports = selectImports(adviceMode);
if (imports == null) {
throw new IllegalArgumentException("Unknown AdviceMode: " + adviceMode);
}
return imports;
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class AnnotationConfigUtils method processCommonDefinitionAnnotations.
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
AnnotationAttributes lazy = attributesFor(metadata, Lazy.class);
if (lazy != null) {
abd.setLazyInit(lazy.getBoolean("value"));
} else if (abd.getMetadata() != metadata) {
lazy = attributesFor(abd.getMetadata(), Lazy.class);
if (lazy != null) {
abd.setLazyInit(lazy.getBoolean("value"));
}
}
if (metadata.isAnnotated(Primary.class.getName())) {
abd.setPrimary(true);
}
AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class);
if (dependsOn != null) {
abd.setDependsOn(dependsOn.getStringArray("value"));
}
AnnotationAttributes role = attributesFor(metadata, Role.class);
if (role != null) {
abd.setRole(role.getNumber("value").intValue());
}
AnnotationAttributes description = attributesFor(metadata, Description.class);
if (description != null) {
abd.setDescription(description.getString("value"));
}
}
Aggregations