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

sirius.kernel.settings.ConfigValueAnnotationProcessor Maven / Gradle / Ivy

/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.settings;

import sirius.kernel.Sirius;
import sirius.kernel.di.FieldAnnotationProcessor;
import sirius.kernel.di.Injector;
import sirius.kernel.di.MutableGlobalContext;
import sirius.kernel.di.std.ConfigValue;
import sirius.kernel.di.std.Register;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * AnnotationProcessor which handles the {@link ConfigValue} annotation.
 *
 * @see sirius.kernel.di.FieldAnnotationProcessor
 * @see ConfigValue
 */
@Register
public class ConfigValueAnnotationProcessor implements FieldAnnotationProcessor {

    @Override
    public Class getTrigger() {
        return ConfigValue.class;
    }

    @Override
    public void handle(MutableGlobalContext ctx, Object object, Field field) throws Exception {
        ConfigValue val = field.getAnnotation(ConfigValue.class);
        String key = val.value();

        if (!Sirius.getSettings().injectValueFromConfig(object, field, key) && val.required()) {
            Injector.LOG.WARN("Missing config value: %s in (%s.%s)!",
                              key,
                              field.getDeclaringClass().getName(),
                              field.getName());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy