package com.atlassian.stash.internal.spring.jmx;

import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Properties;

/**
 * A Spring condition for configuration that should only be activated when the property jmx.enabled=true.
 */
class JmxEnabledCondition implements ConfigurationCondition {
    @Override
    public ConfigurationPhase getConfigurationPhase() {
        return ConfigurationPhase.REGISTER_BEAN;
    }

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        return Boolean.valueOf(((Properties) context.getBeanFactory().getBean("applicationProperties"))
                .getProperty("jmx.enabled"));
    }
}
