use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.
the class OnEnabledEndpointElementCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(this.annotationType.getName()));
String endpointName = annotationAttributes.getString("value");
ConditionOutcome outcome = getEndpointOutcome(context, endpointName);
if (outcome != null) {
return outcome;
}
return getDefaultEndpointsOutcome(context);
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.
the class OnEnabledEndpointCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()));
String endpointName = annotationAttributes.getString("value");
boolean enabledByDefault = annotationAttributes.getBoolean("enabledByDefault");
ConditionOutcome outcome = determineEndpointOutcome(endpointName, enabledByDefault, context);
if (outcome != null) {
return outcome;
}
return determineAllEndpointsOutcome(context);
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.
the class AutoConfigurationImportSelector method selectImports.
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
if (!isEnabled(annotationMetadata)) {
return NO_IMPORTS;
}
try {
AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);
AnnotationAttributes attributes = getAttributes(annotationMetadata);
List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
configurations = removeDuplicates(configurations);
configurations = sort(configurations, autoConfigurationMetadata);
Set<String> exclusions = getExclusions(annotationMetadata, attributes);
checkExcludedClasses(configurations, exclusions);
configurations.removeAll(exclusions);
configurations = filter(configurations, autoConfigurationMetadata);
fireAutoConfigurationImportEvents(configurations, exclusions);
return configurations.toArray(new String[configurations.size()]);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class OverriddenMetaAnnotationAttributesTests method overriddenContextConfigurationLocationsAndInheritLocations.
@Test
public void overriddenContextConfigurationLocationsAndInheritLocations() throws Exception {
Class<?> declaringClass = OverriddenMetaLocationsConfigTestCase.class;
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class);
assertNotNull(descriptor);
assertEquals(declaringClass, descriptor.getRootDeclaringClass());
assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
// direct access to annotation attributes:
assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().locations());
assertFalse(descriptor.getAnnotation().inheritLocations());
// overridden attributes:
AnnotationAttributes attributes = descriptor.getAnnotationAttributes();
assertArrayEquals(new String[] { "bar.xml" }, attributes.getStringArray("locations"));
assertTrue(attributes.getBoolean("inheritLocations"));
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class OverriddenMetaAnnotationAttributesTests method overriddenContextConfigurationValue.
@Test
public void overriddenContextConfigurationValue() throws Exception {
Class<?> declaringClass = OverriddenMetaValueConfigTestCase.class;
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class);
assertNotNull(descriptor);
assertEquals(declaringClass, descriptor.getRootDeclaringClass());
assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
// direct access to annotation value:
assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().value());
// overridden attribute:
AnnotationAttributes attributes = descriptor.getAnnotationAttributes();
// NOTE: we would like to be able to override the 'value' attribute; however,
// Spring currently does not allow overrides for the 'value' attribute.
// See SPR-11393 for related discussions.
assertArrayEquals(new String[] { "foo.xml" }, attributes.getStringArray("value"));
}
Aggregations