Discovering and accumulating all @Profile meta-annotations

Issue: SPR-10812
This commit is contained in:
Juergen Hoeller
2013-08-26 20:03:32 +02:00
parent c9771012e9
commit aecf60d21f
2 changed files with 78 additions and 27 deletions

View File

@@ -16,8 +16,8 @@
package org.springframework.context.annotation;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.MultiValueMap;
/**
* {@link Condition} that matches based on the value of a {@link Profile @Profile}
@@ -25,15 +25,21 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
*
* @author Chris Beams
* @author Phillip Webb
* @author Juergen Hoeller
* @since 4.0
*/
class ProfileCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (context.getEnvironment() != null && metadata.isAnnotated(Profile.class.getName())) {
AnnotationAttributes profile = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(Profile.class.getName()));
if (!context.getEnvironment().acceptsProfiles(profile.getStringArray("value"))) {
if (context.getEnvironment() != null) {
MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
if (attrs != null) {
for (Object value : attrs.get("value")) {
if (context.getEnvironment().acceptsProfiles(((String[]) value))) {
return true;
}
}
return false;
}
}