All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.bootstrap.condition.AbstractOnBootstrapCondition Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.bootstrap.condition;

import java.lang.annotation.Annotation;

import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.type.AnnotatedTypeMetadata;

abstract class AbstractOnBootstrapCondition extends SpringBootCondition {

    private String message = "Spring Cloud bootstrap environment";
    private final Class conditionType;
    private final boolean available;

    AbstractOnBootstrapCondition(Class conditionType, boolean available) {
        this.conditionType = conditionType;
        this.available = available;
    }

    @Override
    public final ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConfigurableEnvironment environment = (ConfigurableEnvironment)context.getEnvironment();
        boolean springCloudMatch = matchCondition(environment);
        String message = "Spring Cloud bootstrap environment";
        return new ConditionOutcome(springCloudMatch, ConditionMessage.forCondition(conditionType).available(message));
    }

    protected abstract boolean matchCondition(ConfigurableEnvironment environment);

    protected ConditionOutcome createConditionOutcome(boolean match) {
        ConditionMessage conditionMessage = available ? ConditionMessage.forCondition(conditionType).available(message)
            : ConditionMessage.forCondition(conditionType).notAvailable(message);
        return new ConditionOutcome(match, conditionMessage);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy