Search in sources :

Example 1 with ClassMetadata

use of org.springframework.core.type.ClassMetadata in project spring-boot by spring-projects.

the class CacheCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String sourceClass = "";
    if (metadata instanceof ClassMetadata) {
        sourceClass = ((ClassMetadata) metadata).getClassName();
    }
    ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass);
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "spring.cache.");
    if (!resolver.containsProperty("type")) {
        return ConditionOutcome.match(message.because("automatic cache type"));
    }
    CacheType cacheType = CacheConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
    String value = resolver.getProperty("type").replace('-', '_').toUpperCase();
    if (value.equals(cacheType.name())) {
        return ConditionOutcome.match(message.because(value + " cache type"));
    }
    return ConditionOutcome.noMatch(message.because(value + " cache type"));
}
Also used : ClassMetadata(org.springframework.core.type.ClassMetadata) ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Aggregations

ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)1 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)1 ClassMetadata (org.springframework.core.type.ClassMetadata)1