Search in sources :

Example 1 with ConfigurationPhase

use of org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase in project spring-framework by spring-projects.

the class ConditionEvaluator method shouldSkip.

/**
	 * Determine if an item should be skipped based on {@code @Conditional} annotations.
	 * @param metadata the meta data
	 * @param phase the phase of the call
	 * @return if the item should be skipped
	 */
public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase phase) {
    if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) {
        return false;
    }
    if (phase == null) {
        if (metadata instanceof AnnotationMetadata && ConfigurationClassUtils.isConfigurationCandidate((AnnotationMetadata) metadata)) {
            return shouldSkip(metadata, ConfigurationPhase.PARSE_CONFIGURATION);
        }
        return shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN);
    }
    List<Condition> conditions = new ArrayList<>();
    for (String[] conditionClasses : getConditionClasses(metadata)) {
        for (String conditionClass : conditionClasses) {
            Condition condition = getCondition(conditionClass, this.context.getClassLoader());
            conditions.add(condition);
        }
    }
    AnnotationAwareOrderComparator.sort(conditions);
    for (Condition condition : conditions) {
        ConfigurationPhase requiredPhase = null;
        if (condition instanceof ConfigurationCondition) {
            requiredPhase = ((ConfigurationCondition) condition).getConfigurationPhase();
        }
        if (requiredPhase == null || requiredPhase == phase) {
            if (!condition.matches(this.context, metadata)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) ConfigurationPhase(org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata)

Aggregations

ArrayList (java.util.ArrayList)1 ConfigurationPhase (org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase)1 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)1