Search in sources :

Example 1 with Type

use of org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type in project spring-boot by spring-projects.

the class OnWebApplicationCondition method isWebApplication.

private ConditionOutcome isWebApplication(ConditionContext context, AnnotatedTypeMetadata metadata, boolean required) {
    ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnWebApplication.class, required ? "(required)" : "");
    Type type = deduceType(metadata);
    if (Type.SERVLET == type) {
        return isServletWebApplication(context);
    } else if (Type.REACTIVE == type) {
        return isReactiveWebApplication(context);
    } else {
        ConditionOutcome servletOutcome = isServletWebApplication(context);
        if (servletOutcome.isMatch() && required) {
            return new ConditionOutcome(servletOutcome.isMatch(), message.because(servletOutcome.getMessage()));
        }
        ConditionOutcome reactiveOutcome = isReactiveWebApplication(context);
        if (reactiveOutcome.isMatch() && required) {
            return new ConditionOutcome(reactiveOutcome.isMatch(), message.because(reactiveOutcome.getMessage()));
        }
        boolean finalOutcome = (required ? servletOutcome.isMatch() && reactiveOutcome.isMatch() : servletOutcome.isMatch() || reactiveOutcome.isMatch());
        return new ConditionOutcome(finalOutcome, message.because(servletOutcome.getMessage()).append("and").append(reactiveOutcome.getMessage()));
    }
}
Also used : Type(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type)

Aggregations

Type (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type)1