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

io.smallrye.config.RelocateConfigSourceInterceptor Maven / Gradle / Ivy

package io.smallrye.config;

import java.io.Serializable;
import java.util.Map;
import java.util.function.Function;

import javax.annotation.Priority;

@Priority(Priorities.LIBRARY + 1000)
public class RelocateConfigSourceInterceptor implements ConfigSourceInterceptor {
    private static final long serialVersionUID = 3476637906383945843L;

    private final Function mapping;

    public RelocateConfigSourceInterceptor(final Function mapping) {
        this.mapping = mapping != null ? mapping : Function.identity();
    }

    public RelocateConfigSourceInterceptor(final Map mappings) {
        this((Serializable & Function) name -> mappings.getOrDefault(name, name));
    }

    @Override
    public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
        final String map = mapping.apply(name);
        ConfigValue configValue = context.proceed(map);
        if (configValue == null && !name.equals(map)) {
            configValue = context.proceed(name);
        }
        return configValue;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy