com.bluetrainsoftware.common.config.ConfigKeyProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stickycode-extended-config Show documentation
Show all versions of stickycode-extended-config Show documentation
Extends the functionality of Spring Boot and Sticky Code and provides extra support for Kubernetes style mounted volumes.
package com.bluetrainsoftware.common.config;
import net.stickycode.bootstrap.ComponentContainer;
import net.stickycode.coercion.Coercion;
import net.stickycode.coercion.CoercionFinder;
import net.stickycode.coercion.CoercionTarget;
import net.stickycode.coercion.target.CoercionTargets;
import net.stickycode.configuration.ResolvedConfiguration;
import net.stickycode.configured.ConfigurationAttribute;
import net.stickycode.configured.ConfigurationRepository;
import net.stickycode.configured.ConfiguredFieldsMustNotBePrimitiveAsDefaultDerivationIsImpossibleException;
import net.stickycode.configured.MissingConfigurationException;
import net.stickycode.reflector.AnnotatedFieldProcessor;
import net.stickycode.reflector.Fields;
import net.stickycode.stereotype.Configured;
import java.lang.reflect.Field;
public class ConfigKeyProcessor extends AnnotatedFieldProcessor {
private final ConfigurationRepository configuration;
public ConfigKeyProcessor(ConfigurationRepository configuration) {
super(ConfigKey.class, Configured.class);
this.configuration = configuration;
}
@Override
public void processField(final Object target, final Field field) {
if (field.getType().isPrimitive())
throw new ConfiguredFieldsMustNotBePrimitiveAsDefaultDerivationIsImpossibleException(target, field);
configuration.register(new ConfigurationAttribute() {
private CoercionTarget coercionTarget = CoercionTargets.find(field);
private ResolvedConfiguration resolution;
private Object value;
private Coercion